blob: 22f99dfef843d2bf3879e6bc9b8339142fa83ee2 [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 Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
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;
Grace Jia0ddb3612021-04-22 13:35:26 -0700358 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800360 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700362 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800363 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
Peter Wangdafb9ac2020-01-15 14:13:38 -0800365 /** User Activity */
366 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
368
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700369 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
370
Derek Tan97ebb422014-09-05 16:55:38 -0700371 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
372 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800373 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800374 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700375
Michelecea4cf22018-12-21 15:00:11 -0800376 // String to store multi SIM allowed
377 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
378
Derek Tan740e1672017-06-27 14:56:27 -0700379 // The AID of ISD-R.
380 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
381
yinxub1bed742017-04-17 11:45:04 -0700382 private NetworkScanRequestTracker mNetworkScanRequestTracker;
383
David Kelly5e06a7f2018-03-12 14:10:59 +0000384 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
385 private static final int MANUFACTURER_CODE_LENGTH = 8;
386
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800388 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389
Derek Tan89e89d42014-07-08 17:00:10 -0700390 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700391 * Experiment flag to enable erase modem config on reset network, default value is false
392 */
393 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
394 "reset_network_erase_modem_config_enabled";
395
Rambo Wang0f050d82021-02-12 11:43:36 -0800396 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
397
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700399 * A request object to use for transmitting data to an ICC.
400 */
401 private static final class IccAPDUArgument {
402 public int channel, cla, command, p1, p2, p3;
403 public String data;
404
405 public IccAPDUArgument(int channel, int cla, int command,
406 int p1, int p2, int p3, String data) {
407 this.channel = channel;
408 this.cla = cla;
409 this.command = command;
410 this.p1 = p1;
411 this.p2 = p2;
412 this.p3 = p3;
413 this.data = data;
414 }
415 }
416
417 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700418 * A request object to use for transmitting data to an ICC.
419 */
420 private static final class ManualNetworkSelectionArgument {
421 public OperatorInfo operatorInfo;
422 public boolean persistSelection;
423
424 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
425 this.operatorInfo = operatorInfo;
426 this.persistSelection = persistSelection;
427 }
428 }
429
430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
432 * request after sending. The main thread will notify the request when it is complete.
433 */
434 private static final class MainThreadRequest {
435 /** The argument to use for the request */
436 public Object argument;
437 /** The result of the request that is run on the main thread */
438 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800439 // The subscriber id that this request applies to. Defaults to
440 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
441 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
Nathan Harold92bed182018-10-12 18:16:49 -0700443 // In cases where subId is unavailable, the caller needs to specify the phone.
444 public Phone phone;
445
vagdeviaf9a5b92018-08-15 16:01:53 -0700446 public WorkSource workSource;
447
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 public MainThreadRequest(Object argument) {
449 this.argument = argument;
450 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800451
Nathan Harold92bed182018-10-12 18:16:49 -0700452 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
453 this.argument = argument;
454 if (phone != null) {
455 this.phone = phone;
456 }
457 this.workSource = workSource;
458 }
459
vagdeviaf9a5b92018-08-15 16:01:53 -0700460 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800461 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800462 if (subId != null) {
463 this.subId = subId;
464 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700465 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 }
468
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800469 private static final class IncomingThirdPartyCallArgs {
470 public final ComponentName component;
471 public final String callId;
472 public final String callerDisplayName;
473
474 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
475 String callerDisplayName) {
476 this.component = component;
477 this.callId = callId;
478 this.callerDisplayName = callerDisplayName;
479 }
480 }
481
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 /**
483 * A handler that processes messages on the main thread in the phone process. Since many
484 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
485 * inbound binder threads to the main thread in the phone process. The Binder thread
486 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
487 * on, which will be notified when the operation completes and will contain the result of the
488 * request.
489 *
490 * <p>If a MainThreadRequest object is provided in the msg.obj field,
491 * note that request.result must be set to something non-null for the calling thread to
492 * unblock.
493 */
494 private final class MainThreadHandler extends Handler {
495 @Override
496 public void handleMessage(Message msg) {
497 MainThreadRequest request;
498 Message onCompleted;
499 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800502 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503
504 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 case CMD_HANDLE_USSD_REQUEST: {
506 request = (MainThreadRequest) msg.obj;
507 final Phone phone = getPhoneFromRequest(request);
508 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
509 String ussdRequest = ussdObject.first;
510 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 if (!isUssdApiAllowed(request.subId)) {
513 // Carrier does not support use of this API, return failure.
514 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
515 UssdResponse response = new UssdResponse(ussdRequest, null);
516 Bundle returnData = new Bundle();
517 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
518 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 request.result = true;
521 notifyRequester(request);
522 return;
523 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700524
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 try {
526 request.result = phone != null
527 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
528 } catch (CallStateException cse) {
529 request.result = false;
530 }
531 // Wake up the requesting thread
532 notifyRequester(request);
533 break;
pkanwar32d516d2016-10-14 19:37:38 -0700534 }
535
Yorke Lee716f67e2015-06-17 15:39:16 -0700536 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 final Phone phone = getPhoneFromRequest(request);
539 request.result = phone != null ?
540 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
541 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccTransmitApduLogicalChannel: No UICC");
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
557 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 iccArgument.channel, iccArgument.cla, iccArgument.command,
560 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
572 if (ar.result == null) {
573 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800574 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800576 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 } else {
578 loge("iccTransmitApduLogicalChannel: Unknown exception");
579 }
580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
585 request = (MainThreadRequest) msg.obj;
586 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (uiccCard == null) {
589 loge("iccTransmitApduBasicChannel: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 } else {
593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
594 request);
595 uiccCard.iccTransmitApduBasicChannel(
596 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
597 iccArgument.p3, iccArgument.data, onCompleted);
598 }
599 break;
600
601 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
606 } else {
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("iccTransmitApduBasicChannel: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("iccTransmitApduBasicChannel: CommandException: " +
612 ar.exception);
613 } else {
614 loge("iccTransmitApduBasicChannel: Unknown exception");
615 }
616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 break;
619
620 case CMD_EXCHANGE_SIM_IO:
621 request = (MainThreadRequest) msg.obj;
622 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 if (uiccCard == null) {
625 loge("iccExchangeSimIO: No UICC");
626 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
630 request);
631 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
632 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
633 iccArgument.data, onCompleted);
634 }
635 break;
636
637 case EVENT_EXCHANGE_SIM_IO_DONE:
638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
640 if (ar.exception == null && ar.result != null) {
641 request.result = ar.result;
642 } else {
643 request.result = new IccIoResult(0x6f, 0, (byte[])null);
644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 break;
647
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 case CMD_SEND_ENVELOPE:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("sendEnvelopeWithStatus: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
657 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
658 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 break;
660
661 case EVENT_SEND_ENVELOPE_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700667 request.result = new IccIoResult(0x6F, 0, (byte[])null);
668 if (ar.result == null) {
669 loge("sendEnvelopeWithStatus: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("sendEnvelopeWithStatus: CommandException: " +
672 ar.exception);
673 } else {
674 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
675 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 break;
679
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 case CMD_OPEN_CHANNEL:
681 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800682 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800683 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 if (uiccCard == null) {
685 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800686 request.result = new IccOpenLogicalChannelResponse(-1,
687 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 } else {
690 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
692 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
696 case EVENT_OPEN_CHANNEL_DONE:
697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 int[] result = (int[]) ar.result;
702 int channelId = result[0];
703 byte[] selectResponse = null;
704 if (result.length > 1) {
705 selectResponse = new byte[result.length - 1];
706 for (int i = 1; i < result.length; ++i) {
707 selectResponse[i - 1] = (byte) result[i];
708 }
709 }
710 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700711 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 if (ar.result == null) {
714 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 if (ar.exception != null) {
717 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
718 }
719
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700720 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700721 if (ar.exception instanceof CommandException) {
722 CommandException.Error error =
723 ((CommandException) (ar.exception)).getCommandError();
724 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700725 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700726 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 }
729 }
730 openChannelResp = new IccOpenLogicalChannelResponse(
731 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700733 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case CMD_CLOSE_CHANNEL:
738 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800739 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700740 if (uiccCard == null) {
741 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900742 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
746 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 break;
749
750 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800751 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
752 break;
753
754 case CMD_NV_READ_ITEM:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
758 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800759 break;
760
761 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800764 if (ar.exception == null && ar.result != null) {
765 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800767 request.result = "";
768 if (ar.result == null) {
769 loge("nvReadItem: Empty response");
770 } else if (ar.exception instanceof CommandException) {
771 loge("nvReadItem: CommandException: " +
772 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 }
776 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700777 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 break;
779
Jake Hambye994d462014-02-03 13:10:13 -0800780 case CMD_NV_WRITE_ITEM:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
783 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700785 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_WRITE_ITEM_DONE:
789 handleNullReturnEvent(msg, "nvWriteItem");
790 break;
791
792 case CMD_NV_WRITE_CDMA_PRL:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800796 break;
797
798 case EVENT_NV_WRITE_CDMA_PRL_DONE:
799 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
800 break;
801
chen xu6dac5ab2018-10-26 17:39:23 -0700802 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800803 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700804 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800805 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case EVENT_RESET_MODEM_CONFIG_DONE:
809 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800810 break;
811
Sooraj Sasindran37444802020-08-11 10:40:43 -0700812 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
815 request);
816 Phone phone = getPhoneFromRequest(request);
817 if (phone != null) {
818 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
819 } else {
820 loge("isNRDualConnectivityEnabled: No phone object");
821 request.result = false;
822 notifyRequester(request);
823 }
824 break;
825 }
826
827 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result;
832 } else {
833 // request.result must be set to something non-null
834 // for the calling thread to unblock
835 if (request.result != null) {
836 request.result = ar.result;
837 } else {
838 request.result = false;
839 }
840 if (ar.result == null) {
841 loge("isNRDualConnectivityEnabled: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("isNRDualConnectivityEnabled: CommandException: "
844 + ar.exception);
845 } else {
846 loge("isNRDualConnectivityEnabled: Unknown exception");
847 }
848 }
849 notifyRequester(request);
850 break;
851
852 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
853 request = (MainThreadRequest) msg.obj;
854 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
855 Phone phone = getPhoneFromRequest(request);
856 if (phone != null) {
857 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
858 request.workSource);
859 } else {
860 loge("enableNrDualConnectivity: No phone object");
861 request.result =
862 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
863 notifyRequester(request);
864 }
865 break;
866 }
867
868 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null) {
872 request.result =
873 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
874 } else {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
878 if (ar.exception instanceof CommandException) {
879 CommandException.Error error =
880 ((CommandException) (ar.exception)).getCommandError();
881 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
882 request.result =
883 TelephonyManager
884 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000885 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
886 request.result =
887 TelephonyManager
888 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700889 }
890 loge("enableNrDualConnectivity" + ": CommandException: "
891 + ar.exception);
892 } else {
893 loge("enableNrDualConnectivity" + ": Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898 }
899
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
903 request);
904 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
SongFerngWang3ef3e072020-12-21 16:41:52 +0800907 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result; // Integer
912 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530913 // request.result must be set to something non-null
914 // for the calling thread to unblock
915 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800917 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: CommandException: "
920 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800922 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 }
924 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 break;
927
SongFerngWang3ef3e072020-12-21 16:41:52 +0800928 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800929 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
931 request);
932 Pair<Integer, Long> reasonWithNetworkTypes =
933 (Pair<Integer, Long>) request.argument;
934 getPhoneFromRequest(request).setAllowedNetworkTypes(
935 reasonWithNetworkTypes.first,
936 reasonWithNetworkTypes.second,
937 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800938 break;
939
SongFerngWang3ef3e072020-12-21 16:41:52 +0800940 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
941 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800942 break;
943
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000944 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
945 request = (MainThreadRequest)msg.obj;
946 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000948 break;
949
950 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
951 ar = (AsyncResult)msg.obj;
952 request = (MainThreadRequest)ar.userObj;
953 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000955 break;
956
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800957 case CMD_SET_VOICEMAIL_NUMBER:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
960 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800961 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
962 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800963 break;
964
965 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
966 handleNullReturnEvent(msg, "setVoicemailNumber");
967 break;
968
Stuart Scott54788802015-03-30 13:18:01 -0700969 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
972 request);
973 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
974 break;
975
976 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
977 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
978 break;
979
Shishir Agrawal302c8692015-06-19 13:49:39 -0700980 case CMD_PERFORM_NETWORK_SCAN:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
983 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
984 break;
985
Hall Liu27d24262020-09-18 19:04:59 -0700986 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700989 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
990 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
991 request.argument;
992 int callForwardingReason = args.first;
993 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800994 break;
Hall Liu27d24262020-09-18 19:04:59 -0700995 }
996 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700999 TelephonyManager.CallForwardingInfoCallback callback =
1000 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1001 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001002 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001003 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1005 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1006 // Service Class is a bit mask per 3gpp 27.007. Search for
1007 // any service for voice call.
1008 if ((callForwardInfo.serviceClass
1009 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001010 callForwardingInfo = new CallForwardingInfo(true,
1011 callForwardInfo.reason,
1012 callForwardInfo.number,
1013 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001014 break;
1015 }
1016 }
1017 // Didn't find a call forward info for voice call.
1018 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001019 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1020 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001021 }
Hall Liu27d24262020-09-18 19:04:59 -07001022 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 } else {
1024 if (ar.result == null) {
1025 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1026 }
1027 if (ar.exception != null) {
1028 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1029 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001030 int errorCode = TelephonyManager
1031 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager
1037 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001038 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager
1040 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001041 }
1042 }
Hall Liu27d24262020-09-18 19:04:59 -07001043 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001044 }
Shuo Qian4a594052020-01-23 11:59:30 -08001045 break;
Hall Liu27d24262020-09-18 19:04:59 -07001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047
Hall Liu27d24262020-09-18 19:04:59 -07001048 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001051 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001052 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001053 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1054 request.argument).first;
1055 request.phone.setCallForwardingOption(
1056 callForwardingInfoToSet.isEnabled()
1057 ? CommandsInterface.CF_ACTION_ENABLE
1058 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001059 callForwardingInfoToSet.getReason(),
1060 callForwardingInfoToSet.getNumber(),
1061 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1062 break;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
Shuo Qian4a594052020-01-23 11:59:30 -08001064
Hall Liu27d24262020-09-18 19:04:59 -07001065 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001068 Consumer<Integer> callback =
1069 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1070 request.argument).second;
1071 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001072 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001073 int errorCode = TelephonyManager.CallForwardingInfoCallback
1074 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001079 errorCode = TelephonyManager.CallForwardingInfoCallback
1080 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001081 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001082 errorCode = TelephonyManager.CallForwardingInfoCallback
1083 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 }
1086 callback.accept(errorCode);
1087 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001088 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001089 }
Shuo Qian4a594052020-01-23 11:59:30 -08001090 break;
Hall Liu27d24262020-09-18 19:04:59 -07001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092
Hall Liu27d24262020-09-18 19:04:59 -07001093 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1096 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1097 break;
Hall Liu27d24262020-09-18 19:04:59 -07001098 }
Shuo Qian4a594052020-01-23 11:59:30 -08001099
Hall Liu27d24262020-09-18 19:04:59 -07001100 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001103 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001104 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1105 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001106 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001107 // Service Class is a bit mask per 3gpp 27.007.
1108 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001109 if (callForwardResults.length > 1
1110 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001111 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001112 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001113 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1114 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001116 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 }
1118 } else {
1119 if (ar.result == null) {
1120 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1121 }
1122 if (ar.exception != null) {
1123 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1124 }
1125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1129 callForwardingStatus =
1130 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1131 }
1132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001141 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1142 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001143 break;
Hall Liu27d24262020-09-18 19:04:59 -07001144 }
Shuo Qian4a594052020-01-23 11:59:30 -08001145
Hall Liu27d24262020-09-18 19:04:59 -07001146 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001149 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1150 Consumer<Integer> callback =
1151 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1152 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001154 if (ar.exception instanceof CommandException) {
1155 CommandException.Error error =
1156 ((CommandException) (ar.exception)).getCommandError();
1157 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1158 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1159 } else {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1161 }
1162 } else {
1163 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1164 }
1165 } else {
1166 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1167 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001168 }
Shuo Qian4a594052020-01-23 11:59:30 -08001169 break;
Hall Liu27d24262020-09-18 19:04:59 -07001170 }
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 {
Sarah Chin428d1d62021-03-13 03:17:40 -08001649 request.result = new IllegalStateException(
1650 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001651 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
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001941 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001942 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);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001947 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001948 } else if (ar.result == null) {
1949 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001950 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001951 } else {
1952 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001953 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1954 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001955 }
1956
1957 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001958 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001959 }
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);
Grace Jia0ddb3612021-04-22 13:35:26 -07002169 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002171 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002172 mTelephonySharedPreferences =
2173 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002174 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002175 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002176 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002177 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 publish();
2180 }
2181
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002182 private Phone getDefaultPhone() {
2183 Phone thePhone = getPhone(getDefaultSubscription());
2184 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2185 }
2186
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 private void publish() {
2188 if (DBG) log("publish: " + this);
2189
Peter Wangc035ce42020-01-08 21:00:22 -08002190 TelephonyFrameworkInitializer
2191 .getTelephonyServiceManager()
2192 .getTelephonyServiceRegisterer()
2193 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
Stuart Scott584921c2015-01-15 17:10:34 -08002196 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002197 if (request.phone != null) {
2198 return request.phone;
2199 } else {
2200 return getPhoneFromSubId(request.subId);
2201 }
2202 }
2203
2204 private Phone getPhoneFromSubId(int subId) {
2205 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2206 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002207 }
2208
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002209 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2210 Phone phone = getPhoneFromRequest(request);
2211 return phone == null ? null :
2212 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2213 }
2214
Wink Saville36469e72014-06-11 15:17:00 -07002215 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002216 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002217 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219
Kai Shif70f46f2021-03-03 13:59:46 -08002220 private void sendEraseModemConfig(@NonNull Phone phone) {
2221 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2222 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2223 }
2224
2225 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2226 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2227 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002228 }
2229
Peter Wang44b186e2020-01-13 23:33:09 -08002230 private boolean isImsAvailableOnDevice() {
2231 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2232 if (pm == null) {
2233 // For some reason package manger is not available.. This will fail internally anyway,
2234 // so do not throw error and allow.
2235 return true;
2236 }
2237 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2238 }
2239
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002241 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
Wink Savilleb564aae2014-10-23 10:18:09 -07002244 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 if (DBG) log("dial: " + number);
2246 // No permission check needed here: This is just a wrapper around the
2247 // ACTION_DIAL intent, which is available to any app since it puts up
2248 // the UI before it does anything.
2249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 final long identity = Binder.clearCallingIdentity();
2251 try {
2252 String url = createTelUrl(number);
2253 if (url == null) {
2254 return;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 // PENDING: should we just silently fail if phone is offhook or ringing?
2258 PhoneConstants.State state = mCM.getState(subId);
2259 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2260 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2262 mApp.startActivity(intent);
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267 }
2268
2269 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002270 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 if (DBG) log("call: " + number);
2275
2276 // This is just a wrapper around the ACTION_CALL intent, but we still
2277 // need to do a permission check since we're calling startActivity()
2278 // from the context of the phone app.
2279 enforceCallPermission();
2280
Jordan Liu1617b712019-07-10 15:06:26 -07002281 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 != AppOpsManager.MODE_ALLOWED) {
2283 return;
2284 }
2285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 String url = createTelUrl(number);
2289 if (url == null) {
2290 return;
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 boolean isValid = false;
2294 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2295 if (slist != null) {
2296 for (SubscriptionInfo subInfoRecord : slist) {
2297 if (subInfoRecord.getSubscriptionId() == subId) {
2298 isValid = true;
2299 break;
2300 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002301 }
Wink Saville08874612014-08-31 19:19:58 -07002302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 if (!isValid) {
2304 return;
2305 }
Wink Saville08874612014-08-31 19:19:58 -07002306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2308 intent.putExtra(SUBSCRIPTION_KEY, subId);
2309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2310 mApp.startActivity(intent);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
Wink Savilleb564aae2014-10-23 10:18:09 -07002316 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002317 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2319 }
2320
Wink Savilleb564aae2014-10-23 10:18:09 -07002321 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002322 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002323 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2324 }
2325
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002331 Phone phone = getPhone(subId);
2332 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333 checkSimPin.start();
2334 return checkSimPin.unlockSim(null, pin);
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
2337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
2339
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002345 Phone phone = getPhone(subId);
2346 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 checkSimPuk.start();
2348 return checkSimPuk.unlockSim(puk, pin);
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 * a synchronous one.
2357 */
2358 private static class UnlockSim extends Thread {
2359
2360 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002361 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362
2363 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002364 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2365 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
2367 // For replies from SimCard interface
2368 private Handler mHandler;
2369
2370 // For async handler to identify request type
2371 private static final int SUPPLY_PIN_COMPLETE = 100;
2372
Michele Berionne5e411512020-11-13 02:36:59 +00002373 UnlockSim(int phoneId, IccCard simCard) {
2374 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 mSimCard = simCard;
2376 }
2377
2378 @Override
2379 public void run() {
2380 Looper.prepare();
2381 synchronized (UnlockSim.this) {
2382 mHandler = new Handler() {
2383 @Override
2384 public void handleMessage(Message msg) {
2385 AsyncResult ar = (AsyncResult) msg.obj;
2386 switch (msg.what) {
2387 case SUPPLY_PIN_COMPLETE:
2388 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2389 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002390 mRetryCount = msg.arg1;
2391 if (ar.exception != null) {
2392 if (ar.exception instanceof CommandException &&
2393 ((CommandException)(ar.exception)).getCommandError()
2394 == CommandException.Error.PASSWORD_INCORRECT) {
2395 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002396 } //When UiccCardApp dispose,handle message and return exception
2397 else if (ar.exception instanceof CommandException &&
2398 ((CommandException) (ar.exception)).getCommandError()
2399 == CommandException.Error.ABORTED) {
2400 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002401 } else {
2402 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2403 }
2404 } else {
2405 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 mDone = true;
2408 UnlockSim.this.notifyAll();
2409 }
2410 break;
2411 }
2412 }
2413 };
2414 UnlockSim.this.notifyAll();
2415 }
2416 Looper.loop();
2417 }
2418
2419 /*
2420 * Use PIN or PUK to unlock SIM card
2421 *
2422 * If PUK is null, unlock SIM card with PIN
2423 *
2424 * If PUK is not null, unlock SIM card with PUK and set PIN code
2425 */
Wink Saville9de0f752013-10-22 19:04:03 -07002426 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
2428 while (mHandler == null) {
2429 try {
2430 wait();
2431 } catch (InterruptedException e) {
2432 Thread.currentThread().interrupt();
2433 }
2434 }
2435 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2436
2437 if (puk == null) {
2438 mSimCard.supplyPin(pin, callback);
2439 } else {
2440 mSimCard.supplyPuk(puk, pin, callback);
2441 }
2442
2443 while (!mDone) {
2444 try {
2445 Log.d(LOG_TAG, "wait for done");
2446 wait();
2447 } catch (InterruptedException e) {
2448 // Restore the interrupted status
2449 Thread.currentThread().interrupt();
2450 }
2451 }
2452 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002453 int[] resultArray = new int[2];
2454 resultArray[0] = mResult;
2455 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002456
2457 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2458 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2459 }
2460
Wink Saville9de0f752013-10-22 19:04:03 -07002461 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463 }
2464
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002465 /**
2466 * This method has been removed due to privacy and stability concerns.
2467 */
2468 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002470 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2471 return;
Wink Saville36469e72014-06-11 15:17:00 -07002472 }
2473
Nathan Harold1f889d82020-06-04 17:05:26 -07002474 @Override
2475 public void updateServiceLocationWithPackageName(String callingPackage) {
2476 mApp.getSystemService(AppOpsManager.class)
2477 .checkPackage(Binder.getCallingUid(), callingPackage);
2478
Nathan Haroldf096d982020-11-18 17:18:06 -08002479 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002480 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2481 // Callers targeting S have no business invoking this method.
2482 return;
2483 }
2484
2485 LocationAccessPolicy.LocationPermissionResult locationResult =
2486 LocationAccessPolicy.checkLocationPermission(mApp,
2487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2488 .setCallingPackage(callingPackage)
2489 .setCallingFeatureId(null)
2490 .setCallingPid(Binder.getCallingPid())
2491 .setCallingUid(Binder.getCallingUid())
2492 .setMethod("updateServiceLocation")
2493 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 // Apps that lack location permission have no business calling this method;
2497 // however, because no permission was declared in the public API, denials must
2498 // all be "soft".
2499 switch (locationResult) {
2500 case DENIED_HARD: /* fall through */
2501 case DENIED_SOFT:
2502 return;
2503 }
2504
2505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002508 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002510 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002517 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002518 @Override
2519 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 return isRadioOnWithFeature(callingPackage, null);
2521 }
2522
2523
2524 @Override
2525 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2526 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2527 callingFeatureId);
2528 }
2529
2530 @Deprecated
2531 @Override
2532 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2533 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002537 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2538 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002540 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002541 return false;
2542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 return isRadioOnForSubscriber(subId);
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 }
2551
2552 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2558 } else {
2559 return false;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002567 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
Wink Saville36469e72014-06-11 15:17:00 -07002569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 final Phone phone = getPhone(subId);
2576 if (phone != null) {
2577 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
2584 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002585 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
Wink Savilleb564aae2014-10-23 10:18:09 -07002588 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
2594 if (phone == null) {
2595 return false;
2596 }
2597 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2598 toggleRadioOnOffForSubscriber(subId);
2599 }
2600 return true;
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
Wink Saville36469e72014-06-11 15:17:00 -07002605
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002606 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002607 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002608 /*
2609 * If any of the Radios are available, it will need to be
2610 * shutdown. So return true if any Radio is available.
2611 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2615 Phone phone = PhoneFactory.getPhone(i);
2616 if (phone != null && phone.isRadioAvailable()) return true;
2617 }
2618 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2619 return false;
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002622 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002623 }
2624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002626 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 enforceModifyPermission();
2628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2632 logv("Shutting down Phone " + i);
2633 shutdownRadioUsingPhoneId(i);
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002637 }
2638 }
2639
2640 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002641 Phone phone = PhoneFactory.getPhone(phoneId);
2642 if (phone != null && phone.isRadioAvailable()) {
2643 phone.shutdownRadio();
2644 }
2645 }
2646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2653 if (defaultPhone != null) {
2654 defaultPhone.setRadioPower(turnOn);
2655 return true;
2656 } else {
2657 loge("There's no default phone.");
2658 return false;
2659 }
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002662 }
Wink Saville36469e72014-06-11 15:17:00 -07002663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 phone.setRadioPower(turnOn);
2673 return true;
2674 } else {
2675 return false;
2676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
2681
Wink Saville36469e72014-06-11 15:17:00 -07002682 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 public boolean enableDataConnectivity() {
2685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 int subId = mSubscriptionController.getDefaultDataSubId();
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002692 phone.getDataEnabledSettings().setDataEnabled(
2693 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 return true;
2695 } else {
2696 return false;
2697 }
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
Wink Saville36469e72014-06-11 15:17:00 -07002703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 public boolean disableDataConnectivity() {
2706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 int subId = mSubscriptionController.getDefaultDataSubId();
2711 final Phone phone = getPhone(subId);
2712 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002713 phone.getDataEnabledSettings().setDataEnabled(
2714 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 return true;
2716 } else {
2717 return false;
2718 }
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002725 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 final Phone phone = getPhone(subId);
2729 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002730 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 } else {
2732 return false;
2733 }
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
2739 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002740 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
pkanwarae03a6b2016-11-06 20:37:09 -08002743 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 enforceCallPermission();
2745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2749 return;
2750 }
2751 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2752 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
pkanwar32d516d2016-10-14 19:37:38 -07002756 };
2757
Wink Savilleb564aae2014-10-23 10:18:09 -07002758 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2764 return false;
2765 }
2766 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002772 /**
2773 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2774 * tag on getCallState Binder call.
2775 */
2776 @Deprecated
2777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002779 if (CompatChanges.isChangeEnabled(
2780 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2781 Binder.getCallingUid())) {
2782 // Do not allow this API to be called on API version 31+, it should only be
2783 // called on old apps using this Binder call directly.
2784 throw new SecurityException("This method can only be used for applications "
2785 + "targeting API version 30 or less.");
2786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002789 Phone phone = getPhone(getDefaultSubscription());
2790 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2791 PhoneConstantConversions.convertCallState(phone.getState());
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
2795 }
2796
2797 @Override
2798 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2799 if (CompatChanges.isChangeEnabled(
2800 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2801 Binder.getCallingUid())) {
2802 // Check READ_PHONE_STATE for API version 31+
2803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2804 featureId, "getCallStateForSubscription")) {
2805 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2806 + "targeting API level 31+.");
2807 }
2808 }
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2813 PhoneConstantConversions.convertCallState(phone.getState());
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002820 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002821 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2822 }
2823
2824 @Override
2825 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002828 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 if (phone != null) {
2830 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2831 } else {
2832 return PhoneConstantConversions.convertDataState(
2833 PhoneConstants.DataState.DISCONNECTED);
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002841 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002842 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2843 }
2844
2845 @Override
2846 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 if (phone != null) {
2851 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2852 } else {
2853 return TelephonyManager.DATA_ACTIVITY_NONE;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 }
2859
2860 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002861 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002863 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002864
2865 LocationAccessPolicy.LocationPermissionResult locationResult =
2866 LocationAccessPolicy.checkLocationPermission(mApp,
2867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2868 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002869 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002870 .setCallingPid(Binder.getCallingPid())
2871 .setCallingUid(Binder.getCallingUid())
2872 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002873 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2875 .build());
2876 switch (locationResult) {
2877 case DENIED_HARD:
2878 throw new SecurityException("Not allowed to access cell location");
2879 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002880 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2881 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002888 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002889 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 } finally {
2891 Binder.restoreCallingIdentity(identity);
2892 }
Svetoslav64fad262015-04-14 14:35:21 -07002893 }
2894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002896 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002897 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2898 // registered cell info, so return a NULL country instead.
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002901 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2902 // Get default phone in this case.
2903 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2904 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002905 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002907 if (phone == null) return "";
2908 ServiceStateTracker sst = phone.getServiceStateTracker();
2909 if (sst == null) return "";
2910 LocaleTracker lt = sst.getLocaleTracker();
2911 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002912 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002916 }
2917
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002918 /**
2919 * This method was removed due to potential issues caused by performing partial
2920 * updates of service state, and lack of a credible use case.
2921 *
2922 * This has the ability to break the telephony implementation by disabling notification of
2923 * changes in device connectivity. DO NOT USE THIS!
2924 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002925 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 public void enableLocationUpdates() {
2927 mApp.enforceCallingOrSelfPermission(
2928 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002931 /**
2932 * This method was removed due to potential issues caused by performing partial
2933 * updates of service state, and lack of a credible use case.
2934 *
2935 * This has the ability to break the telephony implementation by disabling notification of
2936 * changes in device connectivity. DO NOT USE THIS!
2937 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 @Override
2939 public void disableLocationUpdates() {
2940 mApp.enforceCallingOrSelfPermission(
2941 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
2944 @Override
2945 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002946 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2947 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002948 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002949 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2950 throw new SecurityException(
2951 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2952 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002953
Jordan Liu1617b712019-07-10 15:06:26 -07002954 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2956 return null;
2957 }
Svetoslav64fad262015-04-14 14:35:21 -07002958
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002959 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002961 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002962 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963
Nathan Haroldf180aac2018-06-01 18:43:55 -07002964 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2965 for (CellInfo ci : info) {
2966 if (ci instanceof CellInfoGsm) {
2967 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2968 } else if (ci instanceof CellInfoWcdma) {
2969 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002972 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002975 private List<CellInfo> getCachedCellInfo() {
2976 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2977 for (Phone phone : PhoneFactory.getPhones()) {
2978 List<CellInfo> info = phone.getAllCellInfo();
2979 if (info != null) cellInfos.addAll(info);
2980 }
2981 return cellInfos;
2982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983
2984 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002985 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002987 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002988
2989 LocationAccessPolicy.LocationPermissionResult locationResult =
2990 LocationAccessPolicy.checkLocationPermission(mApp,
2991 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2992 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002993 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002994 .setCallingPid(Binder.getCallingPid())
2995 .setCallingUid(Binder.getCallingUid())
2996 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002997 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2999 .build());
3000 switch (locationResult) {
3001 case DENIED_HARD:
3002 throw new SecurityException("Not allowed to access cell info");
3003 case DENIED_SOFT:
3004 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
Nathan Haroldf096d982020-11-18 17:18:06 -08003007 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003008 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3009 return getCachedCellInfo();
3010 }
3011
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003012 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003013 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3017 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003018 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003019 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 if (info != null) cellInfos.addAll(info);
3021 }
3022 return cellInfos;
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 }
3026 }
3027
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003028 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003029 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3030 String callingFeatureId) {
3031 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3032 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003033 }
3034
3035 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003036 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3037 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003038 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003039 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003040 }
3041
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3043 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003045 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003046
3047 LocationAccessPolicy.LocationPermissionResult locationResult =
3048 LocationAccessPolicy.checkLocationPermission(mApp,
3049 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3050 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003051 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003052 .setCallingPid(Binder.getCallingPid())
3053 .setCallingUid(Binder.getCallingUid())
3054 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003055 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3056 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003057 .build());
3058 switch (locationResult) {
3059 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003060 if (TelephonyPermissions
3061 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003062 // Safetynet logging for b/154934934
3063 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3064 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003065 throw new SecurityException("Not allowed to access cell info");
3066 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003067 if (TelephonyPermissions
3068 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003069 // Safetynet logging for b/154934934
3070 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3071 }
Nathan Harold5320c422019-05-09 10:26:08 -07003072 try {
3073 cb.onCellInfo(new ArrayList<CellInfo>());
3074 } catch (RemoteException re) {
3075 // Drop without consequences
3076 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003077 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003078 }
3079
Nathan Harolda939a962019-05-09 10:13:47 -07003080
3081 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003082 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3083
3084 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3085 }
3086
3087 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003089 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Shishir Agrawala9f32182016-04-12 12:00:16 -07003100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003101 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 Phone phone = PhoneFactory.getPhone(slotIndex);
3103 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 return null;
3105 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003107 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003108 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003109 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003110 return null;
3111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 return phone.getImei();
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003119 }
3120
3121 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003122 public String getTypeAllocationCodeForSlot(int slotIndex) {
3123 Phone phone = PhoneFactory.getPhone(slotIndex);
3124 String tac = null;
3125 if (phone != null) {
3126 String imei = phone.getImei();
3127 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3128 }
3129 return tac;
3130 }
3131
3132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003133 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003134 try {
3135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3136 } catch (SecurityException se) {
3137 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3138 throw new SecurityException("Package " + callingPackage + " does not belong to "
3139 + Binder.getCallingUid());
3140 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003141 Phone phone = PhoneFactory.getPhone(slotIndex);
3142 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003143 return null;
3144 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003145
Jeff Davidson913390f2018-02-23 17:11:49 -08003146 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003147 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003148 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003149 return null;
3150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151
3152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 return phone.getMeid();
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
Jack Yu2af8d712017-03-15 17:14:14 -07003158 }
3159
3160 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003161 public String getManufacturerCodeForSlot(int slotIndex) {
3162 Phone phone = PhoneFactory.getPhone(slotIndex);
3163 String manufacturerCode = null;
3164 if (phone != null) {
3165 String meid = phone.getMeid();
3166 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3167 }
3168 return manufacturerCode;
3169 }
3170
3171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003172 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3173 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003174 Phone phone = PhoneFactory.getPhone(slotIndex);
3175 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003176 return null;
3177 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003178 int subId = phone.getSubId();
3179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 mApp, subId, callingPackage, callingFeatureId,
3181 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003182 return null;
3183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 return phone.getDeviceSvn();
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003191 }
3192
fionaxu43304da2017-11-27 22:51:16 -08003193 @Override
3194 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 final Phone phone = getPhone(subId);
3198 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
fionaxu43304da2017-11-27 22:51:16 -08003202 }
3203
3204 @Override
3205 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 final Phone phone = getPhone(subId);
3209 return phone == null ? null : phone.getCarrierName();
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
fionaxu43304da2017-11-27 22:51:16 -08003213 }
3214
calvinpanffe225e2018-11-01 19:43:06 +08003215 @Override
chen xu0026ca62019-03-06 15:28:50 -08003216 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003217 final long identity = Binder.clearCallingIdentity();
3218 try {
3219 final Phone phone = getPhone(subId);
3220 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003221 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
3226
3227 @Override
chen xu0026ca62019-03-06 15:28:50 -08003228 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003232 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003233 } finally {
3234 Binder.restoreCallingIdentity(identity);
3235 }
3236 }
3237
chen xu651eec72018-11-11 19:03:44 -08003238 @Override
chen xu864e11c2018-12-06 22:10:03 -08003239 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3240 if (!isSubscriptionMccMnc) {
3241 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3242 }
chen xu651eec72018-11-11 19:03:44 -08003243 final Phone phone = PhoneFactory.getPhone(slotIndex);
3244 if (phone == null) {
3245 return TelephonyManager.UNKNOWN_CARRIER_ID;
3246 }
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
3252 }
3253 }
3254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003255 //
3256 // Internal helper methods.
3257 //
3258
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003259 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003260 * Make sure the caller is the calling package itself
3261 *
3262 * @throws SecurityException if the caller is not the calling package
3263 */
3264 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3265 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003266 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3267 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003268 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003269 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003270 } catch (PackageManager.NameNotFoundException e) {
3271 // packageUid is -1
3272 }
3273 if (packageUid != callingUid) {
3274 throw new SecurityException(message + ": Package " + callingPackage
3275 + " does not belong to " + callingUid);
3276 }
3277 }
3278
3279 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3281 *
3282 * @throws SecurityException if the caller does not have the required permission
3283 */
3284 private void enforceModifyPermission() {
3285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3286 }
3287
Shuo Qiancd19c462020-01-16 20:51:11 -08003288 /**
3289 * Make sure the caller is system.
3290 *
3291 * @throws SecurityException if the caller is not system.
3292 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003293 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003294 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3295 throw new SecurityException("Caller must be system");
3296 }
3297 }
3298
Shuo Qian3b6ee772019-11-13 17:43:31 -08003299 private void enforceActiveEmergencySessionPermission() {
3300 mApp.enforceCallingOrSelfPermission(
3301 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3302 }
3303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 /**
3305 * Make sure the caller has the CALL_PHONE permission.
3306 *
3307 * @throws SecurityException if the caller does not have the required permission
3308 */
3309 private void enforceCallPermission() {
3310 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3311 }
3312
paulhu5a773602019-08-23 19:17:33 +08003313 private void enforceSettingsPermission() {
3314 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003315 }
3316
Michele Berionne5e411512020-11-13 02:36:59 +00003317 private void enforceRebootPermission() {
3318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3319 }
3320
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 private String createTelUrl(String number) {
3322 if (TextUtils.isEmpty(number)) {
3323 return null;
3324 }
3325
Jake Hambye994d462014-02-03 13:10:13 -08003326 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 }
3328
Ihab Awadf9e92732013-12-05 18:02:52 -08003329 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003330 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3331 }
3332
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003333 private static void logv(String msg) {
3334 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3335 }
3336
Ihab Awadf9e92732013-12-05 18:02:52 -08003337 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3339 }
3340
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003341 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003342 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003343 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003344 }
3345
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003347 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = PhoneFactory.getPhone(slotIndex);
3351 if (phone == null) {
3352 return PhoneConstants.PHONE_TYPE_NONE;
3353 } else {
3354 return phone.getPhoneType();
3355 }
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 }
3360
3361 /**
3362 * Returns the CDMA ERI icon index to display
3363 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3366 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3367 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003368 }
3369
Sanket Padawe356d7632015-06-22 14:03:32 -07003370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3372 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 mApp, subId, callingPackage, callingFeatureId,
3375 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003376 return -1;
3377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 final Phone phone = getPhone(subId);
3382 if (phone != null) {
3383 return phone.getCdmaEriIconIndex();
3384 } else {
3385 return -1;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
3392 /**
3393 * Returns the CDMA ERI icon mode,
3394 * 0 - ON
3395 * 1 - FLASHING
3396 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003398 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3399 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3400 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003401 }
3402
Sanket Padawe356d7632015-06-22 14:03:32 -07003403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003404 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3405 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003407 mApp, subId, callingPackage, callingFeatureId,
3408 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003409 return -1;
3410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 final Phone phone = getPhone(subId);
3415 if (phone != null) {
3416 return phone.getCdmaEriIconMode();
3417 } else {
3418 return -1;
3419 }
3420 } finally {
3421 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 }
3424
3425 /**
3426 * Returns the CDMA ERI text,
3427 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3430 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3431 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003432 }
3433
Sanket Padawe356d7632015-06-22 14:03:32 -07003434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003435 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3436 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003438 mApp, subId, callingPackage, callingFeatureId,
3439 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003440 return null;
3441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442
3443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 final Phone phone = getPhone(subId);
3446 if (phone != null) {
3447 return phone.getCdmaEriText();
3448 } else {
3449 return null;
3450 }
3451 } finally {
3452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003454 }
3455
3456 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003457 * Returns the CDMA MDN.
3458 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003459 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003460 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3462 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
3464 final long identity = Binder.clearCallingIdentity();
3465 try {
3466 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468 return phone.getLine1Number();
3469 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003470 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471 return null;
3472 }
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003475 }
3476 }
3477
3478 /**
3479 * Returns the CDMA MIN.
3480 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003481 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003482 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3484 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003485
3486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3490 return phone.getCdmaMin();
3491 } else {
3492 return null;
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003496 }
3497 }
3498
Hall Liud892bec2018-11-30 14:51:45 -08003499 @Override
3500 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3501 INumberVerificationCallback callback, String callingPackage) {
3502 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3503 != PERMISSION_GRANTED) {
3504 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3505 }
3506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3507
3508 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3509 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003510 throw new SecurityException("Calling package must be configured in the device config: "
3511 + "calling package: " + callingPackage
3512 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003513 }
3514
3515 if (range == null) {
3516 throw new NullPointerException("Range must be non-null");
3517 }
3518
3519 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003520 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003521
3522 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3523 }
3524
Junda Liuca05d5d2014-08-14 22:36:34 -07003525 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 * Returns true if CDMA provisioning needs to run.
3527 */
3528 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 final long identity = Binder.clearCallingIdentity();
3530 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003531 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003535 }
3536
3537 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003538 * Sets the voice mail number of a given subId.
3539 */
3540 @Override
3541 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003542 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3543 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3548 new Pair<String, String>(alphaTag, number), new Integer(subId));
3549 return success;
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003553 }
3554
Ta-wei Yen87c49842016-05-13 21:19:52 -07003555 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003556 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003558 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3559 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003560 if (!TextUtils.equals(callingPackage, systemDialer)) {
3561 throw new SecurityException("caller must be system dialer");
3562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3567 if (phoneAccountHandle == null) {
3568 return null;
3569 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003573 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003574 }
3575
3576 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003577 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3578 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003581 mApp, subId, callingPackage, callingFeatureId,
3582 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003583 return null;
3584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003586 final long identity = Binder.clearCallingIdentity();
3587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003592 }
3593
3594 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003595 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3596 VisualVoicemailSmsFilterSettings settings) {
3597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003602 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603 } finally {
3604 Binder.restoreCallingIdentity(identity);
3605 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003606 }
3607
3608 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003609 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611
3612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003615 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616 } finally {
3617 Binder.restoreCallingIdentity(identity);
3618 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003619 }
3620
3621 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003622 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3623 String callingPackage, int subId) {
3624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625
3626 final long identity = Binder.clearCallingIdentity();
3627 try {
3628 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003629 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003633 }
3634
3635 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003636 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638
3639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003646 }
3647
3648 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003649 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3650 String callingAttributionTag, int subId, String number, int port, String text,
3651 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003653 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003654 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003655 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003656 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3657 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003658 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003659
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003660 /**
fionaxu0152e512016-11-14 13:36:14 -08003661 * Sets the voice activation state of a given subId.
3662 */
3663 @Override
3664 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3666 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667
3668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 final Phone phone = getPhone(subId);
3671 if (phone != null) {
3672 phone.setVoiceActivationState(activationState);
3673 } else {
3674 loge("setVoiceActivationState fails with invalid subId: " + subId);
3675 }
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003678 }
3679 }
3680
3681 /**
3682 * Sets the data activation state of a given subId.
3683 */
3684 @Override
3685 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3687 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 final Phone phone = getPhone(subId);
3692 if (phone != null) {
3693 phone.setDataActivationState(activationState);
3694 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003695 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 }
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003699 }
3700 }
3701
3702 /**
3703 * Returns the voice activation state of a given subId.
3704 */
3705 @Override
3706 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
fionaxu0152e512016-11-14 13:36:14 -08003709 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 if (phone != null) {
3713 return phone.getVoiceActivationState();
3714 } else {
3715 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3716 }
3717 } finally {
3718 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003719 }
3720 }
3721
3722 /**
3723 * Returns the data activation state of a given subId.
3724 */
3725 @Override
3726 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
fionaxu0152e512016-11-14 13:36:14 -08003729 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 if (phone != null) {
3733 return phone.getDataActivationState();
3734 } else {
3735 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3736 }
3737 } finally {
3738 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003739 }
3740 }
3741
3742 /**
Wink Saville36469e72014-06-11 15:17:00 -07003743 * Returns the unread count of voicemails for a subId
3744 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003745 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003746 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3747 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003749 mApp, subId, callingPackage, callingFeatureId,
3750 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003751 return 0;
3752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 final Phone phone = getPhone(subId);
3756 if (phone != null) {
3757 return phone.getVoiceMessageCount();
3758 } else {
3759 return 0;
3760 }
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003764 }
3765
3766 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003767 * returns true, if the device is in a state where both voice and data
3768 * are supported simultaneously. This can change based on location or network condition.
3769 */
3770 @Override
3771 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 final Phone phone = getPhone(subId);
3775 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003779 }
3780
3781 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003782 * Send the dialer code if called from the current default dialer or the caller has
3783 * carrier privilege.
3784 * @param inputCode The dialer code to send
3785 */
3786 @Override
3787 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003790 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3791 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003792 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003793 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003794 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 } finally {
3801 Binder.restoreCallingIdentity(identity);
3802 }
fionaxu235cc5e2017-03-06 22:25:57 -08003803 }
3804
Pengquan Menga1bb6272018-09-06 09:59:22 -07003805 @Override
3806 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003807 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003808 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003809 mApp, subId, "getNetworkSelectionMode");
3810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 if (!isActiveSubscription(subId)) {
3813 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3814 }
3815 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003818 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003819 }
3820
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003822 public boolean isInEmergencySmsMode() {
3823 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 for (Phone phone : PhoneFactory.getPhones()) {
3827 if (phone.isInEmergencySmsMode()) {
3828 return true;
3829 }
3830 }
3831 } finally {
3832 Binder.restoreCallingIdentity(identity);
3833 }
3834 return false;
3835 }
3836
shilu366312e2019-12-17 09:28:10 -08003837 /**
3838 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3839 * @param subId The subscription to use to check the configuration.
3840 * @param c The callback that will be used to send the result.
3841 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003843 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3844 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003845 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003846 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003847
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003848 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3849 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3850 "IMS not available on device.");
3851 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 final long token = Binder.clearCallingIdentity();
3853 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003854 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003857 } catch (ImsException e) {
3858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 } finally {
3860 Binder.restoreCallingIdentity(token);
3861 }
3862 }
3863
shilu366312e2019-12-17 09:28:10 -08003864 /**
3865 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3866 * @param subId The subscription to use to check the configuration.
3867 * @param c The callback that will be used to send the result.
3868 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003870 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003871 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003872 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3875 }
Meng Wangafbc5852019-09-19 17:37:13 -07003876 final long token = Binder.clearCallingIdentity();
3877 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003878 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3880 .removeRegistrationCallbackForSubscription(c, subId);
3881 } catch (ImsException e) {
3882 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3883 + "is inactive, ignoring unregister.");
3884 // If the subscription is no longer active, just return, since the callback
3885 // will already have been removed internally.
3886 } finally {
3887 Binder.restoreCallingIdentity(token);
3888 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 }
3890
Brad Ebingera34a6c22019-10-22 17:36:18 -07003891 /**
3892 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3893 */
3894 @Override
3895 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3896 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3897 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3898 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3899 "IMS not available on device.");
3900 }
3901 final long token = Binder.clearCallingIdentity();
3902 try {
3903 Phone phone = getPhone(subId);
3904 if (phone == null) {
3905 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3906 + subId + "'");
3907 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3908 }
3909 phone.getImsRegistrationState(regState -> {
3910 try {
3911 consumer.accept((regState == null)
3912 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3913 } catch (RemoteException e) {
3914 // Ignore if the remote process is no longer available to call back.
3915 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3916 }
3917 });
3918 } finally {
3919 Binder.restoreCallingIdentity(token);
3920 }
3921 }
3922
3923 /**
3924 * Get the transport type for the IMS service registration state.
3925 */
3926 @Override
3927 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003928 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003929 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003930 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3931 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3932 "IMS not available on device.");
3933 }
3934 final long token = Binder.clearCallingIdentity();
3935 try {
3936 Phone phone = getPhone(subId);
3937 if (phone == null) {
3938 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3939 + subId + "'");
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3941 }
3942 phone.getImsRegistrationTech(regTech -> {
3943 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3944 int regTechConverted = (regTech == null)
3945 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3946 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3947 regTechConverted);
3948 try {
3949 consumer.accept(regTechConverted);
3950 } catch (RemoteException e) {
3951 // Ignore if the remote process is no longer available to call back.
3952 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3953 }
3954 });
3955 } finally {
3956 Binder.restoreCallingIdentity(token);
3957 }
3958 }
3959
shilu366312e2019-12-17 09:28:10 -08003960 /**
3961 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3962 * @param subId The subscription to use to check the configuration.
3963 * @param c The callback that will be used to send the result.
3964 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003966 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3967 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003969 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003970 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3971 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3972 "IMS not available on device.");
3973 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3975 final long token = Binder.clearCallingIdentity();
3976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003979 } catch (ImsException e) {
3980 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 } finally {
3982 Binder.restoreCallingIdentity(token);
3983 }
3984 }
3985
shilu366312e2019-12-17 09:28:10 -08003986 /**
3987 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3988 * @param subId The subscription to use to check the configuration.
3989 * @param c The callback that will be used to send the result.
3990 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003992 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003993 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003994 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003995 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3996 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3997 }
Meng Wangafbc5852019-09-19 17:37:13 -07003998
3999 final long token = Binder.clearCallingIdentity();
4000 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07004001 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07004002 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004003 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004004 } catch (ImsException e) {
4005 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4006 + "is inactive, ignoring unregister.");
4007 // If the subscription is no longer active, just return, since the callback
4008 // will already have been removed internally.
4009 } finally {
4010 Binder.restoreCallingIdentity(token);
4011 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 }
4013
4014 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004015 public boolean isCapable(int subId, int capability, int regTech) {
4016 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4018 final long token = Binder.clearCallingIdentity();
4019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004020 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004022 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4024 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004025 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004026 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4027 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 } finally {
4029 Binder.restoreCallingIdentity(token);
4030 }
4031 }
4032
4033 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004034 public boolean isAvailable(int subId, int capability, int regTech) {
4035 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 final long token = Binder.clearCallingIdentity();
4037 try {
4038 Phone phone = getPhone(subId);
4039 if (phone == null) return false;
4040 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004041 } catch (com.android.ims.ImsException e) {
4042 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4043 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 } finally {
4045 Binder.restoreCallingIdentity(token);
4046 }
4047 }
4048
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004049 /**
4050 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4051 * subscription.
4052 * @param subId The subscription to use to check the configuration.
4053 * @param callback The callback that will be used to send the result.
4054 * @param capability The MmTelFeature capability that will be used to send the result.
4055 * @param transportType The transport type of the MmTelFeature capability.
4056 */
4057 @Override
4058 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4059 int transportType) {
4060 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4063 "IMS not available on device.");
4064 }
4065 final long token = Binder.clearCallingIdentity();
4066 try {
4067 int slotId = getSlotIndex(subId);
4068 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4069 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4070 + subId + "'");
4071 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4072 }
4073 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4074 transportType, aBoolean -> {
4075 try {
4076 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4077 } catch (RemoteException e) {
4078 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4079 + "running. Ignore");
4080 }
4081 });
4082 } finally {
4083 Binder.restoreCallingIdentity(token);
4084 }
4085 }
4086
shilu366312e2019-12-17 09:28:10 -08004087 /**
4088 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4089 * @param subId The subscription to use to check the configuration.
4090 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 @Override
4092 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004093 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004094 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004095
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4097 final long token = Binder.clearCallingIdentity();
4098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(token);
4105 }
4106 }
4107
4108 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004109 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004111 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (ImsException e) {
4118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
shilu366312e2019-12-17 09:28:10 -08004124 /**
4125 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4126 * @param subId The subscription to use to check the configuration.
4127 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004129 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004130 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004131 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4136 } catch (ImsException e) {
4137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004144 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004146 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 final long identity = Binder.clearCallingIdentity();
4148 try {
4149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
shilu366312e2019-12-17 09:28:10 -08004158 /**
4159 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4160 * @param subId The subscription to use to check the configuration.
4161 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 @Override
4163 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004164 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004165 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004171 } catch (ImsException e) {
4172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 }
4177
4178 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004179 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004181 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004185 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
shilu366312e2019-12-17 09:28:10 -08004193 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004194 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4195 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4196 * @param subId The subscription to use to check the configuration.
4197 */
4198 @Override
4199 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004200 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004201 mApp, subId, "isCrossSimCallingEnabledByUser");
4202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4205 return ImsManager.getInstance(mApp,
4206 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4207 } catch (ImsException e) {
4208 throw new ServiceSpecificException(e.getCode());
4209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
4214 /**
4215 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4216 * Requires MODIFY_PHONE_STATE permission.
4217 * @param subId The subscription to use to check the configuration.
4218 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4219 * false otherwise
4220 */
4221 @Override
4222 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4224 "setCrossSimCallingEnabled");
4225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4228 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4229 .setCrossSimCallingEnabled(isEnabled);
4230 } catch (ImsException e) {
4231 throw new ServiceSpecificException(e.getCode());
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
4235 }
4236
4237 /**
shilu366312e2019-12-17 09:28:10 -08004238 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4239 * @param subId The subscription to use to check the configuration.
4240 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004242
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004244 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004245 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004249 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004251 } catch (ImsException e) {
4252 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
4258 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004259 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004261 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004265 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004267 } catch (ImsException e) {
4268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
4272 }
4273
4274 @Override
4275 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4277 "setVoWiFiNonPersistent");
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
4280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004281 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004282 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004283 } catch (ImsException e) {
4284 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 } finally {
4286 Binder.restoreCallingIdentity(identity);
4287 }
4288 }
4289
shilu366312e2019-12-17 09:28:10 -08004290 /**
4291 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4292 * @param subId The subscription to use to check the configuration.
4293 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 @Override
4295 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004296 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004297 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004301 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004303 } catch (ImsException e) {
4304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004305 } finally {
4306 Binder.restoreCallingIdentity(identity);
4307 }
4308 }
4309
4310 @Override
4311 public void setVoWiFiModeSetting(int subId, int mode) {
4312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4313 "setVoWiFiModeSetting");
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004317 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004319 } catch (ImsException e) {
4320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
4326 @Override
4327 public int getVoWiFiRoamingModeSetting(int subId) {
4328 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
4331 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004332 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004334 } catch (ImsException e) {
4335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
4339 }
4340
4341 @Override
4342 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4344 "setVoWiFiRoamingModeSetting");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004348 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
4357 @Override
4358 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4360 "setRttCapabilityEnabled");
4361 final long identity = Binder.clearCallingIdentity();
4362 try {
4363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004364 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4365 } catch (ImsException e) {
4366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
4370 }
4371
shilu366312e2019-12-17 09:28:10 -08004372 /**
4373 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4374 * @param subId The subscription to use to check the configuration.
4375 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 @Override
4377 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004378 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004379 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004383 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004385 } catch (ImsException e) {
4386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(identity);
4389 }
4390 }
4391
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004392 @Override
4393 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4394 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004397 if (!isImsAvailableOnDevice()) {
4398 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4399 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004400 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004402 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004403 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004404 } catch (ImsException e) {
4405 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
4409 }
4410
4411 @Override
4412 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4413 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4414 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004418 try {
4419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004421 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004422 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004423 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4424 + "is inactive, ignoring unregister.");
4425 // If the subscription is no longer active, just return, since the callback will already
4426 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
allenwtsu99c623b2020-01-03 18:24:23 +08004432
4433 private void checkModifyPhoneStatePermission(int subId, String message) {
4434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4435 message);
4436 }
4437
4438 private boolean isImsProvisioningRequired(int subId, int capability,
4439 boolean isMmtelCapability) {
4440 Phone phone = getPhone(subId);
4441 if (phone == null) {
4442 loge("phone instance null for subid " + subId);
4443 return false;
4444 }
4445 if (isMmtelCapability) {
4446 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4447 return false;
4448 }
4449 } else {
4450 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4451 return false;
4452 }
4453 }
4454 return true;
4455 }
4456
4457 @Override
4458 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4459 boolean isProvisioned) {
4460 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4465 if (!isImsProvisioningRequired(subId, capability, false)) {
4466 return;
4467 }
4468
4469 // this capability requires provisioning, route to the correct API.
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 ims.setEabProvisioned(isProvisioned);
4475 break;
4476 default: {
4477 throw new IllegalArgumentException("Tried to set provisioning for "
4478 + "rcs capability '" + capability + "', which does not require "
4479 + "provisioning.");
4480 }
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485
4486 }
4487
4488
4489 @Override
4490 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4491 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4495 if (!isImsProvisioningRequired(subId, capability, false)) {
4496 return true;
4497 }
4498
4499 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4500 switch (capability) {
4501 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4502 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4503 return ims.isEabProvisionedOnDevice();
4504
4505 default: {
4506 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4507 + "capability '" + capability + "', which does not require "
4508 + "provisioning.");
4509 }
4510 }
4511
4512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 }
4516
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004517 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4519 boolean isProvisioned) {
4520 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004521 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4522 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4523 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004524 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4525 }
allenwtsu99c623b2020-01-03 18:24:23 +08004526 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004530 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 return;
4532 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004533 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4534 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4535 loge("setImsProvisioningStatusForCapability: called for technology that does "
4536 + "not support provisioning - " + tech);
4537 return;
4538 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004539
4540 // this capability requires provisioning, route to the correct API.
4541 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4542 switch (capability) {
4543 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4544 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4545 ims.setVolteProvisioned(isProvisioned);
4546 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4547 ims.setWfcProvisioned(isProvisioned);
4548 }
4549 break;
4550 }
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4552 // There is currently no difference in VT provisioning type.
4553 ims.setVtProvisioned(isProvisioned);
4554 break;
4555 }
4556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4557 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4558 // change the capability of the feature instead if needed.
4559 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4560 == isProvisioned) {
4561 // No change in provisioning.
4562 return;
4563 }
4564 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4565 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004566 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004567 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4569 + ", Exception" + e.getMessage());
4570 }
4571 break;
4572 }
4573 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004574 throw new IllegalArgumentException("Tried to set provisioning for "
4575 + "MmTel capability '" + capability + "', which does not require "
4576 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 }
4578 }
4579
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583 }
4584
4585 @Override
4586 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4587 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004588 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4589 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4590 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4592 }
4593 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004597 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 return true;
4599 }
4600
Brad Ebinger0d79c572021-04-17 15:20:49 -07004601 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4602 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4603 loge("getImsProvisioningStatusForCapability: called for technology that does "
4604 + "not support provisioning - " + tech);
4605 return true;
4606 }
4607
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4609 switch (capability) {
4610 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4611 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4612 return ims.isVolteProvisionedOnDevice();
4613 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4614 return ims.isWfcProvisionedOnDevice();
4615 }
4616 // This should never happen, since we are checking tech above to make sure it
4617 // is either LTE or IWLAN.
4618 throw new IllegalArgumentException("Invalid radio technology for voice "
4619 + "capability.");
4620 }
4621 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4622 // There is currently no difference in VT provisioning type.
4623 return ims.isVtProvisionedOnDevice();
4624 }
4625 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4626 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4627 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4628 }
4629 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004630 throw new IllegalArgumentException(
4631 "Tried to get provisioning for MmTel capability '" + capability
4632 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 }
4634 }
4635
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
4641 @Override
4642 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4643 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4645 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4646 }
4647 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4648 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4649 return (provisionedBits & capability) > 0;
4650 }
4651
4652 @Override
4653 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4654 boolean isProvisioned) {
4655 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4656 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4657 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4658 }
4659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4660 "setProvisioningStatusForCapability");
4661 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4662 // If the current provisioning status for capability already matches isProvisioned,
4663 // do nothing.
4664 if (((provisionedBits & capability) > 0) == isProvisioned) {
4665 return;
4666 }
4667 if (isProvisioned) {
4668 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4669 } else {
4670 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4671 }
4672 }
4673
4674 /**
4675 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4676 * technology. The bitfield should mirror the bitfield defined by
4677 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4678 */
4679 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4680 String key = getMmTelProvisioningKey(subId, tech);
4681 // Default is no capabilities are provisioned.
4682 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4683 }
4684
4685 /**
4686 * Sets the MmTel capability provisioning bitfield (defined by
4687 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4688 * technology specified.
4689 *
4690 * Note: This is a synchronous command and should not be called on UI thread.
4691 */
4692 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4693 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4694 String key = getMmTelProvisioningKey(subId, tech);
4695 editor.putInt(key, newField);
4696 editor.commit();
4697 }
4698
4699 private static String getMmTelProvisioningKey(int subId, int tech) {
4700 // resulting key is provision_ims_mmtel_{subId}_{tech}
4701 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4702 }
4703
4704 /**
4705 * Query CarrierConfig to see if the specified capability requires provisioning for the
4706 * carrier associated with the subscription id.
4707 */
4708 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4709 int capability) {
4710 CarrierConfigManager configManager = new CarrierConfigManager(context);
4711 PersistableBundle c = configManager.getConfigForSubId(subId);
4712 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004713 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4715 false);
4716 boolean requireVoiceVtProvisioning = c.getBoolean(
4717 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4718
4719 // First check to make sure that the capability requires provisioning.
4720 switch (capability) {
4721 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4722 // intentional fallthrough
4723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4724 if (requireVoiceVtProvisioning) {
4725 // Voice and Video requires provisioning
4726 return true;
4727 }
4728 break;
4729 }
4730 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4731 if (requireUtProvisioning) {
4732 // UT requires provisioning
4733 return true;
4734 }
4735 break;
4736 }
4737 }
4738 return false;
4739 }
4740
allenwtsu99c623b2020-01-03 18:24:23 +08004741 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4742 int capability) {
4743 CarrierConfigManager configManager = new CarrierConfigManager(context);
4744 PersistableBundle c = configManager.getConfigForSubId(subId);
4745
4746 boolean requireRcsProvisioning = c.getBoolean(
4747 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4748
4749 // First check to make sure that the capability requires provisioning.
4750 switch (capability) {
4751 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4752 // intentional fallthrough
4753 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4754 if (requireRcsProvisioning) {
4755 // OPTION or PRESENCE requires provisioning
4756 return true;
4757 }
4758 break;
4759 }
4760 }
4761 return false;
4762 }
4763
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4767 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4768 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004769 enforceReadPrivilegedPermission("getImsProvisioningInt");
4770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 int slotId = getSlotIndex(subId);
4774 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4775 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4776 + subId + "' for key:" + key);
4777 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4778 }
calvinpanb5a34062021-02-08 19:59:36 +08004779 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004780 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4782 + subId + "' for key:" + key);
4783 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
4787 }
4788
4789 @Override
4790 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4792 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4793 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 enforceReadPrivilegedPermission("getImsProvisioningString");
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 int slotId = getSlotIndex(subId);
4799 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4800 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4801 + subId + "' for key:" + key);
4802 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4803 }
calvinpanb5a34062021-02-08 19:59:36 +08004804 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004805 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004806 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4807 + subId + "' for key:" + key);
4808 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
4812 }
4813
4814 @Override
4815 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4817 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4818 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4820 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004824 int slotId = getSlotIndex(subId);
4825 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4826 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4827 + subId + "' for key:" + key);
4828 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4829 }
calvinpanb5a34062021-02-08 19:59:36 +08004830 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4831 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004833 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004834 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
4838 }
4839
4840 @Override
4841 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4843 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4844 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4846 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 int slotId = getSlotIndex(subId);
4851 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4852 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4853 + subId + "' for key:" + key);
4854 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4855 }
calvinpanb5a34062021-02-08 19:59:36 +08004856 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4857 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004858 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004859 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004860 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
4864 }
4865
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004866 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004867 int slotId = SubscriptionManager.getSlotIndex(subId);
4868 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004869 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4870 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004871 }
4872 return slotId;
4873 }
4874
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004875 private int getSlotIndex(int subId) {
4876 int slotId = SubscriptionManager.getSlotIndex(subId);
4877 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4878 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4879 }
4880 return slotId;
4881 }
4882
Wink Saville36469e72014-06-11 15:17:00 -07004883 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004884 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004885 */
4886 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4888 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004889 try {
4890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4891 } catch (SecurityException se) {
4892 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4893 throw new SecurityException("Package " + callingPackage + " does not belong to "
4894 + Binder.getCallingUid());
4895 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004896 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004897 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004898 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004899 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004900 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004901 mApp, subId, callingPackage, callingFeatureId,
4902 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004903 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4904 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 final Phone phone = getPhone(subId);
4909 if (phone != null) {
4910 return phone.getServiceState().getDataNetworkType();
4911 } else {
4912 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4913 }
4914 } finally {
4915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004917 }
4918
4919 /**
4920 * Returns the data network type
4921 */
4922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004924 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4925 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004926 }
4927
4928 /**
4929 * Returns the data network type for a subId
4930 */
4931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004932 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4933 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004935 mApp, subId, callingPackage, callingFeatureId,
4936 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004937 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4938 }
4939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 final Phone phone = getPhone(subId);
4943 if (phone != null) {
4944 return phone.getServiceState().getDataNetworkType();
4945 } else {
4946 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4947 }
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004951 }
4952
4953 /**
Wink Saville36469e72014-06-11 15:17:00 -07004954 * Returns the Voice network type for a subId
4955 */
4956 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004957 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4958 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004960 mApp, subId, callingPackage, callingFeatureId,
4961 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004962 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4963 }
4964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 final Phone phone = getPhone(subId);
4968 if (phone != null) {
4969 return phone.getServiceState().getVoiceNetworkType();
4970 } else {
4971 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4972 }
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004975 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004976 }
4977
4978 /**
4979 * @return true if a ICC card is present
4980 */
4981 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004982 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004983 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4984 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004985 }
4986
4987 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004988 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004989 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004990 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004991 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 final Phone phone = PhoneFactory.getPhone(slotIndex);
4995 if (phone != null) {
4996 return phone.getIccCard().hasIccCard();
4997 } else {
4998 return false;
4999 }
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005003 }
5004
5005 /**
5006 * Return if the current radio is LTE on CDMA. This
5007 * is a tri-state return value as for a period of time
5008 * the mode may be unknown.
5009 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005010 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005011 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005012 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005013 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005015 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5016 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5017 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005018 }
5019
Sanket Padawe356d7632015-06-22 14:03:32 -07005020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5022 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005023 try {
5024 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5025 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005026 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5027 }
5028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 final Phone phone = getPhone(subId);
5032 if (phone == null) {
5033 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5034 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005035 return TelephonyProperties.lte_on_cdma_device()
5036 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005040 }
Wink Saville36469e72014-06-11 15:17:00 -07005041 }
5042
Wink Saville36469e72014-06-11 15:17:00 -07005043 /**
5044 * {@hide}
5045 * Returns Default subId, 0 in the case of single standby.
5046 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005047 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005048 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005049 }
5050
Shishir Agrawala9f32182016-04-12 12:00:16 -07005051 private int getSlotForDefaultSubscription() {
5052 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5053 }
5054
Wink Savilleb564aae2014-10-23 10:18:09 -07005055 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005056 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005057 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005058
Pengquan Menge92a50d2018-09-21 15:54:48 -07005059 private boolean isActiveSubscription(int subId) {
5060 return mSubscriptionController.isActiveSubId(subId);
5061 }
5062
Ihab Awadf2177b72013-11-25 13:33:23 -08005063 /**
5064 * @see android.telephony.TelephonyManager.WifiCallingChoices
5065 */
5066 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005069 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5071 getWhenToMakeWifiCallsDefaultPreference());
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005075 }
5076
5077 /**
5078 * @see android.telephony.TelephonyManager.WifiCallingChoices
5079 */
5080 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005084 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005089 }
5090
Sailesh Nepald1e68152013-12-12 19:08:02 -08005091 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005092 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005093 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005094 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005095
Jordan Liu4c733742019-02-28 12:03:40 -08005096 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5097 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5098 if (phoneId == -1) {
5099 throw new IllegalArgumentException("Given slot index: " + slotIndex
5100 + " does not correspond to an active phone");
5101 }
5102 return PhoneFactory.getPhone(phoneId);
5103 }
5104
Shishir Agrawal566b7612013-10-28 14:41:00 -07005105 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005106 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5107 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5109 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005111 if (DBG) {
5112 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5113 }
5114 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5115 p2);
5116 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005117
Jordan Liu4c733742019-02-28 12:03:40 -08005118
5119 @Override
5120 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5121 int slotIndex, String callingPackage, String aid, int p2) {
5122 enforceModifyPermission();
5123 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5124 if (DBG) {
5125 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5126 }
5127 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5128 callingPackage, aid, p2);
5129 }
5130
5131 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5132 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (TextUtils.equals(ISDR_AID, aid)) {
5136 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005137 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5138 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 if (bestComponent == null
5140 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5141 loge("The calling package is not allowed to access ISD-R.");
5142 throw new SecurityException(
5143 "The calling package is not allowed to access ISD-R.");
5144 }
Derek Tan740e1672017-06-27 14:56:27 -07005145 }
Derek Tan740e1672017-06-27 14:56:27 -07005146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005148 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5149 null /* workSource */);
5150 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 return response;
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005155 }
5156
5157 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005158 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5160 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005161 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5162 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5163 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005164
Jordan Liu4c733742019-02-28 12:03:40 -08005165 @Override
5166 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5167 enforceModifyPermission();
5168 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5169 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5170 channel);
5171 }
5172
5173 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 final long identity = Binder.clearCallingIdentity();
5175 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 if (channel < 0) {
5177 return false;
5178 }
Jordan Liu4c733742019-02-28 12:03:40 -08005179 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5180 null /* workSource */);
5181 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 return success;
5183 } finally {
5184 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005185 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005186 }
5187
5188 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005189 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005190 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005193 if (DBG) {
5194 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5195 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5196 + p3 + " data=" + data);
5197 }
5198 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5199 command, p1, p2, p3, data);
5200 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005201
Jordan Liu4c733742019-02-28 12:03:40 -08005202 @Override
5203 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5204 int command, int p1, int p2, int p3, String data) {
5205 enforceModifyPermission();
5206 if (DBG) {
5207 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5208 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5209 + p3 + " data=" + data);
5210 }
5211 return iccTransmitApduLogicalChannelWithPermission(
5212 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5213 data);
5214 }
5215
5216 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5217 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005220 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 return "";
5222 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005225 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5226 null /* workSource */);
5227 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 // Append the returned status code to the end of the response payload.
5230 String s = Integer.toHexString(
5231 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5232 if (response.payload != null) {
5233 s = IccUtils.bytesToHexString(response.payload) + s;
5234 }
5235 return s;
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005238 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005239 }
Jake Hambye994d462014-02-03 13:10:13 -08005240
Evan Charltonc66da362014-05-16 14:06:40 -07005241 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005242 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5243 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5245 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005247 if (DBG) {
5248 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5249 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5250 }
5251 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5252 cla, command, p1, p2, p3, data);
5253 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005254
Jordan Liu4c733742019-02-28 12:03:40 -08005255 @Override
5256 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5257 int command, int p1, int p2, int p3, String data) {
5258 enforceModifyPermission();
5259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5260 if (DBG) {
5261 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5262 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5263 + " data=" + data);
5264 }
5265
5266 return iccTransmitApduBasicChannelWithPermission(
5267 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5268 p2, p3, data);
5269 }
5270
5271 // open APDU basic channel assuming the caller has sufficient permissions
5272 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5273 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5277 && TextUtils.equals(ISDR_AID, data)) {
5278 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005279 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5280 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 if (bestComponent == null
5282 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5283 loge("The calling package is not allowed to select ISD-R.");
5284 throw new SecurityException(
5285 "The calling package is not allowed to select ISD-R.");
5286 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005287 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005290 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5291 null /* workSource */);
5292 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 // Append the returned status code to the end of the response payload.
5295 String s = Integer.toHexString(
5296 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5297 if (response.payload != null) {
5298 s = IccUtils.bytesToHexString(response.payload) + s;
5299 }
5300 return s;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005303 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005304 }
5305
5306 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005307 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005308 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 final long identity = Binder.clearCallingIdentity();
5313 try {
5314 if (DBG) {
5315 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5316 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5317 }
5318
5319 IccIoResult response =
5320 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5321 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5322 subId);
5323
5324 if (DBG) {
5325 log("Exchange SIM_IO [R]" + response);
5326 }
5327
5328 byte[] result = null;
5329 int length = 2;
5330 if (response.payload != null) {
5331 length = 2 + response.payload.length;
5332 result = new byte[length];
5333 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5334 } else {
5335 result = new byte[length];
5336 }
5337
5338 result[length - 1] = (byte) response.sw2;
5339 result[length - 2] = (byte) response.sw1;
5340 return result;
5341 } finally {
5342 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005343 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005344 }
5345
Nathan Haroldb3014052017-01-25 15:57:32 -08005346 /**
5347 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5348 * on a particular subscription
5349 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005350 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5351 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005353 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005354 return null;
5355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356
5357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 if (appType != TelephonyManager.APPTYPE_USIM
5360 && appType != TelephonyManager.APPTYPE_SIM) {
5361 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5362 return null;
5363 }
5364 Object response = sendRequest(
5365 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5366 if (response instanceof String[]) {
5367 return (String[]) response;
5368 }
yincheng zhao2737e882019-09-06 17:06:54 -07005369 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005371 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005374 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005375 }
5376
yincheng zhao2737e882019-09-06 17:06:54 -07005377 /**
5378 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5379 * subscription.
5380 *
5381 * @param subId the id of the subscription.
5382 * @param appType the uicc app type, must be USIM or SIM.
5383 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5384 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005385 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005386 * @return number of fplmns that is successfully written to the SIM.
5387 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005388 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5389 String callingFeatureId) {
5390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5391 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005392 if (DBG) logv("no permissions for setForbiddenplmns");
5393 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5394 }
5395 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5396 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5397 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5398 }
5399 if (fplmns == null) {
5400 throw new IllegalArgumentException("Fplmn List provided is null");
5401 }
5402 for (String fplmn : fplmns) {
5403 if (!CellIdentity.isValidPlmn(fplmn)) {
5404 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5405 }
5406 }
5407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 Object response = sendRequest(
5410 CMD_SET_FORBIDDEN_PLMNS,
5411 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5412 subId);
5413 return (int) response;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
5417 }
5418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005419 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005420 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5422 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5427 if (response.payload == null) {
5428 return "";
5429 }
Evan Charltonc66da362014-05-16 14:06:40 -07005430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 // Append the returned status code to the end of the response payload.
5432 String s = Integer.toHexString(
5433 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5434 s = IccUtils.bytesToHexString(response.payload) + s;
5435 return s;
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
Evan Charltonc66da362014-05-16 14:06:40 -07005439 }
5440
Jake Hambye994d462014-02-03 13:10:13 -08005441 /**
5442 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5443 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5444 *
5445 * @param itemID the ID of the item to read
5446 * @return the NV item as a String, or null on error.
5447 */
5448 @Override
5449 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005450 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5452 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453
5454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005457 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5459 return value;
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Jake Hambye994d462014-02-03 13:10:13 -08005463 }
5464
5465 /**
5466 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5467 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5468 *
5469 * @param itemID the ID of the item to read
5470 * @param itemValue the value to write, as a String
5471 * @return true on success; false on any failure
5472 */
5473 @Override
5474 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005475 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5477 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478
5479 final long identity = Binder.clearCallingIdentity();
5480 try {
5481 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5482 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005483 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5485 return success;
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Jake Hambye994d462014-02-03 13:10:13 -08005489 }
5490
5491 /**
5492 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5493 * Used for device configuration by some CDMA operators.
5494 *
5495 * @param preferredRoamingList byte array containing the new PRL
5496 * @return true on success; false on any failure
5497 */
5498 @Override
5499 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5501 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5506 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5507 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5508 return success;
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
Jake Hambye994d462014-02-03 13:10:13 -08005512 }
5513
5514 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005515 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005516 * Used for device configuration by some CDMA operators.
5517 *
chen xu6dac5ab2018-10-26 17:39:23 -07005518 * @param slotIndex - device slot.
5519 *
Jake Hambye994d462014-02-03 13:10:13 -08005520 * @return true on success; false on any failure
5521 */
5522 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005523 public boolean resetModemConfig(int slotIndex) {
5524 Phone phone = PhoneFactory.getPhone(slotIndex);
5525 if (phone != null) {
5526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528
chen xu6dac5ab2018-10-26 17:39:23 -07005529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5532 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5533 return success;
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 }
chen xu6dac5ab2018-10-26 17:39:23 -07005538 return false;
5539 }
5540
5541 /**
5542 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5543 *
5544 * @param slotIndex - device slot.
5545 *
5546 * @return true on success; false on any failure
5547 */
5548 @Override
5549 public boolean rebootModem(int slotIndex) {
5550 Phone phone = PhoneFactory.getPhone(slotIndex);
5551 if (phone != null) {
5552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, phone.getSubId(), "rebootModem");
5554
5555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5558 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5559 return success;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
5563 }
5564 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005565 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005566
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005567 public String[] getPcscfAddress(String apnType, String callingPackage,
5568 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005569 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5571 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005572 return new String[0];
5573 }
5574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 final long identity = Binder.clearCallingIdentity();
5576 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 } finally {
5579 Binder.restoreCallingIdentity(identity);
5580 }
Wink Saville36469e72014-06-11 15:17:00 -07005581 }
5582
Brad Ebinger51f743a2017-01-23 13:50:20 -08005583 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005584 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5585 * {@link #disableIms(int)}.
5586 * @param slotIndex device slot.
5587 */
5588 public void resetIms(int slotIndex) {
5589 enforceModifyPermission();
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (mImsResolver == null) {
5594 // may happen if the does not support IMS.
5595 return;
5596 }
5597 mImsResolver.disableIms(slotIndex);
5598 mImsResolver.enableIms(slotIndex);
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005605 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5606 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005607 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005608 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005613 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005614 // may happen if the device does not support IMS.
5615 return;
5616 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005617 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 } finally {
5619 Binder.restoreCallingIdentity(identity);
5620 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005621 }
5622
5623 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005624 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5625 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005626 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005627 public void disableIms(int slotId) {
5628 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005632 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005633 // may happen if the device does not support IMS.
5634 return;
5635 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005636 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005640 }
5641
5642 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005643 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5644 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005645 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005646 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005647 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005648 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 Ebinger67b3e042020-09-11 12:45:11 -07005653 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5654 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005655 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005656 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005660 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005661 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005662 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5663 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005664 @Override
5665 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005666 enforceModifyPermission();
5667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005671 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
5675 }
5676
5677 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005678 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005679 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005680 */
5681 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005686 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005687 // may happen if the device does not support IMS.
5688 return null;
5689 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005690 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005694 }
5695
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005696 /**
5697 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005698 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005699 */
5700 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702
5703 final long identity = Binder.clearCallingIdentity();
5704 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005705 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005706 // may happen if the device does not support IMS.
5707 return null;
5708 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005709 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 } finally {
5711 Binder.restoreCallingIdentity(identity);
5712 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 }
5714
Brad Ebinger884c07b2018-02-15 16:17:40 -08005715 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005716 * Sets the ImsService Package Name that Telephony will bind to.
5717 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 * @param slotIndex the slot ID that the ImsService should bind for.
5719 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005720 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005721 * @param featureTypes An integer array of feature types associated with a packageName.
5722 * @param packageName The name of the package that the current configuration will be replaced
5723 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005724 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005725 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005726 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5727 int[] featureTypes, String packageName) {
5728 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5731 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 final long identity = Binder.clearCallingIdentity();
5735 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005736 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005737 // may happen if the device does not support IMS.
5738 return false;
5739 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 Map<Integer, String> featureConfig = new HashMap<>();
5741 for (int featureType : featureTypes) {
5742 featureConfig.put(featureType, packageName);
5743 }
5744 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5745 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005749 }
5750
5751 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005752 * Clears any carrier ImsService overrides for the slot index specified that were previously
5753 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5754 *
5755 * This should only be used for testing.
5756 *
5757 * @param slotIndex the slot ID that the ImsService should bind for.
5758 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5759 */
5760 @Override
5761 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5762 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5764 "clearCarrierImsServiceOverride");
5765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5766 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5767 "clearCarrierImsServiceOverride");
5768
5769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 if (mImsResolver == null) {
5772 // may happen if the device does not support IMS.
5773 return false;
5774 }
5775 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
5781 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005782 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005783 *
5784 * @param slotId The slot that the ImsService is associated with.
5785 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5786 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005787 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005788 * @return the package name of the ImsService configuration.
5789 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005790 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5791 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005792 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005794 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005795 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5796 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 final long identity = Binder.clearCallingIdentity();
5799 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005801 // may happen if the device does not support IMS.
5802 return "";
5803 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005804 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005805 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5806 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005810 }
5811
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005812 /**
5813 * Get the MmTelFeature state associated with the requested subscription id.
5814 * @param subId The subscription that the MmTelFeature is associated with.
5815 * @param callback A callback with an integer containing the
5816 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5817 */
5818 @Override
5819 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5820 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5821 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5822 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5823 "IMS not available on device.");
5824 }
5825 final long token = Binder.clearCallingIdentity();
5826 try {
5827 int slotId = getSlotIndex(subId);
5828 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5829 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5830 + subId + "'");
5831 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5832 }
5833 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5834 try {
5835 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5836 } catch (RemoteException e) {
5837 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5838 + "Ignore");
5839 }
5840 });
5841 } finally {
5842 Binder.restoreCallingIdentity(token);
5843 }
5844 }
5845
Daniel Brightbb5840b2021-01-12 15:48:18 -08005846 /**
5847 * Sets the ims registration state on all valid {@link Phone}s.
5848 */
5849 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
5852 final long identity = Binder.clearCallingIdentity();
5853 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005854 // NOTE: Before S, this method only set the default phone.
5855 for (final Phone phone : PhoneFactory.getPhones()) {
5856 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5857 phone.setImsRegistrationState(registered);
5858 }
5859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Wink Saville36469e72014-06-11 15:17:00 -07005863 }
5864
5865 /**
Stuart Scott54788802015-03-30 13:18:01 -07005866 * Set the network selection mode to automatic.
5867 *
5868 */
5869 @Override
5870 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5872 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
shilufc958392020-01-20 11:36:01 -08005876 if (!isActiveSubscription(subId)) {
5877 return;
5878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005880 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5881 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Stuart Scott54788802015-03-30 13:18:01 -07005885 }
5886
Jack Yud10cdd42020-09-28 20:28:01 -07005887 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005888 * Ask the radio to connect to the input network and change selection mode to manual.
5889 *
5890 * @param subId the id of the subscription.
5891 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5892 * the operator to attach to.
5893 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5894 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5895 * normal network selection next time.
5896 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005897 */
5898 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005899 public boolean setNetworkSelectionModeManual(
5900 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5902 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005903
5904 if (!isActiveSubscription(subId)) {
5905 return false;
5906 }
5907
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005910 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005912 if (DBG) {
5913 log("setNetworkSelectionModeManual: subId: " + subId
5914 + " operator: " + operatorInfo);
5915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005920 }
shilu84f6e8b2019-12-19 13:58:01 -08005921 /**
5922 * Get the manual network selection
5923 *
5924 * @param subId the id of the subscription.
5925 *
5926 * @return the previously saved user selected PLMN
5927 */
5928 @Override
5929 public String getManualNetworkSelectionPlmn(int subId) {
5930 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005931 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005932 mApp, subId, "getManualNetworkSelectionPlmn");
5933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
5936 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005937 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005938 }
5939
5940 final Phone phone = getPhone(subId);
5941 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005942 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005943 }
5944 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5945 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5946 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
5950 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005951
5952 /**
5953 * Scans for available networks.
5954 */
5955 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005956 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5957 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5959 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005960 LocationAccessPolicy.LocationPermissionResult locationResult =
5961 LocationAccessPolicy.checkLocationPermission(mApp,
5962 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5963 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005964 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005965 .setCallingPid(Binder.getCallingPid())
5966 .setCallingUid(Binder.getCallingUid())
5967 .setMethod("getCellNetworkScanResults")
5968 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005969 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5970 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005971 .build());
5972 switch (locationResult) {
5973 case DENIED_HARD:
5974 throw new SecurityException("Not allowed to access scan results -- location");
5975 case DENIED_SOFT:
5976 return null;
5977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978
Pengquan Menga1bb6272018-09-06 09:59:22 -07005979 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 try {
5981 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005982 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 } finally {
5985 Binder.restoreCallingIdentity(identity);
5986 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005987 }
5988
5989 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005990 * Get the call forwarding info, given the call forwarding reason.
5991 */
5992 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005993 public void getCallForwarding(int subId, int callForwardingReason,
5994 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005995 enforceReadPrivilegedPermission("getCallForwarding");
5996 long identity = Binder.clearCallingIdentity();
5997 try {
5998 if (DBG) {
5999 log("getCallForwarding: subId " + subId
6000 + " callForwardingReason" + callForwardingReason);
6001 }
Hall Liu27d24262020-09-18 19:04:59 -07006002
6003 Phone phone = getPhone(subId);
6004 if (phone == null) {
6005 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006006 callback.onError(
6007 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006008 } catch (RemoteException e) {
6009 // ignore
6010 }
6011 return;
6012 }
6013
6014 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6015 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6016 @Override
6017 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6018 try {
6019 callback.onCallForwardingInfoAvailable(info);
6020 } catch (RemoteException e) {
6021 // ignore
6022 }
6023 }
6024
6025 @Override
6026 public void onError(int error) {
6027 try {
6028 callback.onError(error);
6029 } catch (RemoteException e) {
6030 // ignore
6031 }
6032 }
6033 });
6034 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
6038 }
6039
6040 /**
6041 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6042 * reason, the number to forward, and the timeout before the forwarding is attempted.
6043 */
6044 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006045 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6046 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006047 enforceModifyPermission();
6048 long identity = Binder.clearCallingIdentity();
6049 try {
6050 if (DBG) {
6051 log("setCallForwarding: subId " + subId
6052 + " callForwardingInfo" + callForwardingInfo);
6053 }
Hall Liu27d24262020-09-18 19:04:59 -07006054
6055 Phone phone = getPhone(subId);
6056 if (phone == null) {
6057 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006058 callback.accept(
6059 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006060 } catch (RemoteException e) {
6061 // ignore
6062 }
6063 return;
6064 }
6065
6066 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6067 FunctionalUtils.ignoreRemoteException(callback::accept));
6068
6069 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
6073 }
6074
6075 /**
Hall Liu27d24262020-09-18 19:04:59 -07006076 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006077 */
6078 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006079 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006080 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006081 long identity = Binder.clearCallingIdentity();
6082 try {
Hall Liu27d24262020-09-18 19:04:59 -07006083 Phone phone = getPhone(subId);
6084 if (phone == null) {
6085 try {
6086 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6087 } catch (RemoteException e) {
6088 // ignore
6089 }
6090 return;
6091 }
SongFerngWang0e767992021-03-31 22:08:45 +08006092 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6093 PersistableBundle c = configManager.getConfigForSubId(subId);
6094 boolean requireUssd = c.getBoolean(
6095 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006096
Shuo Qian4a594052020-01-23 11:59:30 -08006097 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006098 if (requireUssd) {
6099 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6100 getSubscriptionCarrierId(subId));
6101 String newUssdCommand = "";
6102 try {
6103 newUssdCommand = carrierXmlParser.getFeature(
6104 CarrierXmlParser.FEATURE_CALL_WAITING)
6105 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6106 } catch (NullPointerException e) {
6107 loge("Failed to generate USSD number" + e);
6108 }
6109 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6110 mMainThreadHandler, callback, carrierXmlParser,
6111 CarrierXmlParser.SsEntry.SSAction.QUERY);
6112 final String ussdCommand = newUssdCommand;
6113 Executors.newSingleThreadExecutor().execute(() -> {
6114 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6115 });
6116 } else {
6117 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6118 callback::accept);
6119 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6120 }
Shuo Qian4a594052020-01-23 11:59:30 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
6124 }
6125
6126 /**
Hall Liu27d24262020-09-18 19:04:59 -07006127 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006128 */
6129 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006130 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006131 enforceModifyPermission();
6132 long identity = Binder.clearCallingIdentity();
6133 try {
Hall Liu27d24262020-09-18 19:04:59 -07006134 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6135
6136 Phone phone = getPhone(subId);
6137 if (phone == null) {
6138 try {
6139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6140 } catch (RemoteException e) {
6141 // ignore
6142 }
6143 return;
6144 }
6145
SongFerngWang0e767992021-03-31 22:08:45 +08006146 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6147 PersistableBundle c = configManager.getConfigForSubId(subId);
6148 boolean requireUssd = c.getBoolean(
6149 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006150
SongFerngWang0e767992021-03-31 22:08:45 +08006151 if (DBG) log("getCallWaitingStatus: subId " + subId);
6152 if (requireUssd) {
6153 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6154 getSubscriptionCarrierId(subId));
6155 CarrierXmlParser.SsEntry.SSAction ssAction =
6156 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6157 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6158 String newUssdCommand = "";
6159 try {
6160 newUssdCommand = carrierXmlParser.getFeature(
6161 CarrierXmlParser.FEATURE_CALL_WAITING)
6162 .makeCommand(ssAction, null);
6163 } catch (NullPointerException e) {
6164 loge("Failed to generate USSD number" + e);
6165 }
6166 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6167 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6168 final String ussdCommand = newUssdCommand;
6169 Executors.newSingleThreadExecutor().execute(() -> {
6170 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6171 });
6172 } else {
6173 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6174 FunctionalUtils.ignoreRemoteException(callback::accept));
6175
6176 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6177 }
Shuo Qian4a594052020-01-23 11:59:30 -08006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
6181 }
6182
6183 /**
yinxub1bed742017-04-17 11:45:04 -07006184 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006185 *
yinxub1bed742017-04-17 11:45:04 -07006186 * @param subId id of the subscription
6187 * @param request contains the radio access networks with bands/channels to scan
6188 * @param messenger callback messenger for scan results or errors
6189 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006190 * @return the id of the requested scan which can be used to stop the scan.
6191 */
6192 @Override
6193 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006194 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6196 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006197 LocationAccessPolicy.LocationPermissionResult locationResult =
6198 LocationAccessPolicy.checkLocationPermission(mApp,
6199 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6200 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006201 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006202 .setCallingPid(Binder.getCallingPid())
6203 .setCallingUid(Binder.getCallingUid())
6204 .setMethod("requestNetworkScan")
6205 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006206 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6207 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006208 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006209 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006210 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6211 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006212 if (e != null) {
6213 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6214 throw e;
6215 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006216 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006217 return TelephonyScanManager.INVALID_SCAN_ID;
6218 }
6219 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 }
Hall Liu912dfd32019-04-25 14:02:26 -07006221 int callingUid = Binder.getCallingUid();
6222 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 return mNetworkScanRequestTracker.startNetworkScan(
6226 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006227 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
yinxu504e1392017-04-12 16:03:22 -07006231 }
6232
Hall Liub2ac8ef2019-02-28 15:56:23 -08006233 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006234 NetworkScanRequest request, int subId, String callingPackage) {
6235 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006236 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6237 boolean hasNetworkScanPermission =
6238 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6239 == PERMISSION_GRANTED;
6240
6241 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6242 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6243 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006244 }
6245
6246 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6247 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006248 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6249 return new SecurityException("Specific channels must not be"
6250 + " scanned without location access.");
6251 }
6252 }
6253 }
6254
Hall Liub2ac8ef2019-02-28 15:56:23 -08006255 return null;
6256 }
6257
yinxu504e1392017-04-12 16:03:22 -07006258 /**
6259 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006260 *
6261 * @param subId id of the subscription
6262 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006263 */
6264 @Override
6265 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6267 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268
Hall Liu912dfd32019-04-25 14:02:26 -07006269 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
6271 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006272 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
yinxu504e1392017-04-12 16:03:22 -07006276 }
6277
6278 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006279 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006280 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006281 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006282 */
6283 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006284 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006285 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006286 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006287 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006291 if (DBG) log("getAllowedNetworkTypesBitmask");
6292 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6293 int networkTypesBitmask = (result != null ? result[0] : -1);
6294 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6295 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006299 }
6300
6301 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006302 * Get the allowed network types for certain reason.
6303 *
6304 * @param subId the id of the subscription.
6305 * @param reason the reason the allowed network type change is taking place
6306 * @return the allowed network types.
6307 */
6308 @Override
6309 public long getAllowedNetworkTypesForReason(int subId,
6310 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006312 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
6319 }
6320
6321 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006322 * Enable/Disable E-UTRA-NR Dual Connectivity
6323 * @param subId subscription id of the sim card
6324 * @param nrDualConnectivityState expected NR dual connectivity state
6325 * This can be passed following states
6326 * <ol>
6327 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6328 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6329 * <li>Disable NR dual connectivity and force secondary cell to be released
6330 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6331 * </ol>
6332 * @return operation result.
6333 */
6334 @Override
6335 public int setNrDualConnectivityState(int subId,
6336 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6338 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006339 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006340 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6341 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6342 }
6343
Sooraj Sasindran37444802020-08-11 10:40:43 -07006344 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6348 nrDualConnectivityState, subId,
6349 workSource);
6350 if (DBG) log("enableNRDualConnectivity result: " + result);
6351 return result;
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
6355 }
6356
6357 /**
6358 * Is E-UTRA-NR Dual Connectivity enabled
6359 * @return true if dual connectivity is enabled else false
6360 */
6361 @Override
6362 public boolean isNrDualConnectivityEnabled(int subId) {
6363 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006364 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006365 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006366 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006367 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6368 return false;
6369 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6374 null, subId, workSource);
6375 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6376 return isEnabled;
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
6381
6382 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006383 * Set the allowed network types of the device and
6384 * provide the reason triggering the allowed network change.
6385 *
6386 * @param subId the id of the subscription.
6387 * @param reason the reason the allowed network type change is taking place
6388 * @param allowedNetworkTypes the allowed network types.
6389 * @return true on success; false on any failure.
6390 */
6391 @Override
6392 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006393 @TelephonyManager.AllowedNetworkTypesReason int reason,
6394 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6396 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006397 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006398 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6399 return false;
6400 }
6401 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6402 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006403 return false;
6404 }
6405
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006406 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6407 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6408
6409
6410 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6411 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6412 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006414
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006415 final long identity = Binder.clearCallingIdentity();
6416 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 Boolean success = (Boolean) sendRequest(
6418 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6419 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6420
6421 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6422 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
6428 /**
Miaoa84611c2019-03-15 09:21:10 +08006429 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006430 *
Miaoa84611c2019-03-15 09:21:10 +08006431 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006432 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006433 * @hide
6434 */
6435 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006436 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006439 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440 try {
Miaoa84611c2019-03-15 09:21:10 +08006441 if (phone != null) {
6442 return phone.hasMatchedTetherApnSetting();
6443 } else {
6444 return false;
6445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 } finally {
6447 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006448 }
Junda Liu475951f2014-11-07 16:45:03 -08006449 }
6450
6451 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006452 * Enable or disable always reporting signal strength changes from radio.
6453 *
6454 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6455 */
6456 @Override
6457 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6458 enforceModifyPermission();
6459 enforceSystemCaller();
6460
6461 final long identity = Binder.clearCallingIdentity();
6462 final Phone phone = getPhone(subId);
6463 try {
6464 if (phone != null) {
6465 if (DBG) {
6466 log("setAlwaysReportSignalStrength: subId=" + subId
6467 + " isEnable=" + isEnable);
6468 }
6469 phone.setAlwaysReportSignalStrength(isEnable);
6470 } else {
6471 loge("setAlwaysReportSignalStrength: no phone found for subId="
6472 + subId);
6473 }
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
6477 }
6478
6479 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006480 * Get the user enabled state of Mobile Data.
6481 *
6482 * TODO: remove and use isUserDataEnabled.
6483 * This can't be removed now because some vendor codes
6484 * calls through ITelephony directly while they should
6485 * use TelephonyManager.
6486 *
6487 * @return true on enabled
6488 */
6489 @Override
6490 public boolean getDataEnabled(int subId) {
6491 return isUserDataEnabled(subId);
6492 }
6493
6494 /**
6495 * Get whether mobile data is enabled per user setting.
6496 *
6497 * There are other factors deciding whether mobile data is actually enabled, but they are
6498 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006499 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006500 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006501 *
6502 * @return {@code true} if data is enabled else {@code false}
6503 */
6504 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006505 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006506 try {
6507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6508 null);
6509 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6511 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 int phoneId = mSubscriptionController.getPhoneId(subId);
6517 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6518 Phone phone = PhoneFactory.getPhone(phoneId);
6519 if (phone != null) {
6520 boolean retVal = phone.isUserDataEnabled();
6521 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6522 return retVal;
6523 } else {
6524 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6525 return false;
6526 }
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006529 }
6530 }
6531
6532 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006533 * Checks if the device is capable of mobile data by considering whether whether the
6534 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6535 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006536 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006537 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006538 */
6539 @Override
6540 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006541 try {
6542 try {
6543 mApp.enforceCallingOrSelfPermission(
6544 android.Manifest.permission.ACCESS_NETWORK_STATE,
6545 null);
6546 } catch (Exception e) {
6547 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6548 "isDataEnabled");
6549 }
6550 } catch (Exception e) {
6551 enforceReadPrivilegedPermission("isDataEnabled");
6552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 int phoneId = mSubscriptionController.getPhoneId(subId);
6557 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6558 Phone phone = PhoneFactory.getPhone(phoneId);
6559 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006560 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6562 return retVal;
6563 } else {
6564 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6565 return false;
6566 }
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006569 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006570 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006571
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006572 /**
6573 * Check if data is enabled for a specific reason
6574 * @param subId Subscription index
6575 * @param reason the reason the data enable change is taking place
6576 * @return {@code true} if the overall data is enabled; {@code false} if not.
6577 */
6578 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006579 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006580 @TelephonyManager.DataEnabledReason int reason) {
6581 try {
6582 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6583 null);
6584 } catch (Exception e) {
6585 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006586 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006587 }
6588
6589
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 int phoneId = mSubscriptionController.getPhoneId(subId);
6593 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006594 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006595 + " reason=" + reason);
6596 }
6597 Phone phone = PhoneFactory.getPhone(phoneId);
6598 if (phone != null) {
6599 boolean retVal;
6600 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6601 retVal = phone.isUserDataEnabled();
6602 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006603 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006604 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006605 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006606 return retVal;
6607 } else {
6608 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006609 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006610 + subId + " retVal=false");
6611 }
6612 return false;
6613 }
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006619 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006620 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006621 if (uid == Process.PHONE_UID) {
6622 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6623 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006624 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6625 }
6626
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006627 //load access rules from carrier configs, and check those as well: b/139133814
6628 SubscriptionController subController = SubscriptionController.getInstance();
6629 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6630 || subController == null) return privilegeFromSim;
6631
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006632 PackageManager pkgMgr = phone.getContext().getPackageManager();
6633 String[] packages = pkgMgr.getPackagesForUid(uid);
6634
6635 final long identity = Binder.clearCallingIdentity();
6636 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006637 int subId = phone.getSubId();
6638 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6639 // A test override is in place for the privileges for this subId, so don't try to
6640 // read the subscription privileges.
6641 return privilegeFromSim;
6642 }
6643 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006644 SubscriptionManager subManager = (SubscriptionManager)
6645 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6646 for (String pkg : packages) {
6647 if (subManager.canManageSubscription(subInfo, pkg)) {
6648 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6649 }
6650 }
6651 return privilegeFromSim;
6652 } finally {
6653 Binder.restoreCallingIdentity(identity);
6654 }
6655 }
6656
6657 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6658 String pkgName) {
6659 //load access rules from carrier configs, and check those as well: b/139133814
6660 SubscriptionController subController = SubscriptionController.getInstance();
6661 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6662 || subController == null) return privilegeFromSim;
6663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006666 int subId = phone.getSubId();
6667 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6668 // A test override is in place for the privileges for this subId, so don't try to
6669 // read the subscription privileges.
6670 return privilegeFromSim;
6671 }
6672 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006673 SubscriptionManager subManager = (SubscriptionManager)
6674 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6675 return subManager.canManageSubscription(subInfo, pkgName)
6676 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
6680 }
6681
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006682 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006683 public int getCarrierPrivilegeStatus(int subId) {
6684 final Phone phone = getPhone(subId);
6685 if (phone == null) {
6686 loge("getCarrierPrivilegeStatus: Invalid subId");
6687 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6688 }
6689 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006690 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006691 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006692 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6693 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006694
6695 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6696 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006697 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006698 }
Junda Liu29340342014-07-10 15:23:27 -07006699
6700 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006702 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006703 final Phone phone = getPhone(subId);
6704 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006705 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006706 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6707 }
6708 UiccProfile profile =
6709 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6710 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006711 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6713 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006714 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006715 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006716 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 }
6718
6719 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006720 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006721 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006722 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006723 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006724 }
6725
6726 int phoneId = SubscriptionManager.getPhoneId(subId);
6727 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006728 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006729 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6731 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006732 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6733 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6734 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006735 }
6736
6737 @Override
6738 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006739 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006740 if (TextUtils.isEmpty(pkgName))
6741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006742 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6743 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6744 UiccCard card = UiccController.getInstance().getUiccCard(i);
6745 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006746 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006747 continue;
6748 }
6749
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006750 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6751 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6752 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006753 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6754 break;
6755 }
6756 }
6757
6758 return result;
Junda Liu29340342014-07-10 15:23:27 -07006759 }
Derek Tan89e89d42014-07-08 17:00:10 -07006760
6761 @Override
Junda Liue64de782015-04-16 17:19:16 -07006762 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006763 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006764 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6765 loge("phoneId " + phoneId + " is not valid.");
6766 return null;
6767 }
6768 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006769 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006770 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006771 return null ;
6772 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006773 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006774 }
6775
Amith Yamasani6e118872016-02-19 12:53:51 -08006776 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006777 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006778 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006780 List<String> privilegedPackages = new ArrayList<>();
6781 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006782 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6783 // has UICC in that slot.
6784 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 if (card.hasCarrierPrivilegeRules()) {
6786 if (packages == null) {
6787 // Only check packages in user 0 for now
6788 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006789 PackageManager.MATCH_DISABLED_COMPONENTS
6790 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006791 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006792 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006793 }
6794 for (int p = packages.size() - 1; p >= 0; p--) {
6795 PackageInfo pkgInfo = packages.get(p);
6796 if (pkgInfo != null && pkgInfo.packageName != null
6797 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006798 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006799 privilegedPackages.add(pkgInfo.packageName);
6800 }
6801 }
6802 }
6803 }
6804 return privilegedPackages;
6805 }
6806
chen xuf7e9fe82019-05-09 19:31:02 -07006807 @Override
6808 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006809 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6810
6811 final long identity = Binder.clearCallingIdentity();
6812
chen xuf7e9fe82019-05-09 19:31:02 -07006813 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006814 try {
6815 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6816 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6817 }
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006820 }
6821 return privilegedPackages;
6822 }
6823
Wink Savilleb564aae2014-10-23 10:18:09 -07006824 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006825 final Phone phone = getPhone(subId);
6826 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006827 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006828 return null;
6829 }
6830 String iccId = card.getIccId();
6831 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006832 return null;
6833 }
6834 return iccId;
6835 }
6836
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006837 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006838 public void setCallComposerStatus(int subId, int status) {
6839 enforceModifyPermission();
6840
6841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 Phone phone = getPhone(subId);
6844 if (phone != null) {
6845 Phone defaultPhone = phone.getImsPhone();
6846 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6847 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6848 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006849 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6850 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006851 }
6852 }
Shuo Qian284ae752020-12-22 19:10:14 -08006853 } catch (ImsException e) {
6854 throw new ServiceSpecificException(e.getCode());
6855 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006856 Binder.restoreCallingIdentity(identity);
6857 }
6858 }
6859
6860 @Override
6861 public int getCallComposerStatus(int subId) {
6862 enforceReadPrivilegedPermission("getCallComposerStatus");
6863
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
6866 Phone phone = getPhone(subId);
6867 if (phone != null) {
6868 Phone defaultPhone = phone.getImsPhone();
6869 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6870 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6871 return imsPhone.getCallComposerStatus();
6872 }
6873 }
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6878 }
6879
6880 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006881 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6882 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006883 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006884 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 final String iccId = getIccId(subId);
6889 final Phone phone = getPhone(subId);
6890 if (phone == null) {
6891 return false;
6892 }
6893 final String subscriberId = phone.getSubscriberId();
6894
6895 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006896 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 + subscriberId + " to " + number);
6898 }
6899
6900 if (TextUtils.isEmpty(iccId)) {
6901 return false;
6902 }
6903
6904 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6905
6906 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6907 if (alphaTag == null) {
6908 editor.remove(alphaTagPrefKey);
6909 } else {
6910 editor.putString(alphaTagPrefKey, alphaTag);
6911 }
6912
6913 // Record both the line number and IMSI for this ICCID, since we need to
6914 // track all merged IMSIs based on line number
6915 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6916 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6917 if (number == null) {
6918 editor.remove(numberPrefKey);
6919 editor.remove(subscriberPrefKey);
6920 } else {
6921 editor.putString(numberPrefKey, number);
6922 editor.putString(subscriberPrefKey, subscriberId);
6923 }
6924
6925 editor.commit();
6926 return true;
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006929 }
Derek Tan7226c842014-07-02 17:42:23 -07006930 }
6931
6932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006933 public String getLine1NumberForDisplay(int subId, String callingPackage,
6934 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006935 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006936 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006937 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006938 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006939 return null;
6940 }
Derek Tan97ebb422014-09-05 16:55:38 -07006941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 String iccId = getIccId(subId);
6945 if (iccId != null) {
6946 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6947 if (DBG_MERGE) {
6948 log("getLine1NumberForDisplay returning "
6949 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6950 }
6951 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6954 return null;
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006957 }
Derek Tan7226c842014-07-02 17:42:23 -07006958 }
6959
6960 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006961 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6962 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006964 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006965 return null;
6966 }
Derek Tan97ebb422014-09-05 16:55:38 -07006967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 String iccId = getIccId(subId);
6971 if (iccId != null) {
6972 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6973 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6974 }
6975 return null;
6976 } finally {
6977 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006978 }
Derek Tan7226c842014-07-02 17:42:23 -07006979 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006980
6981 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006982 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6983 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006984 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6985 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006987 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006988 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006989 return null;
6990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006991
Jordan Liub49b04b2019-05-06 14:45:15 -07006992 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6993 // the process, where TelephonyManager was instantiated.
6994 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006995 final long identity = Binder.clearCallingIdentity();
6996 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006997 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final TelephonyManager tele = TelephonyManager.from(context);
6999 final SubscriptionManager sub = SubscriptionManager.from(context);
7000
7001 // Figure out what subscribers are currently active
7002 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
Jordan Liub49b04b2019-05-06 14:45:15 -07007004 // Only consider subs which match the current subId
7005 // This logic can be simplified. See b/131189269 for progress.
7006 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007007 activeSubscriberIds.add(tele.getSubscriberId(subId));
7008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009
7010 // First pass, find a number override for an active subscriber
7011 String mergeNumber = null;
7012 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7013 for (String key : prefs.keySet()) {
7014 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7015 final String subscriberId = (String) prefs.get(key);
7016 if (activeSubscriberIds.contains(subscriberId)) {
7017 final String iccId = key.substring(
7018 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7019 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7020 mergeNumber = (String) prefs.get(numberKey);
7021 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007022 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 + " for active subscriber " + subscriberId);
7024 }
7025 if (!TextUtils.isEmpty(mergeNumber)) {
7026 break;
7027 }
7028 }
7029 }
7030 }
7031
7032 // Shortcut when no active merged subscribers
7033 if (TextUtils.isEmpty(mergeNumber)) {
7034 return null;
7035 }
7036
7037 // Second pass, find all subscribers under that line override
7038 final ArraySet<String> result = new ArraySet<>();
7039 for (String key : prefs.keySet()) {
7040 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7041 final String number = (String) prefs.get(key);
7042 if (mergeNumber.equals(number)) {
7043 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7044 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7045 final String subscriberId = (String) prefs.get(subscriberKey);
7046 if (!TextUtils.isEmpty(subscriberId)) {
7047 result.add(subscriberId);
7048 }
7049 }
7050 }
7051 }
7052
7053 final String[] resultArray = result.toArray(new String[result.size()]);
7054 Arrays.sort(resultArray);
7055 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007056 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7058 }
7059 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007062 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007063 }
7064
7065 @Override
zoey chen38003472019-12-13 17:16:31 +08007066 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7067 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 final TelephonyManager telephonyManager = mApp.getSystemService(
7072 TelephonyManager.class);
7073 String subscriberId = telephonyManager.getSubscriberId(subId);
7074 if (subscriberId == null) {
7075 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007076 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007077 + subId);
7078 }
7079 return null;
7080 }
7081
7082 final SubscriptionInfo info = SubscriptionController.getInstance()
7083 .getSubscriptionInfo(subId);
7084 final ParcelUuid groupUuid = info.getGroupUuid();
7085 // If it doesn't belong to any group, return just subscriberId of itself.
7086 if (groupUuid == null) {
7087 return new String[]{subscriberId};
7088 }
7089
7090 // Get all subscriberIds from the group.
7091 final List<String> mergedSubscriberIds = new ArrayList<>();
7092 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007094 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007095 for (SubscriptionInfo subInfo : groupInfos) {
7096 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7097 if (subscriberId != null) {
7098 mergedSubscriberIds.add(subscriberId);
7099 }
7100 }
7101
7102 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105
7106 }
7107 }
7108
7109 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007110 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 final Phone phone = getPhone(subId);
7117 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007121 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007122
7123 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007124 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007125 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7126 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7128 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129
7130 final long identity = Binder.clearCallingIdentity();
7131 try {
7132 final Phone phone = getPhone(subId);
7133 if (phone == null) {
7134 return false;
7135 }
7136 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7137 cdmaNonRoamingList);
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007140 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007141 }
7142
7143 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007144 @Deprecated
7145 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7146 enforceModifyPermission();
7147
7148 int returnValue = 0;
7149 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007150 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007151 if(result.exception == null) {
7152 if (result.result != null) {
7153 byte[] responseData = (byte[])(result.result);
7154 if(responseData.length > oemResp.length) {
7155 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7156 responseData.length + "bytes. Buffer Size is " +
7157 oemResp.length + "bytes.");
7158 }
7159 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7160 returnValue = responseData.length;
7161 }
7162 } else {
7163 CommandException ex = (CommandException) result.exception;
7164 returnValue = ex.getCommandError().ordinal();
7165 if(returnValue > 0) returnValue *= -1;
7166 }
7167 } catch (RuntimeException e) {
7168 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7169 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7170 if(returnValue > 0) returnValue *= -1;
7171 }
7172
7173 return returnValue;
7174 }
7175
7176 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007177 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007178 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007179 try {
7180 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007181 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007182 mApp, phone.getSubId(), "getRadioAccessFamily");
7183 } catch (SecurityException e) {
7184 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7185 throw e;
7186 }
chen xub97461a2018-10-26 14:17:57 -07007187 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007188 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007189 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final long identity = Binder.clearCallingIdentity();
7192 try {
chen xub97461a2018-10-26 14:17:57 -07007193 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007194 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007195 mApp, phone.getSubId(), "getRadioAccessFamily");
7196 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
7199 }
chen xub97461a2018-10-26 14:17:57 -07007200 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007201 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007202
7203 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007204 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007205 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007206 try {
7207 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7208 Binder.getCallingUid())) {
7209 throw new SecurityException("Package uid and package name do not match: "
7210 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7211 }
7212 } catch (PackageManager.NameNotFoundException e) {
7213 throw new SecurityException("Package name invalid:" + callingPackage);
7214 }
7215 RoleManager rm = mApp.getSystemService(RoleManager.class);
7216 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7217 if (!dialerRoleHolders.contains(callingPackage)) {
7218 throw new SecurityException("App must be the dialer role holder to"
7219 + " upload a call composer pic");
7220 }
7221
7222 Executors.newSingleThreadExecutor().execute(() -> {
7223 ByteArrayOutputStream output = new ByteArrayOutputStream(
7224 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7225 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7226 boolean readUntilEnd = false;
7227 int totalBytesRead = 0;
7228 byte[] buffer = new byte[16 * 1024];
7229 while (true) {
7230 int numRead;
7231 try {
7232 numRead = input.read(buffer);
7233 } catch (IOException e) {
7234 try {
7235 fd.checkError();
7236 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7237 null);
7238 } catch (IOException e1) {
7239 // This means that the other side closed explicitly with an error. If this
7240 // happens, log and ignore.
7241 loge("Remote end of call composer picture pipe closed: " + e1);
7242 }
7243 break;
7244 }
7245 if (numRead == -1) {
7246 readUntilEnd = true;
7247 break;
7248 }
7249 totalBytesRead += numRead;
7250 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7251 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7252 try {
7253 input.close();
7254 } catch (IOException e) {
7255 // ignore
7256 }
7257 break;
7258 }
7259 output.write(buffer, 0, numRead);
7260 }
7261 // Generally, the remote end will close the file descriptors. The only case where we
7262 // close is above, where the picture size is too big.
7263
7264 try {
7265 fd.checkError();
7266 } catch (IOException e) {
7267 loge("Remote end for call composer closed with an error: " + e);
7268 return;
7269 }
7270
Hall Liuaa4211e2021-01-20 15:43:39 -08007271 if (!readUntilEnd) {
7272 loge("Did not finish reading entire image; aborting");
7273 return;
7274 }
Hall Liu82694d52020-12-11 18:22:04 -08007275
Hall Liuaa4211e2021-01-20 15:43:39 -08007276 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7277 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7278 new CallComposerPictureTransfer.Factory() {},
7279 imageData,
7280 (result) -> {
7281 if (result.first != null) {
7282 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7283 Bundle outputResult = new Bundle();
7284 outputResult.putParcelable(
7285 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7286 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7287 outputResult);
7288 } else {
7289 callback.send(result.second, null);
7290 }
7291 }
7292 );
Hall Liu82694d52020-12-11 18:22:04 -08007293 });
7294 }
7295
7296 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007297 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300
7301 final long identity = Binder.clearCallingIdentity();
7302 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303 ImsManager.getInstance(defaultPhone.getContext(),
7304 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007308 }
7309
7310 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007311 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7314 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007315 return false;
7316 }
Svet Ganovb320e182015-04-16 12:30:10 -07007317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 // Check the user preference and the system-level IMS setting. Even if the user has
7321 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7322 // In the long run, we may instead need to check if there exists a connection service
7323 // which can support video calling.
7324 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007325 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 return imsManager.isVtEnabledByPlatform()
7327 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7328 && imsManager.isVtEnabledByUser();
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007332 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007333
Andrew Leea1239f22015-03-02 17:44:07 -08007334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007335 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7336 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007338 mApp, subId, callingPackage, callingFeatureId,
7339 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 return false;
7341 }
7342
7343 final long identity = Binder.clearCallingIdentity();
7344 try {
7345 CarrierConfigManager configManager =
7346 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007347 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
Andrew Leea1239f22015-03-02 17:44:07 -08007352 }
7353
7354 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007355 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007357 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return false;
7359 }
7360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 CarrierConfigManager configManager =
7364 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007365 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
Andrew Leea1239f22015-03-02 17:44:07 -08007370 }
7371
Andrew Lee9431b832015-03-09 18:46:45 -07007372 @Override
7373 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007374 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007375 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007376 }
7377
7378 @Override
7379 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 final long identity = Binder.clearCallingIdentity();
7381 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007382 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
Andrew Lee9431b832015-03-09 18:46:45 -07007386 }
7387
Hall Liuf6668912018-10-31 17:05:23 -07007388 /**
7389 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7390 * support for the feature and device firmware support.
7391 *
7392 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7393 */
7394 @Override
7395 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007397 final Phone phone = getPhone(subscriptionId);
7398 if (phone == null) {
7399 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7400 return false;
7401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007403 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7405 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 return isCarrierSupported && isDeviceSupported;
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
7410 }
Hall Liu98187582018-01-22 19:15:32 -08007411 }
7412
Hall Liuf6668912018-10-31 17:05:23 -07007413 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007414 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7415 * RTT setting, will return true if the device and carrier both support RTT.
7416 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007417 */
7418 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007421 boolean isRttSupported = isRttSupported(subscriptionId);
7422 boolean isUserRttSettingOn = Settings.Secure.getInt(
7423 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7424 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7425 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7426 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007430 }
7431
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007432 @Deprecated
7433 @Override
7434 public String getDeviceId(String callingPackage) {
7435 return getDeviceIdWithFeature(callingPackage, null);
7436 }
7437
Sanket Padawe7310cc72015-01-14 09:53:20 -08007438 /**
7439 * Returns the unique device ID of phone, for example, the IMEI for
7440 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7441 *
7442 * <p>Requires Permission:
7443 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7444 */
7445 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007447 try {
7448 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7449 } catch (SecurityException se) {
7450 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7451 throw new SecurityException("Package " + callingPackage + " does not belong to "
7452 + Binder.getCallingUid());
7453 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007454 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007455 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007456 return null;
7457 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007458 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007459 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007461 return null;
7462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463
7464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 return phone.getDeviceId();
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007470 }
7471
Ping Sunc67b7c22016-03-02 19:16:45 +08007472 /**
7473 * {@hide}
7474 * Returns the IMS Registration Status on a particular subid
7475 *
7476 * @param subId
7477 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007478 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007479 Phone phone = getPhone(subId);
7480 if (phone != null) {
7481 return phone.isImsRegistered();
7482 } else {
7483 return false;
7484 }
7485 }
7486
Santos Cordon7a1885b2015-02-03 11:15:19 -08007487 @Override
7488 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007495 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007496
Tyler Gunnf70ed162019-04-03 15:28:53 -07007497 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007498 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007502 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7503 }
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
7510 }
7511
7512 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007513 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007514 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007515 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007516 mApp,
7517 subscriptionId,
7518 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007519 final long identity = Binder.clearCallingIdentity();
7520 try {
7521 Phone phone = getPhone(subscriptionId);
7522 if (phone == null) {
7523 return null;
7524 }
7525 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
7528 }
7529 }
7530
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007531 /**
7532 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007533 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007534 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 Phone phone = getPhone(subId);
7538 if (phone != null) {
7539 return phone.isWifiCallingEnabled();
7540 } else {
7541 return false;
7542 }
7543 } finally {
7544 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007545 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007546 }
7547
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007550 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007551 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = getPhone(subId);
7555 if (phone != null) {
7556 return phone.isVideoEnabled();
7557 } else {
7558 return false;
7559 }
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007562 }
7563 }
7564
7565 /**
7566 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7567 * defined in {@link ImsRegistrationImplBase}.
7568 */
7569 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 Phone phone = getPhone(subId);
7573 if (phone != null) {
7574 return phone.getImsRegistrationTech();
7575 } else {
7576 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7577 }
7578 } finally {
7579 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007580 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007581 }
7582
Stuart Scott8eef64f2015-04-08 15:13:54 -07007583 @Override
7584 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007585 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007586 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7587 return;
7588 }
Kai Shif70f46f2021-03-03 13:59:46 -08007589 Phone defaultPhone = getDefaultPhone();
7590 if (defaultPhone != null) {
7591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7592 mApp, getDefaultPhone().getSubId(), "factoryReset");
7593 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007594 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007595
Svet Ganovcc087f82015-05-12 20:35:54 -07007596 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007597 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7598 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007599 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007600 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007601 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007602 Phone phone = getPhone(subId);
7603 if (phone != null) {
7604 SubscriptionManager.setSubscriptionProperty(subId,
7605 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7606 "user=" + RadioAccessFamily.getRafFromNetworkType(
7607 RILConstants.PREFERRED_NETWORK_MODE));
7608 phone.loadAllowedNetworksFromSubscriptionDatabase();
7609 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007610 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007611 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007612 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007613 // There has been issues when Sms raw table somehow stores orphan
7614 // fragments. They lead to garbled message when new fragments come
7615 // in and combined with those stale ones. In case this happens again,
7616 // user can reset all network settings which will clean up this table.
7617 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007618 // Clean up IMS settings as well here.
7619 int slotId = getSlotIndex(subId);
7620 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7621 ImsManager.getInstance(mApp, slotId).factoryReset();
7622 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007623
Kai Shif70f46f2021-03-03 13:59:46 -08007624 if (defaultPhone == null) {
7625 return;
7626 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007627 // Erase modem config if erase modem on network setting is enabled.
7628 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7629 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7630 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007631 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007632 }
Kai Shif70f46f2021-03-03 13:59:46 -08007633
7634 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007635 } finally {
7636 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007637 }
7638 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007639
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007640 private void cleanUpSmsRawTable(Context context) {
7641 ContentResolver resolver = context.getContentResolver();
7642 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7643 resolver.delete(uri, null, null);
7644 }
7645
Narayan Kamath1c496c22015-04-16 14:40:19 +01007646 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007647 public String getSimLocaleForSubscriber(int subId) {
7648 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7649 final Phone phone = getPhone(subId);
7650 if (phone == null) {
7651 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007652 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 final long identity = Binder.clearCallingIdentity();
7655 try {
chen xu5d3637b2019-01-21 23:31:38 -08007656 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007657 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007658 if (info == null) {
7659 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7660 return null;
7661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 // Try and fetch the locale from the carrier properties or from the SIM language
7663 // preferences (EF-PL and EF-LI)...
7664 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007666 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7667 if (localeFromDefaultSim != null) {
7668 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7669 if (DBG) log("Using locale from subId: " + subId + " locale: "
7670 + localeFromDefaultSim);
7671 return localeFromDefaultSim.toLanguageTag();
7672 } else {
7673 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 }
7675 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 // The SIM language preferences only store a language (e.g. fr = French), not an
7678 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7679 // the SIM and carrier preferences does not include a country we add the country
7680 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007681 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007683 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 return mccLocale.toLanguageTag();
7685 }
7686
7687 if (DBG) log("No locale found - returning null");
7688 return null;
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
7691 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007692 }
7693
7694 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007695 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007696 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007697 }
7698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 /**
7700 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7701 */
7702 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007703 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007704 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007705 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007706
Chenjie Yu1ba97252018-01-11 18:16:20 -08007707 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007708 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007709
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007710 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007711 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7712 * representing the state of the modem.
7713 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007714 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7715 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007716 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007717 */
7718 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007719 public void requestModemActivityInfo(ResultReceiver result) {
7720 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722
7723 final long identity = Binder.clearCallingIdentity();
7724 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007725 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 } finally {
7727 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007728 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007729 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007730
Siddharth Rayb8114062018-06-17 15:02:38 -07007731 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7732 // less than total activity duration.
7733 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7734 if (info == null) {
7735 return false;
7736 }
7737 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007738 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7739 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7740
Siddharth Rayb8114062018-06-17 15:02:38 -07007741 return (info.isValid()
7742 && (info.getSleepTimeMillis() <= activityDurationMs)
7743 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007744 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007745 && (totalTxTimeMs <= activityDurationMs));
7746 }
7747
Jack Yu85bd38a2015-11-09 11:34:32 -08007748 /**
7749 * {@hide}
7750 * Returns the service state information on specified subscription.
7751 */
7752 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007753 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7754 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007756 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007757 return null;
7758 }
7759
Hall Liuf19c44f2018-11-27 14:38:17 -08007760 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7761 LocationAccessPolicy.checkLocationPermission(mApp,
7762 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7763 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007764 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007765 .setCallingPid(Binder.getCallingPid())
7766 .setCallingUid(Binder.getCallingUid())
7767 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007768 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007769 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7771 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007772 .build());
7773
7774 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7775 LocationAccessPolicy.checkLocationPermission(mApp,
7776 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7777 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007778 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007779 .setCallingPid(Binder.getCallingPid())
7780 .setCallingUid(Binder.getCallingUid())
7781 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007782 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007783 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007784 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7785 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007786 .build());
7787 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7788 boolean hasFinePermission =
7789 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7790 boolean hasCoarsePermission =
7791 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7792
Jack Yu479f40e2020-10-27 21:29:25 -07007793 final Phone phone = getPhone(subId);
7794 if (phone == null) {
7795 return null;
7796 }
7797
Jordan Liu0f2bc442020-11-18 16:47:37 -08007798 final long identity = Binder.clearCallingIdentity();
7799
Jack Yu479f40e2020-10-27 21:29:25 -07007800 boolean isCallingPackageDataService = phone.getDataServicePackages()
7801 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007803 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7804 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7805 Rlog.d(LOG_TAG,
7806 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7807 return null;
7808 }
7809
Hall Liuf19c44f2018-11-27 14:38:17 -08007810 ServiceState ss = phone.getServiceState();
7811
7812 // Scrub out the location info in ServiceState depending on what level of access
7813 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007814 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007815 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7816 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007820 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007821
7822 /**
7823 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7824 *
7825 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7826 * voicemail ringtone.
7827 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7828 * PhoneAccount.
7829 */
7830 @Override
7831 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7835 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007836 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7840 } finally {
7841 Binder.restoreCallingIdentity(identity);
7842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007843 }
7844
7845 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007846 * Sets the per-account voicemail ringtone.
7847 *
7848 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7849 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7850 *
7851 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7852 * voicemail ringtone.
7853 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7854 * PhoneAccount.
7855 */
7856 @Override
7857 public void setVoicemailRingtoneUri(String callingPackage,
7858 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007859 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007861 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7862 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7864 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7865 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7871 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007872 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 }
7874 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7875 } finally {
7876 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007877 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007878 }
7879
7880 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007881 * Returns whether vibration is set for voicemail notification in Phone settings.
7882 *
7883 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7884 * voicemail vibration setting.
7885 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7886 */
7887 @Override
7888 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7892 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007893 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007900 }
7901
Youhan Wange64578a2016-05-02 15:32:42 -07007902 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007903 * Sets the per-account voicemail vibration.
7904 *
7905 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7906 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7907 *
7908 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7909 * voicemail vibration setting.
7910 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7911 * specific PhoneAccount.
7912 */
7913 @Override
7914 public void setVoicemailVibrationEnabled(String callingPackage,
7915 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007916 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007918 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7919 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7921 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7922 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007923 }
7924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 final long identity = Binder.clearCallingIdentity();
7926 try {
7927 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7928 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007929 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 }
7931 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007934 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007935 }
7936
7937 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007938 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7939 *
7940 * @throws SecurityException if the caller does not have the required permission
7941 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007942 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007943 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007944 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007945 }
7946
7947 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007948 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7949 * permission.
7950 *
7951 * @throws SecurityException if the caller does not have the required permission
7952 */
7953 private void enforceSendSmsPermission() {
7954 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7955 }
7956
7957 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007958 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007959 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007960 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007961 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007962 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 if (componentName == null) {
7968 throw new SecurityException(
7969 "Caller not current active visual voicemail package[null]");
7970 }
7971 String vvmPackage = componentName.getPackageName();
7972 if (!callingPackage.equals(vvmPackage)) {
7973 throw new SecurityException("Caller not current active visual voicemail package["
7974 + vvmPackage + "]");
7975 }
7976 } finally {
7977 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007978 }
7979 }
7980
7981 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007982 * Return the application ID for the app type.
7983 *
7984 * @param subId the subscription ID that this request applies to.
7985 * @param appType the uicc app type.
7986 * @return Application ID for specificied app type, or null if no uicc.
7987 */
7988 @Override
7989 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007990 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007991 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992
7993 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007994 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 if (phone == null) {
7996 return null;
7997 }
7998 String aid = null;
7999 try {
8000 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8001 .getApplicationByType(appType).getAid();
8002 } catch (Exception e) {
8003 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8004 }
8005 return aid;
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008008 }
Youhan Wange64578a2016-05-02 15:32:42 -07008009 }
8010
Youhan Wang4001d252016-05-11 10:29:41 -07008011 /**
8012 * Return the Electronic Serial Number.
8013 *
8014 * @param subId the subscription ID that this request applies to.
8015 * @return ESN or null if error.
8016 */
8017 @Override
8018 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008019 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008020 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021
8022 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008023 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 if (phone == null) {
8025 return null;
8026 }
8027 String esn = null;
8028 try {
8029 esn = phone.getEsn();
8030 } catch (Exception e) {
8031 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8032 }
8033 return esn;
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008036 }
Youhan Wang4001d252016-05-11 10:29:41 -07008037 }
8038
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008039 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008040 * Return the Preferred Roaming List Version.
8041 *
8042 * @param subId the subscription ID that this request applies to.
8043 * @return PRLVersion or null if error.
8044 */
8045 @Override
8046 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008047 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008048 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049
8050 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008051 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 if (phone == null) {
8053 return null;
8054 }
8055 String cdmaPrlVersion = null;
8056 try {
8057 cdmaPrlVersion = phone.getCdmaPrlVersion();
8058 } catch (Exception e) {
8059 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8060 }
8061 return cdmaPrlVersion;
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008064 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008065 }
8066
8067 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008068 * Get snapshot of Telephony histograms
8069 * @return List of Telephony histograms
8070 * @hide
8071 */
8072 @Override
8073 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8075 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076
8077 final long identity = Binder.clearCallingIdentity();
8078 try {
8079 return RIL.getTelephonyRILTimingHistograms();
8080 } finally {
8081 Binder.restoreCallingIdentity(identity);
8082 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008083 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008084
8085 /**
8086 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008087 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8088 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008089 * Require system privileges. In the future we may add this to carrier APIs.
8090 *
Michele Berionne482f8202018-11-27 18:57:59 -08008091 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008092 */
8093 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008094 @TelephonyManager.SetCarrierRestrictionResult
8095 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008096 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008098
Michele Berionne482f8202018-11-27 18:57:59 -08008099 if (carrierRestrictionRules == null) {
8100 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008101 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103 final long identity = Binder.clearCallingIdentity();
8104 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008105 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008106 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 } finally {
8108 Binder.restoreCallingIdentity(identity);
8109 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008110 }
8111
8112 /**
8113 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008114 * Get the allowed carrier list and the excluded carrier list, including the priority between
8115 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008116 * Require system privileges. In the future we may add this to carrier APIs.
8117 *
Michele Berionne482f8202018-11-27 18:57:59 -08008118 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008119 */
8120 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008121 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008122 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008123 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008127 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8128 if (response instanceof CarrierRestrictionRules) {
8129 return (CarrierRestrictionRules) response;
8130 }
8131 // Response is an Exception of some kind,
8132 // which is signalled to the user as a NULL retval
8133 return null;
8134 } catch (Exception e) {
8135 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8136 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 } finally {
8138 Binder.restoreCallingIdentity(identity);
8139 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008140 }
8141
fionaxu59545b42016-05-25 15:53:37 -07008142 /**
fionaxu59545b42016-05-25 15:53:37 -07008143 * Action set from carrier signalling broadcast receivers to enable/disable radio
8144 * @param subId the subscription ID that this action applies to.
8145 * @param enabled control enable or disable radio.
8146 * {@hide}
8147 */
8148 @Override
8149 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8150 enforceModifyPermission();
8151 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008154 if (phone == null) {
8155 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8156 return;
8157 }
8158 try {
8159 phone.carrierActionSetRadioEnabled(enabled);
8160 } catch (Exception e) {
8161 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 } finally {
8163 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008164 }
8165 }
8166
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008167 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008168 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8169 * network status based on which carrier apps could apply actions accordingly,
8170 * enable/disable default url handler for example.
8171 *
8172 * @param subId the subscription ID that this action applies to.
8173 * @param report control start/stop reporting the default network status.
8174 * {@hide}
8175 */
8176 @Override
8177 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8178 enforceModifyPermission();
8179 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180
8181 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008182 if (phone == null) {
8183 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8184 return;
8185 }
8186 try {
8187 phone.carrierActionReportDefaultNetworkStatus(report);
8188 } catch (Exception e) {
8189 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190 } finally {
8191 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008192 }
8193 }
8194
8195 /**
fionaxud9622282017-07-17 17:51:30 -07008196 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8197 * @param subId the subscription ID that this action applies to.
8198 * {@hide}
8199 */
8200 @Override
8201 public void carrierActionResetAll(int subId) {
8202 enforceModifyPermission();
8203 final Phone phone = getPhone(subId);
8204 if (phone == null) {
8205 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8206 return;
8207 }
8208 try {
8209 phone.carrierActionResetAll();
8210 } catch (Exception e) {
8211 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8212 }
8213 }
8214
8215 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008216 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8217 * bug report is being generated.
8218 */
8219 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008220 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008221 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8222 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008223 writer.println("Permission Denial: can't dump Phone from pid="
8224 + Binder.getCallingPid()
8225 + ", uid=" + Binder.getCallingUid()
8226 + "without permission "
8227 + android.Manifest.permission.DUMP);
8228 return;
8229 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008230 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008231 }
Jack Yueb89b242016-06-22 13:27:47 -07008232
Brad Ebingerdac2f002018-04-03 15:17:52 -07008233 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008234 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8235 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8236 @NonNull String[] args) {
8237 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8238 this, in.getFileDescriptor(), out.getFileDescriptor(),
8239 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008240 }
8241
Jack Yueb89b242016-06-22 13:27:47 -07008242 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008243 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008244 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008245 * @param reason the reason the data enable change is taking place
8246 * @param enabled True if enabling the data, otherwise disabling.
8247 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008248 */
8249 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008250 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008251 boolean enabled) {
8252 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8253 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8254 try {
8255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008256 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008257 } catch (SecurityException se) {
8258 enforceModifyPermission();
8259 }
8260 } else {
8261 enforceModifyPermission();
8262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263
8264 final long identity = Binder.clearCallingIdentity();
8265 try {
8266 Phone phone = getPhone(subId);
8267 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008268 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8269 phone.carrierActionSetMeteredApnsEnabled(enabled);
8270 } else {
8271 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 }
8274 } finally {
8275 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008276 }
8277 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008278
8279 /**
8280 * Get Client request stats
8281 * @return List of Client Request Stats
8282 * @hide
8283 */
8284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008285 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8286 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008288 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008289 return null;
8290 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008291 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 if (phone != null) {
8296 return phone.getClientRequestStats();
8297 }
8298
8299 return null;
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008303 }
8304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008305 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008306 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008307 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008308 }
Jack Yueb4124c2017-02-16 15:32:43 -08008309
8310 /**
Grace Chen70990072017-03-24 17:21:30 -07008311 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008312 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008313 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008314 * @param state State of SIM (power down, power up, pass through)
8315 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8316 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8317 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008318 *
8319 **/
8320 @Override
Grace Chen70990072017-03-24 17:21:30 -07008321 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008322 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008323 Phone phone = PhoneFactory.getPhone(slotIndex);
8324
vagdeviaf9a5b92018-08-15 16:01:53 -07008325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008330 phone.setSimPowerState(state, null, workSource);
8331 }
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
8335 }
8336
8337 /**
8338 * Set SIM card power state.
8339 *
8340 * @param slotIndex SIM slot id.
8341 * @param state State of SIM (power down, power up, pass through)
8342 * @param callback callback to trigger after success or failure
8343 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8344 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8345 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8346 *
8347 **/
8348 @Override
8349 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8350 IIntegerConsumer callback) {
8351 enforceModifyPermission();
8352 Phone phone = PhoneFactory.getPhone(slotIndex);
8353
8354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8355
8356 final long identity = Binder.clearCallingIdentity();
8357 try {
8358 if (phone != null) {
8359 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8360 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 }
8362 } finally {
8363 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008364 }
8365 }
Shuo Qiandd210312017-04-12 22:11:33 +00008366
Tyler Gunn65d45c22017-06-05 11:22:26 -07008367 private boolean isUssdApiAllowed(int subId) {
8368 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008369 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008370 if (configManager == null) {
8371 return false;
8372 }
8373 PersistableBundle pb = configManager.getConfigForSubId(subId);
8374 if (pb == null) {
8375 return false;
8376 }
8377 return pb.getBoolean(
8378 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8379 }
8380
Shuo Qiandd210312017-04-12 22:11:33 +00008381 /**
8382 * Check if phone is in emergency callback mode
8383 * @return true if phone is in emergency callback mode
8384 * @param subId sub id
8385 */
goneil9c5f4872017-12-05 14:07:56 -08008386 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008387 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008388 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008389 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 if (phone != null) {
8394 return phone.isInEcm();
8395 } else {
8396 return false;
8397 }
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008400 }
8401 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008402
8403 /**
8404 * Get the current signal strength information for the given subscription.
8405 * Because this information is not updated when the device is in a low power state
8406 * it should not be relied-upon to be current.
8407 * @param subId Subscription index
8408 * @return the most recent cached signal strength info from the modem
8409 */
8410 @Override
8411 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 Phone p = getPhone(subId);
8415 if (p == null) {
8416 return null;
8417 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008419 return p.getSignalStrength();
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008423 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008424
Pengquan Meng77b7f132018-08-22 14:49:57 -07008425 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008426 * Get the current modem radio state for the given slot.
8427 * @param slotIndex slot index.
8428 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008429 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008430 * @return the current radio power state from the modem
8431 */
8432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008433 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008434 Phone phone = PhoneFactory.getPhone(slotIndex);
8435 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008436 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8437 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008438 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8439 }
8440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 return phone.getRadioPowerState();
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 }
8448 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8449 }
8450
8451 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008452 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8453 *
8454 * <p>Requires one of the following permissions:
8455 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8456 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8457 * privileges.
8458 *
8459 * @param subId subscription id
8460 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8461 * {@code false}.
8462 */
8463 @Override
8464 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008465 try {
8466 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8467 null);
8468 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008469 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008470 mApp, subId, "isDataRoamingEnabled");
8471 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008472
Pengquan Menga1bb6272018-09-06 09:59:22 -07008473 boolean isEnabled = false;
8474 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008475 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008476 Phone phone = getPhone(subId);
8477 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008478 } finally {
8479 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008481 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008482 }
8483
8484
8485 /**
8486 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8487 *
8488 * <p> Requires permission:
8489 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8490 * privileges.
8491 *
8492 * @param subId subscription id
8493 * @param isEnabled {@code true} means enable, {@code false} means disable.
8494 */
8495 @Override
8496 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8498 mApp, subId, "setDataRoamingEnabled");
8499
Pengquan Menga1bb6272018-09-06 09:59:22 -07008500 final long identity = Binder.clearCallingIdentity();
8501 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008502 Phone phone = getPhone(subId);
8503 if (phone != null) {
8504 phone.setDataRoamingEnabled(isEnabled);
8505 }
8506 } finally {
8507 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008508 }
8509 }
8510
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008511 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008512 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008513 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008514 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008515 mApp, subId, "isManualNetworkSelectionAllowed");
8516
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008517 boolean isAllowed = true;
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008520 Phone phone = getPhone(subId);
8521 if (phone != null) {
8522 isAllowed = phone.isCspPlmnEnabled();
8523 }
8524 } finally {
8525 Binder.restoreCallingIdentity(identity);
8526 }
8527 return isAllowed;
8528 }
8529
8530 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008531 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008532 // Verify that tha callingPackage belongs to the calling UID
8533 mApp.getSystemService(AppOpsManager.class)
8534 .checkPackage(Binder.getCallingUid(), callingPackage);
8535
Jordan Liu1e142fc2019-04-22 15:10:43 -07008536 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008537 try {
8538 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008539 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008540 } catch (SecurityException e) {
8541 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8542 // has carrier privileges on an active UICC
8543 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8544 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008545 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008546 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008547 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008551 UiccController uiccController = UiccController.getInstance();
8552 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008553 if (hasReadPermission) {
8554 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008555 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008556
8557 // Remove private info if the caller doesn't have access
8558 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8559 for (UiccCardInfo cardInfo : cardInfos) {
8560 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8561 // is available
8562 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8563 if (card == null || card.getUiccProfile() == null) {
8564 // assume no access if the card or profile is unavailable
8565 filteredInfos.add(cardInfo.getUnprivileged());
8566 continue;
8567 }
8568 UiccProfile profile = card.getUiccProfile();
8569 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8570 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8571 filteredInfos.add(cardInfo);
8572 } else {
8573 filteredInfos.add(cardInfo.getUnprivileged());
8574 }
8575 }
8576 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008577 } finally {
8578 Binder.restoreCallingIdentity(identity);
8579 }
8580 }
8581
8582 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008583 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008584 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008585
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 final long identity = Binder.clearCallingIdentity();
8587 try {
8588 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8589 if (slots == null) {
8590 Rlog.i(LOG_TAG, "slots is null.");
8591 return null;
8592 }
8593
8594 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8595 for (int i = 0; i < slots.length; i++) {
8596 UiccSlot slot = slots[i];
8597 if (slot == null) {
8598 continue;
8599 }
8600
Jordan Liu7be7e652019-05-06 18:55:02 +00008601 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008602 UiccCard card = slot.getUiccCard();
8603 if (card != null) {
8604 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008605 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008606 cardId = slot.getEid();
8607 if (TextUtils.isEmpty(cardId)) {
8608 cardId = slot.getIccId();
8609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 }
8611
Jordan Liu857451f2019-05-09 16:35:35 -07008612 if (cardId != null) {
8613 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8614 // if cardId is an EID, it's all digits so this is fine
8615 cardId = IccUtils.stripTrailingFs(cardId);
8616 }
8617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 int cardState = 0;
8619 switch (slot.getCardState()) {
8620 case CARDSTATE_ABSENT:
8621 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8622 break;
8623 case CARDSTATE_PRESENT:
8624 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8625 break;
8626 case CARDSTATE_ERROR:
8627 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8628 break;
8629 case CARDSTATE_RESTRICTED:
8630 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8631 break;
8632 default:
8633 break;
8634
8635 }
8636
8637 infos[i] = new UiccSlotInfo(
8638 slot.isActive(),
8639 slot.isEuicc(),
8640 cardId,
8641 cardState,
8642 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008643 slot.isExtendedApduSupported(),
8644 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008645 }
8646 return infos;
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008649 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008650 }
8651
8652 @Override
8653 public boolean switchSlots(int[] physicalSlots) {
8654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008655
8656 final long identity = Binder.clearCallingIdentity();
8657 try {
8658 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008662 }
Jack Yu4c988042018-02-27 15:30:01 -08008663
8664 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008665 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008666 final long identity = Binder.clearCallingIdentity();
8667 try {
8668 return UiccController.getInstance().getCardIdForDefaultEuicc();
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 }
8673
Pengquan Meng85728fb2018-03-12 16:31:21 -07008674 /**
goneil47ffb6e2018-04-06 15:40:58 -07008675 * A test API to reload the UICC profile.
8676 *
8677 * <p>Requires that the calling app has permission
8678 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8679 * @hide
8680 */
8681 @Override
8682 public void refreshUiccProfile(int subId) {
8683 enforceModifyPermission();
8684
8685 final long identity = Binder.clearCallingIdentity();
8686 try {
8687 Phone phone = getPhone(subId);
8688 if (phone == null) {
8689 return;
8690 }
8691 UiccCard uiccCard = phone.getUiccCard();
8692 if (uiccCard == null) {
8693 return;
8694 }
8695 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8696 if (uiccProfile == null) {
8697 return;
8698 }
8699 uiccProfile.refresh();
8700 } finally {
8701 Binder.restoreCallingIdentity(identity);
8702 }
8703 }
8704
8705 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008706 * Returns false if the mobile data is disabled by default, otherwise return true.
8707 */
8708 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008709 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008710 }
8711
8712 /**
8713 * Returns true if the data roaming is enabled by default, i.e the system property
8714 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8715 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8716 */
8717 private boolean getDefaultDataRoamingEnabled(int subId) {
8718 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008719 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008720 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008721 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8722 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8723 return isDataRoamingEnabled;
8724 }
8725
8726 /**
8727 * Returns the default network type for the given {@code subId}, if the default network type is
8728 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8729 */
8730 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008731 List<Integer> list = TelephonyProperties.default_network();
8732 int phoneId = mSubscriptionController.getPhoneId(subId);
8733 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8734 return list.get(phoneId);
8735 }
8736 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008737 }
fionaxua13278b2018-03-21 00:08:13 -07008738
8739 @Override
8740 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008741 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 final Phone phone = getPhone(subId);
8747 if (phone == null) {
8748 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8749 return;
8750 }
chen xueaba88a2019-03-15 13:15:10 -07008751 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8752 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008753 if (carrierPrivilegeRules == null) {
8754 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8755 } else {
8756 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008758 } finally {
8759 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008760 }
fionaxua13278b2018-03-21 00:08:13 -07008761 }
8762
8763 @Override
8764 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008765 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008766
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 final Phone phone = getPhone(subId);
8770 if (phone == null) {
8771 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8772 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8773 }
8774 return phone.getCarrierIdListVersion();
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008777 }
fionaxua13278b2018-03-21 00:08:13 -07008778 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008779
8780 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008781 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8782 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008784 mApp, subId, callingPackage, callingFeatureId,
8785 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008786 return -1;
8787 }
8788
8789 final long identity = Binder.clearCallingIdentity();
8790 try {
8791 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8792 } finally {
8793 Binder.restoreCallingIdentity(identity);
8794 }
8795 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008796
8797 @Override
8798 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008799 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008800 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008801 mApp, subId, "getCdmaRoamingMode");
8802
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8806 } finally {
8807 Binder.restoreCallingIdentity(identity);
8808 }
8809 }
8810
8811 @Override
8812 public boolean setCdmaRoamingMode(int subId, int mode) {
8813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8814 mApp, subId, "setCdmaRoamingMode");
8815
8816 final long identity = Binder.clearCallingIdentity();
8817 try {
8818 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8819 } finally {
8820 Binder.restoreCallingIdentity(identity);
8821 }
8822 }
8823
8824 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008825 public int getCdmaSubscriptionMode(int subId) {
8826 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008827 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008828 mApp, subId, "getCdmaSubscriptionMode");
8829
8830 final long identity = Binder.clearCallingIdentity();
8831 try {
8832 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8833 } finally {
8834 Binder.restoreCallingIdentity(identity);
8835 }
8836 }
8837
8838 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008839 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8841 mApp, subId, "setCdmaSubscriptionMode");
8842
8843 final long identity = Binder.clearCallingIdentity();
8844 try {
8845 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
8849 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008850
sqianc5eccab2018-10-19 18:46:41 -07008851 @Override
sqian8c685422019-02-22 15:55:18 -08008852 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008853 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008855 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8856 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008857 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8858 }
8859 final long identity = Binder.clearCallingIdentity();
8860 try {
sqian854d44b2018-12-12 16:48:18 -08008861 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8862 for (Phone phone: PhoneFactory.getPhones()) {
8863 if (phone.getEmergencyNumberTracker() != null
8864 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8865 emergencyNumberListInternal.put(
8866 phone.getSubId(),
8867 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8868 }
sqian11b7a0e2018-12-05 18:48:28 -08008869 }
sqian854d44b2018-12-12 16:48:18 -08008870 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
sqianc5eccab2018-10-19 18:46:41 -07008874 }
8875
8876 @Override
sqian8c685422019-02-22 15:55:18 -08008877 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008878 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008879 if (!exactMatch) {
8880 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008881 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008882 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008883 }
8884 final long identity = Binder.clearCallingIdentity();
8885 try {
sqian854d44b2018-12-12 16:48:18 -08008886 for (Phone phone: PhoneFactory.getPhones()) {
8887 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008888 && phone.getEmergencyNumberTracker()
8889 .isEmergencyNumber(number, exactMatch)) {
8890 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008891 }
sqian11b7a0e2018-12-05 18:48:28 -08008892 }
8893 return false;
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
8896 }
8897 }
8898
sqianf4ca7ed2019-01-15 18:32:07 -08008899 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008900 * Start emergency callback mode for GsmCdmaPhone for testing.
8901 */
8902 @Override
8903 public void startEmergencyCallbackMode() {
8904 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8905 "startEmergencyCallbackMode");
8906 enforceModifyPermission();
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
8909 for (Phone phone : PhoneFactory.getPhones()) {
8910 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8911 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8912 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8913 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8914 gsmCdmaPhone.obtainMessage(
8915 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8916 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8917 }
8918 }
8919 } finally {
8920 Binder.restoreCallingIdentity(identity);
8921 }
8922 }
8923
8924 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008925 * Update emergency number list for test mode.
8926 */
8927 @Override
8928 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8929 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8930 "updateEmergencyNumberListTestMode");
8931
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 for (Phone phone: PhoneFactory.getPhones()) {
8935 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8936 if (tracker != null) {
8937 tracker.executeEmergencyNumberTestModeCommand(action, num);
8938 }
8939 }
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
8942 }
8943 }
8944
8945 /**
8946 * Get the full emergency number list for test mode.
8947 */
8948 @Override
8949 public List<String> getEmergencyNumberListTestMode() {
8950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8951 "getEmergencyNumberListTestMode");
8952
8953 final long identity = Binder.clearCallingIdentity();
8954 try {
8955 Set<String> emergencyNumbers = new HashSet<>();
8956 for (Phone phone: PhoneFactory.getPhones()) {
8957 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8958 if (tracker != null) {
8959 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8960 emergencyNumbers.add(num.getNumber());
8961 }
8962 }
8963 }
8964 return new ArrayList<>(emergencyNumbers);
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
8968 }
8969
chen xud6b45bd2018-10-30 22:27:10 -07008970 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008971 public int getEmergencyNumberDbVersion(int subId) {
8972 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8973
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 final Phone phone = getPhone(subId);
8977 if (phone == null) {
8978 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8979 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8980 }
8981 return phone.getEmergencyNumberDbVersion();
8982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
8986
8987 @Override
8988 public void notifyOtaEmergencyNumberDbInstalled() {
8989 enforceModifyPermission();
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 for (Phone phone: PhoneFactory.getPhones()) {
8994 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8995 if (tracker != null) {
8996 tracker.updateOtaEmergencyNumberDatabase();
8997 }
8998 }
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
9004 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009005 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009006 enforceActiveEmergencySessionPermission();
9007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 for (Phone phone: PhoneFactory.getPhones()) {
9011 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9012 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009013 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9014 }
9015 }
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
9021 @Override
9022 public void resetOtaEmergencyNumberDbFilePath() {
9023 enforceActiveEmergencySessionPermission();
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 for (Phone phone: PhoneFactory.getPhones()) {
9028 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9029 if (tracker != null) {
9030 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009031 }
9032 }
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
9036 }
9037
9038 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009039 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9040 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9041 Phone phone = getPhone(subId);
9042 if (phone == null) {
9043 return null;
9044 }
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 UiccProfile profile = UiccController.getInstance()
9048 .getUiccProfileForPhone(phone.getPhoneId());
9049 if (profile != null) {
9050 return profile.getCertsFromCarrierPrivilegeAccessRules();
9051 }
9052 } finally {
9053 Binder.restoreCallingIdentity(identity);
9054 }
9055 return null;
9056 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009057
9058 /**
9059 * Enable or disable a modem stack.
9060 */
9061 @Override
9062 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9063 enforceModifyPermission();
9064
9065 final long identity = Binder.clearCallingIdentity();
9066 try {
9067 Phone phone = PhoneFactory.getPhone(slotIndex);
9068 if (phone == null) {
9069 return false;
9070 } else {
9071 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9072 }
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
Michelecea4cf22018-12-21 15:00:11 -08009077
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009078 /**
9079 * Whether a modem stack is enabled or not.
9080 */
9081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009082 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9083 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009084 Phone phone = PhoneFactory.getPhone(slotIndex);
9085 if (phone == null) return false;
9086
9087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009088 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9089 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009090 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9091 }
9092
9093 final long identity = Binder.clearCallingIdentity();
9094 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009095 try {
9096 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9097 } catch (NoSuchElementException ex) {
9098 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9099 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
9104
Michelecea4cf22018-12-21 15:00:11 -08009105 @Override
Michele0ea7d782019-03-19 14:58:42 -07009106 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009107 enforceModifyPermission();
9108
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009112 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009113 .commit();
9114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
9119 @Override
Michele0ea7d782019-03-19 14:58:42 -07009120 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009121 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009123 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9124 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009125 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009126 }
Michelecea4cf22018-12-21 15:00:11 -08009127
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
Michele0ea7d782019-03-19 14:58:42 -07009130 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009131 } finally {
9132 Binder.restoreCallingIdentity(identity);
9133 }
9134 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009135
Michele0ea7d782019-03-19 14:58:42 -07009136 @TelephonyManager.IsMultiSimSupportedResult
9137 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009138 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9139 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9140 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009141 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9142 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009143 }
9144 // Check if the hardware supports multisim functionality. If usage of multisim is not
9145 // supported by the modem, indicate that it is restricted.
9146 PhoneCapability staticCapability =
9147 mPhoneConfigurationManager.getStaticPhoneCapability();
9148 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009149 loge("isMultiSimSupportedInternal: no static configuration available");
9150 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009151 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009152 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009153 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9154 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009155 }
9156 // Check if support of multiple SIMs is restricted by carrier
9157 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009158 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009159 }
9160
Michele0ea7d782019-03-19 14:58:42 -07009161 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009162 }
9163
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009164 /**
9165 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009166 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9167 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9168 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009169 * @param numOfSims number of active sims we want to switch to
9170 */
9171 @Override
9172 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009173 if (numOfSims == 1) {
9174 enforceModifyPermission();
9175 } else {
9176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9177 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9178 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009179 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009180
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009181 try {
Michele30b57b22019-03-01 12:01:14 -08009182 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009183 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009184 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9185 return;
9186 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009187 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009193 @Override
9194 public boolean isApplicationOnUicc(int subId, int appType) {
9195 enforceReadPrivilegedPermission("isApplicationOnUicc");
9196 Phone phone = getPhone(subId);
9197 if (phone == null) {
9198 return false;
9199 }
9200 final long identity = Binder.clearCallingIdentity();
9201 try {
9202 UiccCard uiccCard = phone.getUiccCard();
9203 if (uiccCard == null) {
9204 return false;
9205 }
9206 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9207 if (uiccProfile == null) {
9208 return false;
9209 }
9210 if (TelephonyManager.APPTYPE_SIM <= appType
9211 && appType <= TelephonyManager.APPTYPE_ISIM) {
9212 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9213 }
9214 return false;
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
9217 }
9218 }
9219
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009220 /**
chen xub4baa772019-04-03 10:23:41 -07009221 * Get whether making changes to modem configurations will trigger reboot.
9222 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009223 */
9224 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009225 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9226 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009228 mApp, subId, callingPackage, callingFeatureId,
9229 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009230 return false;
9231 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009232 final long identity = Binder.clearCallingIdentity();
9233 try {
9234 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
Nathan Harold29f5f052019-02-15 13:41:57 -08009240 private void updateModemStateMetrics() {
9241 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9242 // TODO: check the state for each modem if the api is ready.
9243 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9244 }
9245
Pengquan Meng3889a572019-01-23 11:16:29 -08009246 @Override
9247 public int[] getSlotsMapping() {
9248 enforceReadPrivilegedPermission("getSlotsMapping");
9249
9250 final long identity = Binder.clearCallingIdentity();
9251 try {
9252 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9253 // All logical slots should have a mapping to a physical slot.
9254 int[] logicalSlotsMapping = new int[phoneCount];
9255 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9256 for (int i = 0; i < slotInfos.length; i++) {
9257 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9258 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9259 }
9260 }
9261 return logicalSlotsMapping;
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009266
9267 /**
9268 * Get the IRadio HAL Version
9269 */
9270 @Override
9271 public int getRadioHalVersion() {
9272 Phone phone = getDefaultPhone();
9273 if (phone == null) return -1;
9274 HalVersion hv = phone.getHalVersion();
9275 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9276 return hv.major * 100 + hv.minor;
9277 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009278
9279 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009280 * Get the current calling package name.
9281 * @return the current calling package name
9282 */
9283 @Override
9284 public String getCurrentPackageName() {
9285 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9286 }
9287
9288 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009289 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9290 * corresponding network requests on a subId.
9291 *
9292 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009293 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009294 * 2) APN is un-metered for this subscription, or
9295 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009296 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009297 *
9298 * @return whether data is allowed for a apn type.
9299 *
9300 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009301 */
9302 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009303 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009304 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9305 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009306
9307 // Now that all security checks passes, perform the operation as ourselves.
9308 final long identity = Binder.clearCallingIdentity();
9309 try {
9310 Phone phone = getPhone(subId);
9311 if (phone == null) return false;
9312
Jack Yu41407ee2019-05-13 16:54:09 -07009313 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009314 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
9320 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009321 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009322 enforceReadPrivilegedPermission("isApnMetered");
9323
9324 // Now that all security checks passes, perform the operation as ourselves.
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
9327 Phone phone = getPhone(subId);
9328 if (phone == null) return true; // By default return true.
9329
Jack Yu41407ee2019-05-13 16:54:09 -07009330 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009335
9336 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009337 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9338 int subscriptionId, IBooleanConsumer resultCallback) {
9339 enforceModifyPermission();
9340 long token = Binder.clearCallingIdentity();
9341 try {
9342 Phone phone = getPhone(subscriptionId);
9343 if (phone == null) {
9344 try {
9345 if (resultCallback != null) {
9346 resultCallback.accept(false);
9347 }
9348 } catch (RemoteException e) {
9349 // ignore
9350 }
9351 return;
9352 }
9353 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9354 Pair.create(specifiers, (x) -> {
9355 try {
9356 if (resultCallback != null) {
9357 resultCallback.accept(x);
9358 }
9359 } catch (RemoteException e) {
9360 // ignore
9361 }
9362 });
9363 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9364 } finally {
9365 Binder.restoreCallingIdentity(token);
9366 }
9367 }
9368
9369 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009370 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9371 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009372 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009373 mApp, subId, "getSystemSelectionChannels");
9374 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009377 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9378 if (result instanceof IllegalStateException) {
9379 throw (IllegalStateException) result;
9380 }
9381 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009382 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9383 return specifiers;
9384 } finally {
9385 Binder.restoreCallingIdentity(identity);
9386 }
9387 }
9388
9389 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009390 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009391 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009392 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9393 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9394 if (iccRecords == null) {
9395 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9396 return false;
9397 }
9398 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9399 }
9400
9401 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009402 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9403 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009404 if (callingPackage == null) {
9405 callingPackage = getCurrentPackageName();
9406 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009407 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9408 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009409 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9410 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009411 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9412 }
9413 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9414 Intent intent = new Intent();
9415 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9416 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9417 // Bring up choose default SMS subscription dialog right now
9418 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9419 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9420 mApp.startActivity(intent);
9421 }
chen xud5ca2d52019-05-28 15:20:57 -07009422
9423 @Override
9424 public String getMmsUAProfUrl(int subId) {
9425 //TODO investigate if this API should require proper permission check in R b/133791609
9426 final long identity = Binder.clearCallingIdentity();
9427 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009428 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9429 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9430 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9431 return carrierUAProfUrl;
9432 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009433 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9434 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 }
9439
9440 @Override
9441 public String getMmsUserAgent(int subId) {
9442 //TODO investigate if this API should require proper permission check in R b/133791609
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009445 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9446 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9447 if (!TextUtils.isEmpty(carrierUserAgent)) {
9448 return carrierUserAgent;
9449 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009450 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9451 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009452 } finally {
9453 Binder.restoreCallingIdentity(identity);
9454 }
9455 }
Jack Yub07d4972019-05-28 16:12:25 -07009456
9457 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009458 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9459 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009460
Jack Yub07d4972019-05-28 16:12:25 -07009461 final long identity = Binder.clearCallingIdentity();
9462 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009463 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009464 if (phone == null) return false;
9465
Hall Liua62f5da2020-09-25 10:42:19 -07009466 switch (policy) {
9467 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9468 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9469 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9470 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9471 default:
9472 throw new IllegalArgumentException(policy + " is not a valid policy");
9473 }
Jack Yub07d4972019-05-28 16:12:25 -07009474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478
9479 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009480 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009481 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009482 enforceModifyPermission();
9483
changbettyd5c246e2019-12-24 15:40:37 +08009484 final long identity = Binder.clearCallingIdentity();
9485 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009486 Phone phone = getPhone(subscriptionId);
9487 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009488
Hall Liua62f5da2020-09-25 10:42:19 -07009489 switch (policy) {
9490 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9491 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9492 break;
9493 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9494 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9495 break;
9496 default:
9497 throw new IllegalArgumentException(policy + " is not a valid policy");
9498 }
changbettyd5c246e2019-12-24 15:40:37 +08009499 } finally {
9500 Binder.restoreCallingIdentity(identity);
9501 }
9502 }
9503
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009504 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009505 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009506 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9507 * otherwise.
9508 */
9509 @Override
9510 public void setCepEnabled(boolean isCepEnabled) {
9511 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9512
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9516 for (Phone phone : PhoneFactory.getPhones()) {
9517 Phone defaultPhone = phone.getImsPhone();
9518 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9519 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9520 ImsPhoneCallTracker imsPhoneCallTracker =
9521 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9522 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9523 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9524 + imsPhone.getMsisdn());
9525 }
9526 }
9527 } finally {
9528 Binder.restoreCallingIdentity(identity);
9529 }
9530 }
allenwtsu46dcc572020-01-08 18:24:03 +08009531
9532 /**
9533 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9534 *
9535 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9536 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9537 * before being read.
9538 */
9539 @Override
9540 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9541 isCompressed) {
9542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9543 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009544 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9545 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9546 }
9547 if (!isImsAvailableOnDevice()) {
9548 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9549 "IMS not available on device.");
9550 }
9551
9552 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009553 try {
Hui Wang761a6682020-10-31 05:12:53 +00009554 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9555 } finally {
9556 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009557 }
9558 }
zoey chene02881a2019-12-30 16:11:23 +08009559
9560 @Override
9561 public boolean isIccLockEnabled(int subId) {
9562 enforceReadPrivilegedPermission("isIccLockEnabled");
9563
9564 // Now that all security checks passes, perform the operation as ourselves.
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
9567 Phone phone = getPhone(subId);
9568 if (phone != null && phone.getIccCard() != null) {
9569 return phone.getIccCard().getIccLockEnabled();
9570 } else {
9571 return false;
9572 }
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
9577
9578 /**
9579 * Set the ICC pin lock enabled or disabled.
9580 *
9581 * @return an integer representing the status of IccLock enabled or disabled in the following
9582 * three cases:
9583 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9584 * successfully.
9585 * - Positive number and zero for remaining password attempts.
9586 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9587 *
9588 */
9589 @Override
9590 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9591 enforceModifyPermission();
9592
9593 Phone phone = getPhone(subId);
9594 if (phone == null) {
9595 return 0;
9596 }
9597 // Now that all security checks passes, perform the operation as ourselves.
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9601 new Pair<Boolean, String>(enabled, password), phone, null);
9602 return attemptsRemaining;
9603
9604 } catch (Exception e) {
9605 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
9609 return 0;
9610 }
9611
9612 /**
9613 * Change the ICC password used in ICC pin lock.
9614 *
9615 * @return an integer representing the status of IccLock changed in the following three cases:
9616 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9617 * - Positive number and zero for remaining password attempts.
9618 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9619 *
9620 */
9621 @Override
9622 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9623 enforceModifyPermission();
9624
9625 Phone phone = getPhone(subId);
9626 if (phone == null) {
9627 return 0;
9628 }
9629 // Now that all security checks passes, perform the operation as ourselves.
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9633 new Pair<String, String>(oldPassword, newPassword), phone, null);
9634 return attemptsRemaining;
9635
9636 } catch (Exception e) {
9637 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 return 0;
9642 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009643
9644 /**
9645 * Request for receiving user activity notification
9646 */
9647 @Override
9648 public void requestUserActivityNotification() {
9649 if (!mNotifyUserActivity.get()
9650 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9651 mNotifyUserActivity.set(true);
9652 }
9653 }
9654
9655 /**
9656 * Called when userActivity is signalled in the power manager.
9657 * This is safe to call from any thread, with any window manager locks held or not.
9658 */
9659 @Override
9660 public void userActivity() {
9661 // ***************************************
9662 // * Inherited from PhoneWindowManager *
9663 // ***************************************
9664 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9665 // WITH ITS LOCKS HELD.
9666 //
9667 // This code must be VERY careful about the locks
9668 // it acquires.
9669 // In fact, the current code acquires way too many,
9670 // and probably has lurking deadlocks.
9671
9672 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9673 throw new SecurityException("Only the OS may call notifyUserActivity()");
9674 }
9675
9676 if (mNotifyUserActivity.getAndSet(false)) {
9677 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9678 USER_ACTIVITY_NOTIFICATION_DELAY);
9679 }
9680 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009681
9682 @Override
9683 public boolean canConnectTo5GInDsdsMode() {
9684 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9685 }
Jack Yud10cdd42020-09-28 20:28:01 -07009686
9687 @Override
9688 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9689 String callingFeatureId) {
9690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9691 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9692 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9693 }
9694
9695 Phone phone = getPhone(subId);
9696 if (phone == null) {
9697 throw new RuntimeException("phone is not available");
9698 }
9699 // Now that all security checks passes, perform the operation as ourselves.
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 return phone.getEquivalentHomePlmns();
9703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
Daniel Bright59e67312020-11-13 11:49:37 -08009707
9708 @Override
9709 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009710 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9711 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009712 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009713 if (radioInterfaceCapabilities == null) {
9714 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009715 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009716 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009717 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009718
Hui Wang641e81c2020-10-12 12:14:23 -07009719 @Override
9720 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9721 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009722 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9723 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9724 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9725 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9726 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009727 if (DBG) {
9728 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9729 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9730 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9731 }
9732
9733 if (!SubscriptionManager.isValidSubscriptionId(subId)
9734 || appType < TelephonyManager.APPTYPE_UNKNOWN
9735 || appType > TelephonyManager.APPTYPE_ISIM
9736 || nafUrl == null || securityProtocol == null || callback == null) {
9737 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9738 if (callback != null) {
9739 try {
9740 callback.onAuthenticationFailure(
9741 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9742 } catch (RemoteException exception) {
9743 log("Fail to notify onAuthenticationFailure due to " + exception);
9744 }
9745 return;
9746 }
9747 }
9748
9749 final long token = Binder.clearCallingIdentity();
9750 try {
9751 getGbaManager(subId).bootstrapAuthenticationRequest(
9752 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9753 forceBootStrapping, callback));
9754 } finally {
9755 Binder.restoreCallingIdentity(token);
9756 }
9757 }
9758
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009759 /**
9760 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9761 * requested radio power state will actually be set. See {@link
9762 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9763 *
9764 * @param subId the subscription ID of the phone requesting to set the radio power state.
9765 * @param enable {@code true} if trying to turn radio on.
9766 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9767 * false}.
9768 */
9769 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9770 Phone phone = getPhone(subId);
9771 if (phone != null) {
9772 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9773 return true;
9774 }
9775 return false;
9776 }
9777
9778 private int handleDataThrottlingRequest(int subId,
9779 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009780 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9781 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9782 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9783 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9784 throw new IllegalArgumentException("modem does not support data throttling");
9785 }
9786
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009787 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9788 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9789 if (!setRadioPowerForThermal(subId, true)) {
9790 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9791 }
9792
9793 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9794
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009795 if (isDataThrottlingSupported) {
9796 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009797 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009798 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9799 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9800 } else if (thermalMitigationResult
9801 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9802 throw new IllegalArgumentException("modem does not support data throttling");
9803 }
9804 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009805 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009806
9807 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009808 }
9809
Jack Nudelman644b91a2021-03-12 14:09:48 -08009810 private static List<String> getThermalMitigationAllowlist(Context context) {
9811 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9812 for (String pckg : context.getResources()
9813 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9814 sThermalMitigationAllowlistedPackages.add(pckg);
9815 }
9816 }
9817
9818 return sThermalMitigationAllowlistedPackages;
9819 }
9820
9821 /**
9822 * Used by shell commands to add an authorized package name for thermal mitigation.
9823 * @param packageName name of package to be allowlisted
9824 * @param context
9825 */
9826 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9827 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9828 sThermalMitigationAllowlistedPackages.add(packageName);
9829 }
9830
9831 /**
9832 * Used by shell commands to remove an authorized package name for thermal mitigation.
9833 * @param packageName name of package to remove from allowlist
9834 * @param context
9835 */
9836 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9837 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9838 sThermalMitigationAllowlistedPackages.remove(packageName);
9839 }
9840
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009841 /**
9842 * Thermal mitigation request to control functionalities at modem.
9843 *
9844 * @param subId the id of the subscription.
9845 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009846 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009847 *
9848 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9849 */
9850 @Override
9851 @ThermalMitigationResult
9852 public int sendThermalMitigationRequest(
9853 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009854 ThermalMitigationRequest thermalMitigationRequest,
9855 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009856 enforceModifyPermission();
9857
Jack Nudelman644b91a2021-03-12 14:09:48 -08009858 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9859 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9860 .contains(callingPackage)) {
9861 throw new SecurityException("Calling package must be configured in the device config. "
9862 + "calling package: " + callingPackage);
9863 }
9864
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009865 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9866 final long identity = Binder.clearCallingIdentity();
9867
9868 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9869 try {
9870 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9871 switch (thermalMitigationAction) {
9872 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9873 thermalMitigationResult =
9874 handleDataThrottlingRequest(subId,
9875 thermalMitigationRequest.getDataThrottlingRequest());
9876 break;
9877 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9878 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9879 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9880 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9881 }
9882
9883 // Ensure that radio is on. If not able to power on due to phone being
9884 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9885 if (!setRadioPowerForThermal(subId, true)) {
9886 thermalMitigationResult =
9887 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9888 break;
9889 }
9890
9891 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9892 false);
9893 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9894 break;
9895 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9896 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9897 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9898 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9899 }
9900
9901 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9902 if (registry != null) {
9903 TelephonyConnectionService service =
9904 registry.getTelephonyConnectionService();
9905 Phone phone = getPhone(subId);
9906 if (phone == null) {
9907 thermalMitigationResult =
9908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9909 break;
9910 }
9911
9912 if (PhoneConstantConversions.convertCallState(phone.getState())
9913 != TelephonyManager.CALL_STATE_IDLE
9914 || phone.isInEmergencySmsMode() || phone.isInEcm()
9915 || (service != null && service.isEmergencyCallPending())) {
9916 String errorMessage = "Phone state is not valid. call state = "
9917 + PhoneConstantConversions.convertCallState(phone.getState())
9918 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9919 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9920 errorMessage += service == null
9921 ? " TelephonyConnectionService is null"
9922 : " isEmergencyCallPending = "
9923 + service.isEmergencyCallPending();
9924 Log.e(LOG_TAG, errorMessage);
9925 thermalMitigationResult =
9926 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9927 break;
9928 }
9929 } else {
9930 thermalMitigationResult =
9931 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9932 break;
9933 }
9934
9935 // Turn radio off. If not able to power off due to phone being unavailable,
9936 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9937 if (!setRadioPowerForThermal(subId, false)) {
9938 thermalMitigationResult =
9939 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9940 break;
9941 }
9942 thermalMitigationResult =
9943 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9944 break;
9945 default:
9946 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9947 + "not exist. Requested action: " + thermalMitigationAction);
9948 }
9949 } catch (IllegalArgumentException e) {
9950 throw e;
9951 } catch (Exception e) {
9952 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9953 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9954 } finally {
9955 Binder.restoreCallingIdentity(identity);
9956 }
9957
9958 if (DBG) {
9959 log("thermalMitigationRequest returning with thermalMitigationResult: "
9960 + thermalMitigationResult);
9961 }
9962
9963 return thermalMitigationResult;
9964 }
Hui Wang641e81c2020-10-12 12:14:23 -07009965
9966 /**
9967 * Set the GbaService Package Name that Telephony will bind to.
9968 *
9969 * @param subId The sim that the GbaService is associated with.
9970 * @param packageName The name of the package to be replaced with.
9971 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9972 */
9973 @Override
9974 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9975 enforceModifyPermission();
9976
9977 final long identity = Binder.clearCallingIdentity();
9978 try {
9979 return getGbaManager(subId).overrideServicePackage(packageName);
9980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 }
9984
9985 /**
9986 * Return the package name of the currently bound GbaService.
9987 *
9988 * @param subId The sim that the GbaService is associated with.
9989 * @return the package name of the GbaService configuration, null if GBA is not supported.
9990 */
9991 @Override
9992 public String getBoundGbaService(int subId) {
9993 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9994
9995 final long identity = Binder.clearCallingIdentity();
9996 try {
9997 return getGbaManager(subId).getServicePackage();
9998 } finally {
9999 Binder.restoreCallingIdentity(identity);
10000 }
10001 }
10002
10003 /**
10004 * Set the release time for telephony to unbind GbaService.
10005 *
10006 * @param subId The sim that the GbaService is associated with.
10007 * @param interval The release time to unbind GbaService by millisecond.
10008 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10009 */
10010 @Override
10011 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10012 enforceModifyPermission();
10013
10014 final long identity = Binder.clearCallingIdentity();
10015 try {
10016 return getGbaManager(subId).overrideReleaseTime(interval);
10017 } finally {
10018 Binder.restoreCallingIdentity(identity);
10019 }
10020 }
10021
10022 /**
10023 * Return the release time for telephony to unbind GbaService.
10024 *
10025 * @param subId The sim that the GbaService is associated with.
10026 * @return The release time to unbind GbaService by millisecond.
10027 */
10028 @Override
10029 public int getGbaReleaseTime(int subId) {
10030 enforceReadPrivilegedPermission("getGbaReleaseTime");
10031
10032 final long identity = Binder.clearCallingIdentity();
10033 try {
10034 return getGbaManager(subId).getReleaseTime();
10035 } finally {
10036 Binder.restoreCallingIdentity(identity);
10037 }
10038 }
10039
10040 private GbaManager getGbaManager(int subId) {
10041 GbaManager instance = GbaManager.getInstance(subId);
10042 if (instance == null) {
10043 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10044 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10045 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10046 }
10047 return instance;
10048 }
Hui Wang761a6682020-10-31 05:12:53 +000010049
10050 /**
10051 * indicate whether the device and the carrier can support
10052 * RCS VoLTE single registration.
10053 */
10054 @Override
10055 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010056 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10057 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10058 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10059 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010060
10061 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10062 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10063 }
10064
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10068 if (rpm != null) {
10069 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
10070 }
10071 return false;
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 /**
10078 * Register RCS provisioning callback.
10079 */
10080 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010081 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010082 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010083 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010084 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010085 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10086 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010087
10088 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10089 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10090 }
10091 if (!isImsAvailableOnDevice()) {
10092 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10093 "IMS not available on device.");
10094 }
10095
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010098 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010099 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -080010100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10101 "Service not available for the subscription.");
10102 }
Hui Wang761a6682020-10-31 05:12:53 +000010103 } finally {
10104 Binder.restoreCallingIdentity(identity);
10105 }
10106 }
10107
10108 /**
10109 * Unregister RCS provisioning callback.
10110 */
10111 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010112 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010113 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010114 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010115 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010116 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10117 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010118
10119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10120 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10121 }
10122 if (!isImsAvailableOnDevice()) {
10123 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10124 "IMS not available on device.");
10125 }
10126
10127 final long identity = Binder.clearCallingIdentity();
10128 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010129 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010130 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
10134 }
10135
10136 /**
10137 * trigger RCS reconfiguration.
10138 */
10139 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010140 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10141 "triggerRcsReconfiguration",
10142 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010143
10144 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10145 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10146 }
10147 if (!isImsAvailableOnDevice()) {
10148 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10149 "IMS not available on device.");
10150 }
10151
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10155 } finally {
10156 Binder.restoreCallingIdentity(identity);
10157 }
10158 }
10159
10160 /**
10161 * Provide the client configuration parameters of the RCS application.
10162 */
10163 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010164 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10165 "setRcsClientConfiguration",
10166 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010167
10168 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10169 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10170 }
10171 if (!isImsAvailableOnDevice()) {
10172 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10173 "IMS not available on device.");
10174 }
10175
10176 final long identity = Binder.clearCallingIdentity();
10177
10178 try {
10179 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10180 if (configBinder == null) {
10181 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10182 } else {
10183 configBinder.setRcsClientConfiguration(rcc);
10184 }
10185 } catch (RemoteException e) {
10186 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010193 * Enables or disables the test mode for RCS VoLTE single registration.
10194 */
10195 @Override
10196 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10198 "setRcsSingleRegistrationTestModeEnabled");
10199
10200 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10201 }
10202
10203 /**
10204 * Gets the test mode for RCS VoLTE single registration.
10205 */
10206 @Override
10207 public boolean getRcsSingleRegistrationTestModeEnabled() {
10208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10209 "getRcsSingleRegistrationTestModeEnabled");
10210
10211 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10212 }
10213
10214 /**
Hui Wang761a6682020-10-31 05:12:53 +000010215 * Overrides the config of RCS VoLTE single registration enabled for the device.
10216 */
10217 @Override
10218 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10220 "setDeviceSingleRegistrationEnabledOverride");
10221 enforceModifyPermission();
10222
10223 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10224 : Boolean.parseBoolean(enabledStr);
10225 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010226 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010227 }
10228
10229 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010230 * Sends a device to device communication message. Only usable via shell.
10231 * @param message message to send.
10232 * @param value message value.
10233 */
10234 @Override
10235 public void sendDeviceToDeviceMessage(int message, int value) {
10236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010237 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010238 enforceModifyPermission();
10239
10240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 TelephonyConnectionService service =
10243 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10244 if (service == null) {
10245 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10246 return;
10247 }
10248 service.sendTestDeviceToDeviceMessage(message, value);
10249 } finally {
10250 Binder.restoreCallingIdentity(identity);
10251 }
10252 }
10253
Tyler Gunnbabbda02021-02-10 11:05:02 -080010254 /**
10255 * Sets the specified device to device transport active.
10256 * @param transport The transport to set active.
10257 */
10258 @Override
10259 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10261 "setActiveDeviceToDeviceTransport");
10262 enforceModifyPermission();
10263
10264 final long identity = Binder.clearCallingIdentity();
10265 try {
10266 TelephonyConnectionService service =
10267 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10268 if (service == null) {
10269 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10270 return;
10271 }
10272 service.setActiveDeviceToDeviceTransport(transport);
10273 } finally {
10274 Binder.restoreCallingIdentity(identity);
10275 }
10276 }
Tyler Gunn92479152021-01-20 16:30:10 -080010277
10278 /**
Hui Wang761a6682020-10-31 05:12:53 +000010279 * Gets the config of RCS VoLTE single registration enabled for the device.
10280 */
10281 @Override
10282 public boolean getDeviceSingleRegistrationEnabled() {
10283 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10284 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10285 }
10286
10287 /**
10288 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10289 */
10290 @Override
10291 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10293 "setCarrierSingleRegistrationEnabledOverride");
10294 enforceModifyPermission();
10295
10296 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10297 : Boolean.parseBoolean(enabledStr);
10298 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10299 subId, enabled);
10300 }
10301
10302 /**
10303 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10304 */
10305 @Override
10306 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10307 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10308 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10309 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010310
10311 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010312 * Overrides the ims feature validation result
10313 */
10314 @Override
10315 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10317 "setImsFeatureValidationOverride");
10318
10319 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10320 : Boolean.parseBoolean(enabledStr);
10321 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10322 subId, enabled);
10323 }
10324
10325 /**
10326 * Gets the ims feature validation override value
10327 */
10328 @Override
10329 public boolean getImsFeatureValidationOverride(int subId) {
10330 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10331 "getImsFeatureValidationOverride");
10332 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10333 }
10334
10335 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010336 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10337 * their mobile plan.
10338 */
10339 @Override
10340 public String getMobileProvisioningUrl() {
10341 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 return getDefaultPhone().getMobileProvisioningUrl();
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010349
James.cf Linbcdf8b32021-01-14 16:44:13 +080010350 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010351 * Get the EAB contact from the EAB database.
10352 */
10353 @Override
10354 public String getContactFromEab(String contact) {
10355 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10356 enforceModifyPermission();
10357 final long identity = Binder.clearCallingIdentity();
10358 try {
10359 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010366 * Remove the EAB contacts from the EAB database.
10367 */
10368 @Override
10369 public int removeContactFromEab(int subId, String contacts) {
10370 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10371 enforceModifyPermission();
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
10379
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010380 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010381 public boolean getDeviceUceEnabled() {
10382 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10383 final long identity = Binder.clearCallingIdentity();
10384 try {
10385 return mApp.getDeviceUceEnabled();
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
10390
10391 @Override
10392 public void setDeviceUceEnabled(boolean isEnabled) {
10393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10394 final long identity = Binder.clearCallingIdentity();
10395 try {
10396 mApp.setDeviceUceEnabled(isEnabled);
10397 } finally {
10398 Binder.restoreCallingIdentity(identity);
10399 }
10400 }
10401
Brad Ebinger14d467f2021-02-12 06:18:28 +000010402 /**
10403 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10404 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10405 */
10406 // Used for SHELL command only right now.
10407 @Override
10408 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10409 List<String> featureTags) {
10410 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10411 "addUceRegistrationOverrideShell");
10412 final long identity = Binder.clearCallingIdentity();
10413 try {
10414 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10415 new ArraySet<>(featureTags));
10416 } catch (ImsException e) {
10417 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
10422
10423 /**
10424 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10425 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10426 */
10427 // Used for SHELL command only right now.
10428 @Override
10429 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10430 List<String> featureTags) {
10431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10432 "removeUceRegistrationOverrideShell");
10433 final long identity = Binder.clearCallingIdentity();
10434 try {
10435 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10436 new ArraySet<>(featureTags));
10437 } catch (ImsException e) {
10438 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
10443
10444 /**
10445 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10446 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10447 */
10448 // Used for SHELL command only right now.
10449 @Override
10450 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10452 "clearUceRegistrationOverrideShell");
10453 final long identity = Binder.clearCallingIdentity();
10454 try {
10455 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10456 } catch (ImsException e) {
10457 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
10463 /**
10464 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10465 */
10466 // Used for SHELL command only right now.
10467 @Override
10468 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10469 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10470 "getLatestRcsContactUceCapabilityShell");
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10474 } catch (ImsException e) {
10475 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10476 } finally {
10477 Binder.restoreCallingIdentity(identity);
10478 }
10479 }
10480
10481 /**
10482 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10483 * device does not have an active PUBLISH.
10484 */
10485 // Used for SHELL command only right now.
10486 @Override
10487 public String getLastUcePidfXmlShell(int subId) {
10488 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10489 final long identity = Binder.clearCallingIdentity();
10490 try {
10491 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10492 } catch (ImsException e) {
10493 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10494 } finally {
10495 Binder.restoreCallingIdentity(identity);
10496 }
10497 }
10498
James.cf Line8713a42021-04-29 16:04:26 +080010499 /**
10500 * Remove UCE requests cannot be sent to the network status.
10501 */
10502 // Used for SHELL command only right now.
10503 @Override
10504 public boolean removeUceRequestDisallowedStatus(int subId) {
10505 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10509 } catch (ImsException e) {
10510 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10511 } finally {
10512 Binder.restoreCallingIdentity(identity);
10513 }
10514 }
10515
Brad Ebinger14d467f2021-02-12 06:18:28 +000010516
James.cf Lin4b784aa2021-01-31 03:25:15 +080010517 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010518 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10519 String callingPackage) {
10520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10521 mApp, subId, "setSignalStrengthUpdateRequest");
10522
10523 final int callingUid = Binder.getCallingUid();
10524 // Verify that tha callingPackage belongs to the calling UID
10525 mApp.getSystemService(AppOpsManager.class)
10526 .checkPackage(callingUid, callingPackage);
10527
10528 validateSignalStrengthUpdateRequest(request, callingUid);
10529
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10533 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10534
10535 if (result instanceof IllegalStateException) {
10536 throw (IllegalStateException) result;
10537 }
10538 } finally {
10539 Binder.restoreCallingIdentity(identity);
10540 }
10541 }
10542
10543 @Override
10544 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10545 String callingPackage) {
10546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10547 mApp, subId, "clearSignalStrengthUpdateRequest");
10548
10549 final int callingUid = Binder.getCallingUid();
10550 // Verify that tha callingPackage belongs to the calling UID
10551 mApp.getSystemService(AppOpsManager.class)
10552 .checkPackage(callingUid, callingPackage);
10553
10554 final long identity = Binder.clearCallingIdentity();
10555 try {
10556 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10557 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10558
10559 if (result instanceof IllegalStateException) {
10560 throw (IllegalStateException) result;
10561 }
10562 } finally {
10563 Binder.restoreCallingIdentity(identity);
10564 }
10565 }
10566
10567 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10568 int callingUid) {
10569 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10570 // phone/system process do not have further restriction on request
10571 return;
10572 }
10573
10574 // Applications has restrictions on how to use the request:
10575 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10576 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10577 // This is not system caller which has been checked above
10578 throw new IllegalArgumentException(
10579 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10580 }
10581
10582 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10583 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10584 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10585 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10586 || info.isEnabled()) {
10587 throw new IllegalArgumentException(
10588 "Only system can set hide fields in SignalThresholdInfo");
10589 }
10590
10591 // Thresholds length for each RAN need in range. This has been validated in
10592 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10593 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10594 final int[] thresholds = info.getThresholds();
10595 Objects.requireNonNull(thresholds);
10596 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10597 || thresholds.length
10598 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10599 throw new IllegalArgumentException(
10600 "thresholds length is out of range: " + thresholds.length);
10601 }
10602 }
10603 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010604
10605 /**
10606 * Gets the current phone capability.
10607 *
10608 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10609 * @return the PhoneCapability which describes the data connection capability of modem.
10610 * It's used to evaluate possible phone config change, for example from single
10611 * SIM device to multi-SIM device.
10612 */
10613 @Override
10614 public PhoneCapability getPhoneCapability() {
10615 enforceReadPrivilegedPermission("getPhoneCapability");
10616 final long identity = Binder.clearCallingIdentity();
10617 try {
10618 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10619 } finally {
10620 Binder.restoreCallingIdentity(identity);
10621 }
10622 }
Michele Berionne5e411512020-11-13 02:36:59 +000010623
10624 /**
10625 * Prepare TelephonyManager for an unattended reboot. The reboot is
10626 * required to be done shortly after the API is invoked.
10627 */
10628 @Override
10629 @TelephonyManager.PrepareUnattendedRebootResult
10630 public int prepareForUnattendedReboot() {
10631 enforceRebootPermission();
10632
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010640
10641 /**
10642 * Request to get the current slicing configuration including URSP rules and
10643 * NSSAIs (configured, allowed and rejected).
10644 *
10645 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10646 */
10647 @Override
10648 public void getSlicingConfig(ResultReceiver callback) {
10649 enforceReadPrivilegedPermission("getSlicingConfig");
10650
10651 final long identity = Binder.clearCallingIdentity();
10652 try {
10653 Phone phone = getDefaultPhone();
10654 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010659}