blob: b355e9bbf10590929b2e1246f2eec4cc79d73816 [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) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 Phone phone = PhoneFactory.getPhone(slotIndex);
3135 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003136 return null;
3137 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003138
Jeff Davidson913390f2018-02-23 17:11:49 -08003139 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003140 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003141 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003142 return null;
3143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 return phone.getMeid();
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
Jack Yu2af8d712017-03-15 17:14:14 -07003151 }
3152
3153 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003154 public String getManufacturerCodeForSlot(int slotIndex) {
3155 Phone phone = PhoneFactory.getPhone(slotIndex);
3156 String manufacturerCode = null;
3157 if (phone != null) {
3158 String meid = phone.getMeid();
3159 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3160 }
3161 return manufacturerCode;
3162 }
3163
3164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003165 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3166 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003167 Phone phone = PhoneFactory.getPhone(slotIndex);
3168 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003169 return null;
3170 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003171 int subId = phone.getSubId();
3172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003173 mApp, subId, callingPackage, callingFeatureId,
3174 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003175 return null;
3176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 return phone.getDeviceSvn();
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003184 }
3185
fionaxu43304da2017-11-27 22:51:16 -08003186 @Override
3187 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = getPhone(subId);
3191 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
fionaxu43304da2017-11-27 22:51:16 -08003195 }
3196
3197 @Override
3198 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
3202 return phone == null ? null : phone.getCarrierName();
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
fionaxu43304da2017-11-27 22:51:16 -08003206 }
3207
calvinpanffe225e2018-11-01 19:43:06 +08003208 @Override
chen xu0026ca62019-03-06 15:28:50 -08003209 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 final Phone phone = getPhone(subId);
3213 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003214 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
chen xu0026ca62019-03-06 15:28:50 -08003221 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003225 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
3229 }
3230
chen xu651eec72018-11-11 19:03:44 -08003231 @Override
chen xu864e11c2018-12-06 22:10:03 -08003232 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3233 if (!isSubscriptionMccMnc) {
3234 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3235 }
chen xu651eec72018-11-11 19:03:44 -08003236 final Phone phone = PhoneFactory.getPhone(slotIndex);
3237 if (phone == null) {
3238 return TelephonyManager.UNKNOWN_CARRIER_ID;
3239 }
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 //
3249 // Internal helper methods.
3250 //
3251
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003252 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003253 * Make sure the caller is the calling package itself
3254 *
3255 * @throws SecurityException if the caller is not the calling package
3256 */
3257 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3258 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003259 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3260 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003261 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003262 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003263 } catch (PackageManager.NameNotFoundException e) {
3264 // packageUid is -1
3265 }
3266 if (packageUid != callingUid) {
3267 throw new SecurityException(message + ": Package " + callingPackage
3268 + " does not belong to " + callingUid);
3269 }
3270 }
3271
3272 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3274 *
3275 * @throws SecurityException if the caller does not have the required permission
3276 */
3277 private void enforceModifyPermission() {
3278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3279 }
3280
Shuo Qiancd19c462020-01-16 20:51:11 -08003281 /**
3282 * Make sure the caller is system.
3283 *
3284 * @throws SecurityException if the caller is not system.
3285 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003286 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003287 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3288 throw new SecurityException("Caller must be system");
3289 }
3290 }
3291
Shuo Qian3b6ee772019-11-13 17:43:31 -08003292 private void enforceActiveEmergencySessionPermission() {
3293 mApp.enforceCallingOrSelfPermission(
3294 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3295 }
3296
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 /**
3298 * Make sure the caller has the CALL_PHONE permission.
3299 *
3300 * @throws SecurityException if the caller does not have the required permission
3301 */
3302 private void enforceCallPermission() {
3303 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3304 }
3305
paulhu5a773602019-08-23 19:17:33 +08003306 private void enforceSettingsPermission() {
3307 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003308 }
3309
Michele Berionne5e411512020-11-13 02:36:59 +00003310 private void enforceRebootPermission() {
3311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3312 }
3313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 private String createTelUrl(String number) {
3315 if (TextUtils.isEmpty(number)) {
3316 return null;
3317 }
3318
Jake Hambye994d462014-02-03 13:10:13 -08003319 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003320 }
3321
Ihab Awadf9e92732013-12-05 18:02:52 -08003322 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3324 }
3325
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003326 private static void logv(String msg) {
3327 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3328 }
3329
Ihab Awadf9e92732013-12-05 18:02:52 -08003330 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3332 }
3333
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003334 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003336 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003337 }
3338
Sanket Padawe356d7632015-06-22 14:03:32 -07003339 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003340 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = PhoneFactory.getPhone(slotIndex);
3344 if (phone == null) {
3345 return PhoneConstants.PHONE_TYPE_NONE;
3346 } else {
3347 return phone.getPhoneType();
3348 }
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
3354 /**
3355 * Returns the CDMA ERI icon index to display
3356 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003357 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003358 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3359 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3360 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003361 }
3362
Sanket Padawe356d7632015-06-22 14:03:32 -07003363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003364 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3365 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003367 mApp, subId, callingPackage, callingFeatureId,
3368 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003369 return -1;
3370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 final Phone phone = getPhone(subId);
3375 if (phone != null) {
3376 return phone.getCdmaEriIconIndex();
3377 } else {
3378 return -1;
3379 }
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 }
3384
3385 /**
3386 * Returns the CDMA ERI icon mode,
3387 * 0 - ON
3388 * 1 - FLASHING
3389 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003390 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003391 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3392 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3393 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003394 }
3395
Sanket Padawe356d7632015-06-22 14:03:32 -07003396 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003397 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3398 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003400 mApp, subId, callingPackage, callingFeatureId,
3401 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003402 return -1;
3403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 final Phone phone = getPhone(subId);
3408 if (phone != null) {
3409 return phone.getCdmaEriIconMode();
3410 } else {
3411 return -1;
3412 }
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 }
3417
3418 /**
3419 * Returns the CDMA ERI text,
3420 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003421 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003422 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3423 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3424 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003425 }
3426
Sanket Padawe356d7632015-06-22 14:03:32 -07003427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003428 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3429 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003431 mApp, subId, callingPackage, callingFeatureId,
3432 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003433 return null;
3434 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 final Phone phone = getPhone(subId);
3439 if (phone != null) {
3440 return phone.getCdmaEriText();
3441 } else {
3442 return null;
3443 }
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 }
3448
3449 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003450 * Returns the CDMA MDN.
3451 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003452 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003453 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3455 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 return phone.getLine1Number();
3462 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 return null;
3465 }
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003468 }
3469 }
3470
3471 /**
3472 * Returns the CDMA MIN.
3473 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003474 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003475 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3477 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 final Phone phone = getPhone(subId);
3482 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3483 return phone.getCdmaMin();
3484 } else {
3485 return null;
3486 }
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003489 }
3490 }
3491
Hall Liud892bec2018-11-30 14:51:45 -08003492 @Override
3493 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3494 INumberVerificationCallback callback, String callingPackage) {
3495 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3496 != PERMISSION_GRANTED) {
3497 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3498 }
3499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3500
3501 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3502 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003503 throw new SecurityException("Calling package must be configured in the device config: "
3504 + "calling package: " + callingPackage
3505 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003506 }
3507
3508 if (range == null) {
3509 throw new NullPointerException("Range must be non-null");
3510 }
3511
3512 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003513 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003514
3515 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3516 }
3517
Junda Liuca05d5d2014-08-14 22:36:34 -07003518 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003519 * Returns true if CDMA provisioning needs to run.
3520 */
3521 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 final long identity = Binder.clearCallingIdentity();
3523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003524 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003528 }
3529
3530 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003531 * Sets the voice mail number of a given subId.
3532 */
3533 @Override
3534 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003535 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3536 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537
3538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3541 new Pair<String, String>(alphaTag, number), new Integer(subId));
3542 return success;
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003546 }
3547
Ta-wei Yen87c49842016-05-13 21:19:52 -07003548 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003549 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003551 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3552 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003553 if (!TextUtils.equals(callingPackage, systemDialer)) {
3554 throw new SecurityException("caller must be system dialer");
3555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3560 if (phoneAccountHandle == null) {
3561 return null;
3562 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003563 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 } finally {
3565 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003566 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003567 }
3568
3569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003570 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3571 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003574 mApp, subId, callingPackage, callingFeatureId,
3575 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003576 return null;
3577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003579 final long identity = Binder.clearCallingIdentity();
3580 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003581 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003582 } finally {
3583 Binder.restoreCallingIdentity(identity);
3584 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003585 }
3586
3587 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003588 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3589 VisualVoicemailSmsFilterSettings settings) {
3590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591
3592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596 } finally {
3597 Binder.restoreCallingIdentity(identity);
3598 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003599 }
3600
3601 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003602 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
3605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003612 }
3613
3614 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003615 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3616 String callingPackage, int subId) {
3617 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 } finally {
3624 Binder.restoreCallingIdentity(identity);
3625 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003626 }
3627
3628 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003629 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631
3632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003639 }
3640
3641 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003642 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3643 String callingAttributionTag, int subId, String number, int port, String text,
3644 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003645 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003646 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003647 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003648 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003649 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3650 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003651 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003652
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003653 /**
fionaxu0152e512016-11-14 13:36:14 -08003654 * Sets the voice activation state of a given subId.
3655 */
3656 @Override
3657 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3659 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 final Phone phone = getPhone(subId);
3664 if (phone != null) {
3665 phone.setVoiceActivationState(activationState);
3666 } else {
3667 loge("setVoiceActivationState fails with invalid subId: " + subId);
3668 }
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003671 }
3672 }
3673
3674 /**
3675 * Sets the data activation state of a given subId.
3676 */
3677 @Override
3678 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3680 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681
3682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 final Phone phone = getPhone(subId);
3685 if (phone != null) {
3686 phone.setDataActivationState(activationState);
3687 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003688 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003692 }
3693 }
3694
3695 /**
3696 * Returns the voice activation state of a given subId.
3697 */
3698 @Override
3699 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701
fionaxu0152e512016-11-14 13:36:14 -08003702 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 if (phone != null) {
3706 return phone.getVoiceActivationState();
3707 } else {
3708 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3709 }
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003712 }
3713 }
3714
3715 /**
3716 * Returns the data activation state of a given subId.
3717 */
3718 @Override
3719 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721
fionaxu0152e512016-11-14 13:36:14 -08003722 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 if (phone != null) {
3726 return phone.getDataActivationState();
3727 } else {
3728 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3729 }
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003732 }
3733 }
3734
3735 /**
Wink Saville36469e72014-06-11 15:17:00 -07003736 * Returns the unread count of voicemails for a subId
3737 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003738 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003739 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3740 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003742 mApp, subId, callingPackage, callingFeatureId,
3743 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003744 return 0;
3745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 final Phone phone = getPhone(subId);
3749 if (phone != null) {
3750 return phone.getVoiceMessageCount();
3751 } else {
3752 return 0;
3753 }
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003757 }
3758
3759 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003760 * returns true, if the device is in a state where both voice and data
3761 * are supported simultaneously. This can change based on location or network condition.
3762 */
3763 @Override
3764 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 final Phone phone = getPhone(subId);
3768 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003772 }
3773
3774 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003775 * Send the dialer code if called from the current default dialer or the caller has
3776 * carrier privilege.
3777 * @param inputCode The dialer code to send
3778 */
3779 @Override
3780 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003781 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003783 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3784 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003785 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003786 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003789
3790 final long identity = Binder.clearCallingIdentity();
3791 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
fionaxu235cc5e2017-03-06 22:25:57 -08003796 }
3797
Pengquan Menga1bb6272018-09-06 09:59:22 -07003798 @Override
3799 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003801 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003802 mApp, subId, "getNetworkSelectionMode");
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 if (!isActiveSubscription(subId)) {
3806 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3807 }
3808 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003811 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003812 }
3813
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003815 public boolean isInEmergencySmsMode() {
3816 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3817 final long identity = Binder.clearCallingIdentity();
3818 try {
3819 for (Phone phone : PhoneFactory.getPhones()) {
3820 if (phone.isInEmergencySmsMode()) {
3821 return true;
3822 }
3823 }
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
3826 }
3827 return false;
3828 }
3829
shilu366312e2019-12-17 09:28:10 -08003830 /**
3831 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3832 * @param subId The subscription to use to check the configuration.
3833 * @param c The callback that will be used to send the result.
3834 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003835 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003836 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3837 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003838 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003839 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003840
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003841 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3842 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3843 "IMS not available on device.");
3844 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 final long token = Binder.clearCallingIdentity();
3846 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003848 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003850 } catch (ImsException e) {
3851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 } finally {
3853 Binder.restoreCallingIdentity(token);
3854 }
3855 }
3856
shilu366312e2019-12-17 09:28:10 -08003857 /**
3858 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3859 * @param subId The subscription to use to check the configuration.
3860 * @param c The callback that will be used to send the result.
3861 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003863 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003864 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003865 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003866 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3867 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3868 }
Meng Wangafbc5852019-09-19 17:37:13 -07003869 final long token = Binder.clearCallingIdentity();
3870 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003871 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003872 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3873 .removeRegistrationCallbackForSubscription(c, subId);
3874 } catch (ImsException e) {
3875 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3876 + "is inactive, ignoring unregister.");
3877 // If the subscription is no longer active, just return, since the callback
3878 // will already have been removed internally.
3879 } finally {
3880 Binder.restoreCallingIdentity(token);
3881 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 }
3883
Brad Ebingera34a6c22019-10-22 17:36:18 -07003884 /**
3885 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3886 */
3887 @Override
3888 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3889 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3890 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3892 "IMS not available on device.");
3893 }
3894 final long token = Binder.clearCallingIdentity();
3895 try {
3896 Phone phone = getPhone(subId);
3897 if (phone == null) {
3898 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3899 + subId + "'");
3900 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3901 }
3902 phone.getImsRegistrationState(regState -> {
3903 try {
3904 consumer.accept((regState == null)
3905 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3906 } catch (RemoteException e) {
3907 // Ignore if the remote process is no longer available to call back.
3908 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3909 }
3910 });
3911 } finally {
3912 Binder.restoreCallingIdentity(token);
3913 }
3914 }
3915
3916 /**
3917 * Get the transport type for the IMS service registration state.
3918 */
3919 @Override
3920 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003922 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003923 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3925 "IMS not available on device.");
3926 }
3927 final long token = Binder.clearCallingIdentity();
3928 try {
3929 Phone phone = getPhone(subId);
3930 if (phone == null) {
3931 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3932 + subId + "'");
3933 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3934 }
3935 phone.getImsRegistrationTech(regTech -> {
3936 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3937 int regTechConverted = (regTech == null)
3938 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3939 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3940 regTechConverted);
3941 try {
3942 consumer.accept(regTechConverted);
3943 } catch (RemoteException e) {
3944 // Ignore if the remote process is no longer available to call back.
3945 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3946 }
3947 });
3948 } finally {
3949 Binder.restoreCallingIdentity(token);
3950 }
3951 }
3952
shilu366312e2019-12-17 09:28:10 -08003953 /**
3954 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3955 * @param subId The subscription to use to check the configuration.
3956 * @param c The callback that will be used to send the result.
3957 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003959 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3960 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003961 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003962 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003963 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3965 "IMS not available on device.");
3966 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3968 final long token = Binder.clearCallingIdentity();
3969 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003972 } catch (ImsException e) {
3973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 } finally {
3975 Binder.restoreCallingIdentity(token);
3976 }
3977 }
3978
shilu366312e2019-12-17 09:28:10 -08003979 /**
3980 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3981 * @param subId The subscription to use to check the configuration.
3982 * @param c The callback that will be used to send the result.
3983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003985 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003986 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3990 }
Meng Wangafbc5852019-09-19 17:37:13 -07003991
3992 final long token = Binder.clearCallingIdentity();
3993 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003994 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003996 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003997 } catch (ImsException e) {
3998 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3999 + "is inactive, ignoring unregister.");
4000 // If the subscription is no longer active, just return, since the callback
4001 // will already have been removed internally.
4002 } finally {
4003 Binder.restoreCallingIdentity(token);
4004 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 }
4006
4007 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004008 public boolean isCapable(int subId, int capability, int regTech) {
4009 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4011 final long token = Binder.clearCallingIdentity();
4012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004015 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4017 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004018 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004019 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4020 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
4024 }
4025
4026 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004027 public boolean isAvailable(int subId, int capability, int regTech) {
4028 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 final long token = Binder.clearCallingIdentity();
4030 try {
4031 Phone phone = getPhone(subId);
4032 if (phone == null) return false;
4033 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004034 } catch (com.android.ims.ImsException e) {
4035 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4036 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(token);
4039 }
4040 }
4041
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004042 /**
4043 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4044 * subscription.
4045 * @param subId The subscription to use to check the configuration.
4046 * @param callback The callback that will be used to send the result.
4047 * @param capability The MmTelFeature capability that will be used to send the result.
4048 * @param transportType The transport type of the MmTelFeature capability.
4049 */
4050 @Override
4051 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4052 int transportType) {
4053 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4056 "IMS not available on device.");
4057 }
4058 final long token = Binder.clearCallingIdentity();
4059 try {
4060 int slotId = getSlotIndex(subId);
4061 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4062 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4063 + subId + "'");
4064 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4065 }
4066 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4067 transportType, aBoolean -> {
4068 try {
4069 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4070 } catch (RemoteException e) {
4071 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4072 + "running. Ignore");
4073 }
4074 });
4075 } finally {
4076 Binder.restoreCallingIdentity(token);
4077 }
4078 }
4079
shilu366312e2019-12-17 09:28:10 -08004080 /**
4081 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4082 * @param subId The subscription to use to check the configuration.
4083 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 @Override
4085 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004086 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004087 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004088
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4090 final long token = Binder.clearCallingIdentity();
4091 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004092 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004094 } catch (ImsException e) {
4095 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 } finally {
4097 Binder.restoreCallingIdentity(token);
4098 }
4099 }
4100
4101 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004102 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004104 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004108 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004110 } catch (ImsException e) {
4111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 } finally {
4113 Binder.restoreCallingIdentity(identity);
4114 }
4115 }
4116
shilu366312e2019-12-17 09:28:10 -08004117 /**
4118 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4119 * @param subId The subscription to use to check the configuration.
4120 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004122 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004123 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004124 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 final long identity = Binder.clearCallingIdentity();
4126 try {
4127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4129 } catch (ImsException e) {
4130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
4134 }
4135
4136 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004137 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004139 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (ImsException e) {
4145 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
4149 }
4150
shilu366312e2019-12-17 09:28:10 -08004151 /**
4152 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4153 * @param subId The subscription to use to check the configuration.
4154 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 @Override
4156 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004157 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004158 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (ImsException e) {
4165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
4171 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004172 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004174 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004178 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (ImsException e) {
4180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
4184 }
4185
shilu366312e2019-12-17 09:28:10 -08004186 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004187 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4188 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4189 * @param subId The subscription to use to check the configuration.
4190 */
4191 @Override
4192 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004193 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004194 mApp, subId, "isCrossSimCallingEnabledByUser");
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4198 return ImsManager.getInstance(mApp,
4199 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4200 } catch (ImsException e) {
4201 throw new ServiceSpecificException(e.getCode());
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
4207 /**
4208 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4209 * Requires MODIFY_PHONE_STATE permission.
4210 * @param subId The subscription to use to check the configuration.
4211 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4212 * false otherwise
4213 */
4214 @Override
4215 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4217 "setCrossSimCallingEnabled");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4221 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4222 .setCrossSimCallingEnabled(isEnabled);
4223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
4230 /**
shilu366312e2019-12-17 09:28:10 -08004231 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4232 * @param subId The subscription to use to check the configuration.
4233 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004235
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004237 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004238 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 final long identity = Binder.clearCallingIdentity();
4240 try {
4241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004242 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 } catch (ImsException e) {
4245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
4251 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004252 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004254 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 final long identity = Binder.clearCallingIdentity();
4256 try {
4257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004258 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004260 } catch (ImsException e) {
4261 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
4265 }
4266
4267 @Override
4268 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4270 "setVoWiFiNonPersistent");
4271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004274 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004275 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004276 } catch (ImsException e) {
4277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 } finally {
4279 Binder.restoreCallingIdentity(identity);
4280 }
4281 }
4282
shilu366312e2019-12-17 09:28:10 -08004283 /**
4284 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4285 * @param subId The subscription to use to check the configuration.
4286 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 @Override
4288 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004289 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004290 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301 }
4302
4303 @Override
4304 public void setVoWiFiModeSetting(int subId, int mode) {
4305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4306 "setVoWiFiModeSetting");
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004310 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004312 } catch (ImsException e) {
4313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 }
4318
4319 @Override
4320 public int getVoWiFiRoamingModeSetting(int subId) {
4321 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
4324 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004325 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004327 } catch (ImsException e) {
4328 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
4332 }
4333
4334 @Override
4335 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4337 "setVoWiFiRoamingModeSetting");
4338 final long identity = Binder.clearCallingIdentity();
4339 try {
4340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004341 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004342 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004343 } catch (ImsException e) {
4344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
4350 @Override
4351 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4353 "setRttCapabilityEnabled");
4354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
shilu366312e2019-12-17 09:28:10 -08004365 /**
4366 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4367 * @param subId The subscription to use to check the configuration.
4368 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 @Override
4370 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004371 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004372 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004376 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
4379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004385 @Override
4386 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4387 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004390 if (!isImsAvailableOnDevice()) {
4391 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4392 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004393 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004395 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004396 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (ImsException e) {
4398 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403
4404 @Override
4405 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4406 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4407 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004408 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4409 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4410 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004411 try {
4412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004413 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004414 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004416 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4417 + "is inactive, ignoring unregister.");
4418 // If the subscription is no longer active, just return, since the callback will already
4419 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
4423 }
4424
allenwtsu99c623b2020-01-03 18:24:23 +08004425
4426 private void checkModifyPhoneStatePermission(int subId, String message) {
4427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4428 message);
4429 }
4430
4431 private boolean isImsProvisioningRequired(int subId, int capability,
4432 boolean isMmtelCapability) {
4433 Phone phone = getPhone(subId);
4434 if (phone == null) {
4435 loge("phone instance null for subid " + subId);
4436 return false;
4437 }
4438 if (isMmtelCapability) {
4439 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4440 return false;
4441 }
4442 } else {
4443 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4444 return false;
4445 }
4446 }
4447 return true;
4448 }
4449
4450 @Override
4451 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4452 boolean isProvisioned) {
4453 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4454
4455 final long identity = Binder.clearCallingIdentity();
4456 try {
4457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4458 if (!isImsProvisioningRequired(subId, capability, false)) {
4459 return;
4460 }
4461
4462 // this capability requires provisioning, route to the correct API.
4463 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4464 switch (capability) {
4465 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4466 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4467 ims.setEabProvisioned(isProvisioned);
4468 break;
4469 default: {
4470 throw new IllegalArgumentException("Tried to set provisioning for "
4471 + "rcs capability '" + capability + "', which does not require "
4472 + "provisioning.");
4473 }
4474 }
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
4478
4479 }
4480
4481
4482 @Override
4483 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4484 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4488 if (!isImsProvisioningRequired(subId, capability, false)) {
4489 return true;
4490 }
4491
4492 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4493 switch (capability) {
4494 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4495 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4496 return ims.isEabProvisionedOnDevice();
4497
4498 default: {
4499 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4500 + "capability '" + capability + "', which does not require "
4501 + "provisioning.");
4502 }
4503 }
4504
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004510 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004511 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4512 boolean isProvisioned) {
4513 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004514 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4515 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4516 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4518 }
allenwtsu99c623b2020-01-03 18:24:23 +08004519 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004523 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004524 return;
4525 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004526 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4527 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4528 loge("setImsProvisioningStatusForCapability: called for technology that does "
4529 + "not support provisioning - " + tech);
4530 return;
4531 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004532
4533 // this capability requires provisioning, route to the correct API.
4534 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4535 switch (capability) {
4536 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4537 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4538 ims.setVolteProvisioned(isProvisioned);
4539 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4540 ims.setWfcProvisioned(isProvisioned);
4541 }
4542 break;
4543 }
4544 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4545 // There is currently no difference in VT provisioning type.
4546 ims.setVtProvisioned(isProvisioned);
4547 break;
4548 }
4549 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4550 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4551 // change the capability of the feature instead if needed.
4552 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4553 == isProvisioned) {
4554 // No change in provisioning.
4555 return;
4556 }
4557 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4558 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004559 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004560 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004561 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4562 + ", Exception" + e.getMessage());
4563 }
4564 break;
4565 }
4566 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004567 throw new IllegalArgumentException("Tried to set provisioning for "
4568 + "MmTel capability '" + capability + "', which does not require "
4569 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004570 }
4571 }
4572
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
4576 }
4577
4578 @Override
4579 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4580 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004581 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4582 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4583 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004584 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4585 }
4586 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
4589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004590 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 return true;
4592 }
4593
Brad Ebinger0d79c572021-04-17 15:20:49 -07004594 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4595 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4596 loge("getImsProvisioningStatusForCapability: called for technology that does "
4597 + "not support provisioning - " + tech);
4598 return true;
4599 }
4600
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004601 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4602 switch (capability) {
4603 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4604 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4605 return ims.isVolteProvisionedOnDevice();
4606 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4607 return ims.isWfcProvisionedOnDevice();
4608 }
4609 // This should never happen, since we are checking tech above to make sure it
4610 // is either LTE or IWLAN.
4611 throw new IllegalArgumentException("Invalid radio technology for voice "
4612 + "capability.");
4613 }
4614 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4615 // There is currently no difference in VT provisioning type.
4616 return ims.isVtProvisionedOnDevice();
4617 }
4618 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4619 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4620 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4621 }
4622 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004623 throw new IllegalArgumentException(
4624 "Tried to get provisioning for MmTel capability '" + capability
4625 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 }
4627 }
4628
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
4632 }
4633
4634 @Override
4635 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4636 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4637 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4638 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4639 }
4640 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4641 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4642 return (provisionedBits & capability) > 0;
4643 }
4644
4645 @Override
4646 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4647 boolean isProvisioned) {
4648 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4649 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4650 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4651 }
4652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4653 "setProvisioningStatusForCapability");
4654 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4655 // If the current provisioning status for capability already matches isProvisioned,
4656 // do nothing.
4657 if (((provisionedBits & capability) > 0) == isProvisioned) {
4658 return;
4659 }
4660 if (isProvisioned) {
4661 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4662 } else {
4663 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4664 }
4665 }
4666
4667 /**
4668 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4669 * technology. The bitfield should mirror the bitfield defined by
4670 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4671 */
4672 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4673 String key = getMmTelProvisioningKey(subId, tech);
4674 // Default is no capabilities are provisioned.
4675 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4676 }
4677
4678 /**
4679 * Sets the MmTel capability provisioning bitfield (defined by
4680 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4681 * technology specified.
4682 *
4683 * Note: This is a synchronous command and should not be called on UI thread.
4684 */
4685 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4686 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4687 String key = getMmTelProvisioningKey(subId, tech);
4688 editor.putInt(key, newField);
4689 editor.commit();
4690 }
4691
4692 private static String getMmTelProvisioningKey(int subId, int tech) {
4693 // resulting key is provision_ims_mmtel_{subId}_{tech}
4694 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4695 }
4696
4697 /**
4698 * Query CarrierConfig to see if the specified capability requires provisioning for the
4699 * carrier associated with the subscription id.
4700 */
4701 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4702 int capability) {
4703 CarrierConfigManager configManager = new CarrierConfigManager(context);
4704 PersistableBundle c = configManager.getConfigForSubId(subId);
4705 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004706 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4708 false);
4709 boolean requireVoiceVtProvisioning = c.getBoolean(
4710 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4711
4712 // First check to make sure that the capability requires provisioning.
4713 switch (capability) {
4714 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4715 // intentional fallthrough
4716 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4717 if (requireVoiceVtProvisioning) {
4718 // Voice and Video requires provisioning
4719 return true;
4720 }
4721 break;
4722 }
4723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4724 if (requireUtProvisioning) {
4725 // UT requires provisioning
4726 return true;
4727 }
4728 break;
4729 }
4730 }
4731 return false;
4732 }
4733
allenwtsu99c623b2020-01-03 18:24:23 +08004734 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4735 int capability) {
4736 CarrierConfigManager configManager = new CarrierConfigManager(context);
4737 PersistableBundle c = configManager.getConfigForSubId(subId);
4738
4739 boolean requireRcsProvisioning = c.getBoolean(
4740 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4741
4742 // First check to make sure that the capability requires provisioning.
4743 switch (capability) {
4744 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4745 // intentional fallthrough
4746 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4747 if (requireRcsProvisioning) {
4748 // OPTION or PRESENCE requires provisioning
4749 return true;
4750 }
4751 break;
4752 }
4753 }
4754 return false;
4755 }
4756
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004757 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004758 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4760 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4761 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004762 enforceReadPrivilegedPermission("getImsProvisioningInt");
4763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 int slotId = getSlotIndex(subId);
4767 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4768 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4769 + subId + "' for key:" + key);
4770 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4771 }
calvinpanb5a34062021-02-08 19:59:36 +08004772 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004773 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4775 + subId + "' for key:" + key);
4776 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004777 } finally {
4778 Binder.restoreCallingIdentity(identity);
4779 }
4780 }
4781
4782 @Override
4783 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004784 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4785 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4786 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004787 enforceReadPrivilegedPermission("getImsProvisioningString");
4788 final long identity = Binder.clearCallingIdentity();
4789 try {
4790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 int slotId = getSlotIndex(subId);
4792 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4793 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4794 + subId + "' for key:" + key);
4795 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4796 }
calvinpanb5a34062021-02-08 19:59:36 +08004797 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004798 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004799 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4800 + subId + "' for key:" + key);
4801 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
4805 }
4806
4807 @Override
4808 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4810 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4811 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4813 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004817 int slotId = getSlotIndex(subId);
4818 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4819 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4820 + subId + "' for key:" + key);
4821 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4822 }
calvinpanb5a34062021-02-08 19:59:36 +08004823 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4824 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004826 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004827 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
4831 }
4832
4833 @Override
4834 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4836 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4837 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 int slotId = getSlotIndex(subId);
4844 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4845 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4846 + subId + "' for key:" + key);
4847 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4848 }
calvinpanb5a34062021-02-08 19:59:36 +08004849 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4850 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004852 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
4857 }
4858
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004859 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004860 int slotId = SubscriptionManager.getSlotIndex(subId);
4861 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004862 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4863 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004864 }
4865 return slotId;
4866 }
4867
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004868 private int getSlotIndex(int subId) {
4869 int slotId = SubscriptionManager.getSlotIndex(subId);
4870 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4871 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4872 }
4873 return slotId;
4874 }
4875
Wink Saville36469e72014-06-11 15:17:00 -07004876 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004877 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004878 */
4879 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004880 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4881 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004882 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004883 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004884 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004885 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004886 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004887 mApp, subId, callingPackage, callingFeatureId,
4888 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004889 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4890 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 final Phone phone = getPhone(subId);
4895 if (phone != null) {
4896 return phone.getServiceState().getDataNetworkType();
4897 } else {
4898 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4899 }
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004903 }
4904
4905 /**
4906 * Returns the data network type
4907 */
4908 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004909 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004910 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4911 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004912 }
4913
4914 /**
4915 * Returns the data network type for a subId
4916 */
4917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004918 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4919 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004921 mApp, subId, callingPackage, callingFeatureId,
4922 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004923 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4924 }
4925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 final Phone phone = getPhone(subId);
4929 if (phone != null) {
4930 return phone.getServiceState().getDataNetworkType();
4931 } else {
4932 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4933 }
4934 } finally {
4935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004937 }
4938
4939 /**
Wink Saville36469e72014-06-11 15:17:00 -07004940 * Returns the Voice network type for a subId
4941 */
4942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004943 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4944 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004946 mApp, subId, callingPackage, callingFeatureId,
4947 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004948 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4949 }
4950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 final Phone phone = getPhone(subId);
4954 if (phone != null) {
4955 return phone.getServiceState().getVoiceNetworkType();
4956 } else {
4957 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4958 }
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004962 }
4963
4964 /**
4965 * @return true if a ICC card is present
4966 */
4967 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004968 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004969 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4970 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004971 }
4972
4973 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004974 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004975 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004976 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004977 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 final long identity = Binder.clearCallingIdentity();
4979 try {
4980 final Phone phone = PhoneFactory.getPhone(slotIndex);
4981 if (phone != null) {
4982 return phone.getIccCard().hasIccCard();
4983 } else {
4984 return false;
4985 }
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004989 }
4990
4991 /**
4992 * Return if the current radio is LTE on CDMA. This
4993 * is a tri-state return value as for a period of time
4994 * the mode may be unknown.
4995 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004996 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004997 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004998 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004999 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005000 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005001 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5002 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5003 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005004 }
5005
Sanket Padawe356d7632015-06-22 14:03:32 -07005006 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005007 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5008 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005009 try {
5010 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5011 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005012 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5013 }
5014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 final long identity = Binder.clearCallingIdentity();
5016 try {
5017 final Phone phone = getPhone(subId);
5018 if (phone == null) {
5019 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5020 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005021 return TelephonyProperties.lte_on_cdma_device()
5022 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 }
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005026 }
Wink Saville36469e72014-06-11 15:17:00 -07005027 }
5028
Wink Saville36469e72014-06-11 15:17:00 -07005029 /**
5030 * {@hide}
5031 * Returns Default subId, 0 in the case of single standby.
5032 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005033 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005034 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005035 }
5036
Shishir Agrawala9f32182016-04-12 12:00:16 -07005037 private int getSlotForDefaultSubscription() {
5038 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5039 }
5040
Wink Savilleb564aae2014-10-23 10:18:09 -07005041 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005042 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005043 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005044
Pengquan Menge92a50d2018-09-21 15:54:48 -07005045 private boolean isActiveSubscription(int subId) {
5046 return mSubscriptionController.isActiveSubId(subId);
5047 }
5048
Ihab Awadf2177b72013-11-25 13:33:23 -08005049 /**
5050 * @see android.telephony.TelephonyManager.WifiCallingChoices
5051 */
5052 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005055 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005056 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5057 getWhenToMakeWifiCallsDefaultPreference());
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005061 }
5062
5063 /**
5064 * @see android.telephony.TelephonyManager.WifiCallingChoices
5065 */
5066 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005070 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005075 }
5076
Sailesh Nepald1e68152013-12-12 19:08:02 -08005077 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005078 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005079 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005080 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005081
Jordan Liu4c733742019-02-28 12:03:40 -08005082 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5083 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5084 if (phoneId == -1) {
5085 throw new IllegalArgumentException("Given slot index: " + slotIndex
5086 + " does not correspond to an active phone");
5087 }
5088 return PhoneFactory.getPhone(phoneId);
5089 }
5090
Shishir Agrawal566b7612013-10-28 14:41:00 -07005091 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005092 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5093 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5095 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005097 if (DBG) {
5098 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5099 }
5100 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5101 p2);
5102 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005103
Jordan Liu4c733742019-02-28 12:03:40 -08005104
5105 @Override
5106 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5107 int slotIndex, String callingPackage, String aid, int p2) {
5108 enforceModifyPermission();
5109 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5110 if (DBG) {
5111 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5112 }
5113 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5114 callingPackage, aid, p2);
5115 }
5116
5117 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5118 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 if (TextUtils.equals(ISDR_AID, aid)) {
5122 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005123 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5124 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 if (bestComponent == null
5126 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5127 loge("The calling package is not allowed to access ISD-R.");
5128 throw new SecurityException(
5129 "The calling package is not allowed to access ISD-R.");
5130 }
Derek Tan740e1672017-06-27 14:56:27 -07005131 }
Derek Tan740e1672017-06-27 14:56:27 -07005132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005134 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5135 null /* workSource */);
5136 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 return response;
5138 } finally {
5139 Binder.restoreCallingIdentity(identity);
5140 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005141 }
5142
5143 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005144 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5146 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005147 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5148 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5149 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005150
Jordan Liu4c733742019-02-28 12:03:40 -08005151 @Override
5152 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5153 enforceModifyPermission();
5154 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5155 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5156 channel);
5157 }
5158
5159 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 final long identity = Binder.clearCallingIdentity();
5161 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 if (channel < 0) {
5163 return false;
5164 }
Jordan Liu4c733742019-02-28 12:03:40 -08005165 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5166 null /* workSource */);
5167 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 return success;
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005171 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005172 }
5173
5174 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005175 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005176 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5178 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005179 if (DBG) {
5180 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5181 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5182 + p3 + " data=" + data);
5183 }
5184 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5185 command, p1, p2, p3, data);
5186 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005187
Jordan Liu4c733742019-02-28 12:03:40 -08005188 @Override
5189 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5190 int command, int p1, int p2, int p3, String data) {
5191 enforceModifyPermission();
5192 if (DBG) {
5193 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5194 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5195 + p3 + " data=" + data);
5196 }
5197 return iccTransmitApduLogicalChannelWithPermission(
5198 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5199 data);
5200 }
5201
5202 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5203 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 final long identity = Binder.clearCallingIdentity();
5205 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005206 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 return "";
5208 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005211 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5212 null /* workSource */);
5213 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005214
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 // Append the returned status code to the end of the response payload.
5216 String s = Integer.toHexString(
5217 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5218 if (response.payload != null) {
5219 s = IccUtils.bytesToHexString(response.payload) + s;
5220 }
5221 return s;
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005224 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005225 }
Jake Hambye994d462014-02-03 13:10:13 -08005226
Evan Charltonc66da362014-05-16 14:06:40 -07005227 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005228 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5229 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5231 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005233 if (DBG) {
5234 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5235 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5236 }
5237 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5238 cla, command, p1, p2, p3, data);
5239 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005240
Jordan Liu4c733742019-02-28 12:03:40 -08005241 @Override
5242 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5243 int command, int p1, int p2, int p3, String data) {
5244 enforceModifyPermission();
5245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5246 if (DBG) {
5247 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5248 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5249 + " data=" + data);
5250 }
5251
5252 return iccTransmitApduBasicChannelWithPermission(
5253 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5254 p2, p3, data);
5255 }
5256
5257 // open APDU basic channel assuming the caller has sufficient permissions
5258 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5259 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260 final long identity = Binder.clearCallingIdentity();
5261 try {
5262 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5263 && TextUtils.equals(ISDR_AID, data)) {
5264 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005265 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5266 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 if (bestComponent == null
5268 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5269 loge("The calling package is not allowed to select ISD-R.");
5270 throw new SecurityException(
5271 "The calling package is not allowed to select ISD-R.");
5272 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005273 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005276 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5277 null /* workSource */);
5278 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 // Append the returned status code to the end of the response payload.
5281 String s = Integer.toHexString(
5282 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5283 if (response.payload != null) {
5284 s = IccUtils.bytesToHexString(response.payload) + s;
5285 }
5286 return s;
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005289 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005290 }
5291
5292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005293 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005294 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5296 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 if (DBG) {
5301 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5302 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5303 }
5304
5305 IccIoResult response =
5306 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5307 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5308 subId);
5309
5310 if (DBG) {
5311 log("Exchange SIM_IO [R]" + response);
5312 }
5313
5314 byte[] result = null;
5315 int length = 2;
5316 if (response.payload != null) {
5317 length = 2 + response.payload.length;
5318 result = new byte[length];
5319 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5320 } else {
5321 result = new byte[length];
5322 }
5323
5324 result[length - 1] = (byte) response.sw2;
5325 result[length - 2] = (byte) response.sw1;
5326 return result;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005329 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005330 }
5331
Nathan Haroldb3014052017-01-25 15:57:32 -08005332 /**
5333 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5334 * on a particular subscription
5335 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005336 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5337 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005339 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005340 return null;
5341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 if (appType != TelephonyManager.APPTYPE_USIM
5346 && appType != TelephonyManager.APPTYPE_SIM) {
5347 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5348 return null;
5349 }
5350 Object response = sendRequest(
5351 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5352 if (response instanceof String[]) {
5353 return (String[]) response;
5354 }
yincheng zhao2737e882019-09-06 17:06:54 -07005355 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005357 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 } finally {
5359 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005360 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005361 }
5362
yincheng zhao2737e882019-09-06 17:06:54 -07005363 /**
5364 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5365 * subscription.
5366 *
5367 * @param subId the id of the subscription.
5368 * @param appType the uicc app type, must be USIM or SIM.
5369 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5370 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005371 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005372 * @return number of fplmns that is successfully written to the SIM.
5373 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005374 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5375 String callingFeatureId) {
5376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5377 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005378 if (DBG) logv("no permissions for setForbiddenplmns");
5379 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5380 }
5381 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5382 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5383 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5384 }
5385 if (fplmns == null) {
5386 throw new IllegalArgumentException("Fplmn List provided is null");
5387 }
5388 for (String fplmn : fplmns) {
5389 if (!CellIdentity.isValidPlmn(fplmn)) {
5390 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5391 }
5392 }
5393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 Object response = sendRequest(
5396 CMD_SET_FORBIDDEN_PLMNS,
5397 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5398 subId);
5399 return (int) response;
5400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
5403 }
5404
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005405 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005406 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5408 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005409
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5413 if (response.payload == null) {
5414 return "";
5415 }
Evan Charltonc66da362014-05-16 14:06:40 -07005416
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 // Append the returned status code to the end of the response payload.
5418 String s = Integer.toHexString(
5419 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5420 s = IccUtils.bytesToHexString(response.payload) + s;
5421 return s;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Evan Charltonc66da362014-05-16 14:06:40 -07005425 }
5426
Jake Hambye994d462014-02-03 13:10:13 -08005427 /**
5428 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5429 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5430 *
5431 * @param itemID the ID of the item to read
5432 * @return the NV item as a String, or null on error.
5433 */
5434 @Override
5435 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005436 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5438 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439
5440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005443 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5445 return value;
5446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
Jake Hambye994d462014-02-03 13:10:13 -08005449 }
5450
5451 /**
5452 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5453 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5454 *
5455 * @param itemID the ID of the item to read
5456 * @param itemValue the value to write, as a String
5457 * @return true on success; false on any failure
5458 */
5459 @Override
5460 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005461 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5463 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5468 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005469 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5471 return success;
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
Jake Hambye994d462014-02-03 13:10:13 -08005475 }
5476
5477 /**
5478 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5479 * Used for device configuration by some CDMA operators.
5480 *
5481 * @param preferredRoamingList byte array containing the new PRL
5482 * @return true on success; false on any failure
5483 */
5484 @Override
5485 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5487 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5492 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5493 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5494 return success;
5495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Jake Hambye994d462014-02-03 13:10:13 -08005498 }
5499
5500 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005501 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005502 * Used for device configuration by some CDMA operators.
5503 *
chen xu6dac5ab2018-10-26 17:39:23 -07005504 * @param slotIndex - device slot.
5505 *
Jake Hambye994d462014-02-03 13:10:13 -08005506 * @return true on success; false on any failure
5507 */
5508 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005509 public boolean resetModemConfig(int slotIndex) {
5510 Phone phone = PhoneFactory.getPhone(slotIndex);
5511 if (phone != null) {
5512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5513 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514
chen xu6dac5ab2018-10-26 17:39:23 -07005515 final long identity = Binder.clearCallingIdentity();
5516 try {
5517 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5518 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5519 return success;
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 }
chen xu6dac5ab2018-10-26 17:39:23 -07005524 return false;
5525 }
5526
5527 /**
5528 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5529 *
5530 * @param slotIndex - device slot.
5531 *
5532 * @return true on success; false on any failure
5533 */
5534 @Override
5535 public boolean rebootModem(int slotIndex) {
5536 Phone phone = PhoneFactory.getPhone(slotIndex);
5537 if (phone != null) {
5538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5539 mApp, phone.getSubId(), "rebootModem");
5540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5544 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5545 return success;
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005551 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005552
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005553 public String[] getPcscfAddress(String apnType, String callingPackage,
5554 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005555 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5557 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005558 return new String[0];
5559 }
5560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 final long identity = Binder.clearCallingIdentity();
5562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005563 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Wink Saville36469e72014-06-11 15:17:00 -07005567 }
5568
Brad Ebinger51f743a2017-01-23 13:50:20 -08005569 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005570 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5571 * {@link #disableIms(int)}.
5572 * @param slotIndex device slot.
5573 */
5574 public void resetIms(int slotIndex) {
5575 enforceModifyPermission();
5576
5577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (mImsResolver == null) {
5580 // may happen if the does not support IMS.
5581 return;
5582 }
5583 mImsResolver.disableIms(slotIndex);
5584 mImsResolver.enableIms(slotIndex);
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
5588 }
5589
5590 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005591 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5592 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005593 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005594 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005600 // may happen if the device does not support IMS.
5601 return;
5602 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005603 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005607 }
5608
5609 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005610 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5611 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005612 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005613 public void disableIms(int slotId) {
5614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005618 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005619 // may happen if the device does not support IMS.
5620 return;
5621 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005622 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005626 }
5627
5628 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005629 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5630 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005631 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005632 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005633 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005638 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005639 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5640 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005641 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005642 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005646 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005647 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005648 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5649 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005650 @Override
5651 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005652 enforceModifyPermission();
5653
5654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005657 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
5661 }
5662
5663 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005664 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005665 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005666 */
5667 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005672 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005673 // may happen if the device does not support IMS.
5674 return null;
5675 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005676 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005680 }
5681
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005682 /**
5683 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005684 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005685 */
5686 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688
5689 final long identity = Binder.clearCallingIdentity();
5690 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005691 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005692 // may happen if the device does not support IMS.
5693 return null;
5694 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005695 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005699 }
5700
Brad Ebinger884c07b2018-02-15 16:17:40 -08005701 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005702 * Sets the ImsService Package Name that Telephony will bind to.
5703 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005704 * @param slotIndex the slot ID that the ImsService should bind for.
5705 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005706 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005707 * @param featureTypes An integer array of feature types associated with a packageName.
5708 * @param packageName The name of the package that the current configuration will be replaced
5709 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005710 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005711 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5713 int[] featureTypes, String packageName) {
5714 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5717 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 final long identity = Binder.clearCallingIdentity();
5721 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005722 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005723 // may happen if the device does not support IMS.
5724 return false;
5725 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005726 Map<Integer, String> featureConfig = new HashMap<>();
5727 for (int featureType : featureTypes) {
5728 featureConfig.put(featureType, packageName);
5729 }
5730 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5731 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005735 }
5736
5737 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005738 * Clears any carrier ImsService overrides for the slot index specified that were previously
5739 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5740 *
5741 * This should only be used for testing.
5742 *
5743 * @param slotIndex the slot ID that the ImsService should bind for.
5744 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5745 */
5746 @Override
5747 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5748 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5750 "clearCarrierImsServiceOverride");
5751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5752 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5753 "clearCarrierImsServiceOverride");
5754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 if (mImsResolver == null) {
5758 // may happen if the device does not support IMS.
5759 return false;
5760 }
5761 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
5765 }
5766
5767 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005769 *
5770 * @param slotId The slot that the ImsService is associated with.
5771 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5772 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005774 * @return the package name of the ImsService configuration.
5775 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005776 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5777 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005778 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005779 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005780 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5782 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 final long identity = Binder.clearCallingIdentity();
5785 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005786 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005787 // may happen if the device does not support IMS.
5788 return "";
5789 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005790 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005791 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5792 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005796 }
5797
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005798 /**
5799 * Get the MmTelFeature state associated with the requested subscription id.
5800 * @param subId The subscription that the MmTelFeature is associated with.
5801 * @param callback A callback with an integer containing the
5802 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5803 */
5804 @Override
5805 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5806 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5807 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5808 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5809 "IMS not available on device.");
5810 }
5811 final long token = Binder.clearCallingIdentity();
5812 try {
5813 int slotId = getSlotIndex(subId);
5814 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5815 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5816 + subId + "'");
5817 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5818 }
5819 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5820 try {
5821 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5822 } catch (RemoteException e) {
5823 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5824 + "Ignore");
5825 }
5826 });
5827 } finally {
5828 Binder.restoreCallingIdentity(token);
5829 }
5830 }
5831
Daniel Brightbb5840b2021-01-12 15:48:18 -08005832 /**
5833 * Sets the ims registration state on all valid {@link Phone}s.
5834 */
5835 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005840 // NOTE: Before S, this method only set the default phone.
5841 for (final Phone phone : PhoneFactory.getPhones()) {
5842 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5843 phone.setImsRegistrationState(registered);
5844 }
5845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Wink Saville36469e72014-06-11 15:17:00 -07005849 }
5850
5851 /**
Stuart Scott54788802015-03-30 13:18:01 -07005852 * Set the network selection mode to automatic.
5853 *
5854 */
5855 @Override
5856 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5858 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859
5860 final long identity = Binder.clearCallingIdentity();
5861 try {
shilufc958392020-01-20 11:36:01 -08005862 if (!isActiveSubscription(subId)) {
5863 return;
5864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005866 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5867 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
Stuart Scott54788802015-03-30 13:18:01 -07005871 }
5872
Jack Yud10cdd42020-09-28 20:28:01 -07005873 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005874 * Ask the radio to connect to the input network and change selection mode to manual.
5875 *
5876 * @param subId the id of the subscription.
5877 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5878 * the operator to attach to.
5879 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5880 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5881 * normal network selection next time.
5882 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005883 */
5884 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005885 public boolean setNetworkSelectionModeManual(
5886 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5888 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005889
5890 if (!isActiveSubscription(subId)) {
5891 return false;
5892 }
5893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 final long identity = Binder.clearCallingIdentity();
5895 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005896 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005898 if (DBG) {
5899 log("setNetworkSelectionModeManual: subId: " + subId
5900 + " operator: " + operatorInfo);
5901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005906 }
shilu84f6e8b2019-12-19 13:58:01 -08005907 /**
5908 * Get the manual network selection
5909 *
5910 * @param subId the id of the subscription.
5911 *
5912 * @return the previously saved user selected PLMN
5913 */
5914 @Override
5915 public String getManualNetworkSelectionPlmn(int subId) {
5916 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005917 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005918 mApp, subId, "getManualNetworkSelectionPlmn");
5919
5920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005923 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005924 }
5925
5926 final Phone phone = getPhone(subId);
5927 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005928 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005929 }
5930 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5931 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5932 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
5936 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005937
5938 /**
5939 * Scans for available networks.
5940 */
5941 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005942 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5945 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005946 LocationAccessPolicy.LocationPermissionResult locationResult =
5947 LocationAccessPolicy.checkLocationPermission(mApp,
5948 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5949 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005950 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005951 .setCallingPid(Binder.getCallingPid())
5952 .setCallingUid(Binder.getCallingUid())
5953 .setMethod("getCellNetworkScanResults")
5954 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005955 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5956 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005957 .build());
5958 switch (locationResult) {
5959 case DENIED_HARD:
5960 throw new SecurityException("Not allowed to access scan results -- location");
5961 case DENIED_SOFT:
5962 return null;
5963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964
Pengquan Menga1bb6272018-09-06 09:59:22 -07005965 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005966 try {
5967 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005968 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005973 }
5974
5975 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005976 * Get the call forwarding info, given the call forwarding reason.
5977 */
5978 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005979 public void getCallForwarding(int subId, int callForwardingReason,
5980 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005981 enforceReadPrivilegedPermission("getCallForwarding");
5982 long identity = Binder.clearCallingIdentity();
5983 try {
5984 if (DBG) {
5985 log("getCallForwarding: subId " + subId
5986 + " callForwardingReason" + callForwardingReason);
5987 }
Hall Liu27d24262020-09-18 19:04:59 -07005988
5989 Phone phone = getPhone(subId);
5990 if (phone == null) {
5991 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005992 callback.onError(
5993 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005994 } catch (RemoteException e) {
5995 // ignore
5996 }
5997 return;
5998 }
5999
6000 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6001 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6002 @Override
6003 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6004 try {
6005 callback.onCallForwardingInfoAvailable(info);
6006 } catch (RemoteException e) {
6007 // ignore
6008 }
6009 }
6010
6011 @Override
6012 public void onError(int error) {
6013 try {
6014 callback.onError(error);
6015 } catch (RemoteException e) {
6016 // ignore
6017 }
6018 }
6019 });
6020 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 }
6025
6026 /**
6027 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6028 * reason, the number to forward, and the timeout before the forwarding is attempted.
6029 */
6030 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006031 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6032 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006033 enforceModifyPermission();
6034 long identity = Binder.clearCallingIdentity();
6035 try {
6036 if (DBG) {
6037 log("setCallForwarding: subId " + subId
6038 + " callForwardingInfo" + callForwardingInfo);
6039 }
Hall Liu27d24262020-09-18 19:04:59 -07006040
6041 Phone phone = getPhone(subId);
6042 if (phone == null) {
6043 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006044 callback.accept(
6045 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006046 } catch (RemoteException e) {
6047 // ignore
6048 }
6049 return;
6050 }
6051
6052 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6053 FunctionalUtils.ignoreRemoteException(callback::accept));
6054
6055 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 /**
Hall Liu27d24262020-09-18 19:04:59 -07006062 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006063 */
6064 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006065 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006066 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006067 long identity = Binder.clearCallingIdentity();
6068 try {
Hall Liu27d24262020-09-18 19:04:59 -07006069 Phone phone = getPhone(subId);
6070 if (phone == null) {
6071 try {
6072 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6073 } catch (RemoteException e) {
6074 // ignore
6075 }
6076 return;
6077 }
SongFerngWang0e767992021-03-31 22:08:45 +08006078 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6079 PersistableBundle c = configManager.getConfigForSubId(subId);
6080 boolean requireUssd = c.getBoolean(
6081 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006082
Shuo Qian4a594052020-01-23 11:59:30 -08006083 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006084 if (requireUssd) {
6085 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6086 getSubscriptionCarrierId(subId));
6087 String newUssdCommand = "";
6088 try {
6089 newUssdCommand = carrierXmlParser.getFeature(
6090 CarrierXmlParser.FEATURE_CALL_WAITING)
6091 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6092 } catch (NullPointerException e) {
6093 loge("Failed to generate USSD number" + e);
6094 }
6095 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6096 mMainThreadHandler, callback, carrierXmlParser,
6097 CarrierXmlParser.SsEntry.SSAction.QUERY);
6098 final String ussdCommand = newUssdCommand;
6099 Executors.newSingleThreadExecutor().execute(() -> {
6100 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6101 });
6102 } else {
6103 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6104 callback::accept);
6105 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6106 }
Shuo Qian4a594052020-01-23 11:59:30 -08006107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
6111
6112 /**
Hall Liu27d24262020-09-18 19:04:59 -07006113 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006114 */
6115 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006116 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006117 enforceModifyPermission();
6118 long identity = Binder.clearCallingIdentity();
6119 try {
Hall Liu27d24262020-09-18 19:04:59 -07006120 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6121
6122 Phone phone = getPhone(subId);
6123 if (phone == null) {
6124 try {
6125 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6126 } catch (RemoteException e) {
6127 // ignore
6128 }
6129 return;
6130 }
6131
SongFerngWang0e767992021-03-31 22:08:45 +08006132 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6133 PersistableBundle c = configManager.getConfigForSubId(subId);
6134 boolean requireUssd = c.getBoolean(
6135 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006136
SongFerngWang0e767992021-03-31 22:08:45 +08006137 if (DBG) log("getCallWaitingStatus: subId " + subId);
6138 if (requireUssd) {
6139 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6140 getSubscriptionCarrierId(subId));
6141 CarrierXmlParser.SsEntry.SSAction ssAction =
6142 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6143 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6144 String newUssdCommand = "";
6145 try {
6146 newUssdCommand = carrierXmlParser.getFeature(
6147 CarrierXmlParser.FEATURE_CALL_WAITING)
6148 .makeCommand(ssAction, null);
6149 } catch (NullPointerException e) {
6150 loge("Failed to generate USSD number" + e);
6151 }
6152 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6153 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6154 final String ussdCommand = newUssdCommand;
6155 Executors.newSingleThreadExecutor().execute(() -> {
6156 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6157 });
6158 } else {
6159 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6160 FunctionalUtils.ignoreRemoteException(callback::accept));
6161
6162 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6163 }
Shuo Qian4a594052020-01-23 11:59:30 -08006164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
6167 }
6168
6169 /**
yinxub1bed742017-04-17 11:45:04 -07006170 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006171 *
yinxub1bed742017-04-17 11:45:04 -07006172 * @param subId id of the subscription
6173 * @param request contains the radio access networks with bands/channels to scan
6174 * @param messenger callback messenger for scan results or errors
6175 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006176 * @return the id of the requested scan which can be used to stop the scan.
6177 */
6178 @Override
6179 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006180 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6182 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006183 LocationAccessPolicy.LocationPermissionResult locationResult =
6184 LocationAccessPolicy.checkLocationPermission(mApp,
6185 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6186 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006187 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006188 .setCallingPid(Binder.getCallingPid())
6189 .setCallingUid(Binder.getCallingUid())
6190 .setMethod("requestNetworkScan")
6191 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6193 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006194 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006195 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006196 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6197 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006198 if (e != null) {
6199 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6200 throw e;
6201 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006202 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006203 return TelephonyScanManager.INVALID_SCAN_ID;
6204 }
6205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206 }
Hall Liu912dfd32019-04-25 14:02:26 -07006207 int callingUid = Binder.getCallingUid();
6208 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 return mNetworkScanRequestTracker.startNetworkScan(
6212 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006213 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
yinxu504e1392017-04-12 16:03:22 -07006217 }
6218
Hall Liub2ac8ef2019-02-28 15:56:23 -08006219 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006220 NetworkScanRequest request, int subId, String callingPackage) {
6221 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006222 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6223 boolean hasNetworkScanPermission =
6224 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6225 == PERMISSION_GRANTED;
6226
6227 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6228 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6229 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006230 }
6231
6232 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6233 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006234 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6235 return new SecurityException("Specific channels must not be"
6236 + " scanned without location access.");
6237 }
6238 }
6239 }
6240
Hall Liub2ac8ef2019-02-28 15:56:23 -08006241 return null;
6242 }
6243
yinxu504e1392017-04-12 16:03:22 -07006244 /**
6245 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006246 *
6247 * @param subId id of the subscription
6248 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006249 */
6250 @Override
6251 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6253 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254
Hall Liu912dfd32019-04-25 14:02:26 -07006255 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 final long identity = Binder.clearCallingIdentity();
6257 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006258 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
yinxu504e1392017-04-12 16:03:22 -07006262 }
6263
6264 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006265 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006266 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006267 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006268 */
6269 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006270 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006271 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006272 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006273 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006277 if (DBG) log("getAllowedNetworkTypesBitmask");
6278 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6279 int networkTypesBitmask = (result != null ? result[0] : -1);
6280 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6281 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006285 }
6286
6287 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006288 * Get the allowed network types for certain reason.
6289 *
6290 * @param subId the id of the subscription.
6291 * @param reason the reason the allowed network type change is taking place
6292 * @return the allowed network types.
6293 */
6294 @Override
6295 public long getAllowedNetworkTypesForReason(int subId,
6296 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006297 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006298 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
6305 }
6306
6307 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006308 * Enable/Disable E-UTRA-NR Dual Connectivity
6309 * @param subId subscription id of the sim card
6310 * @param nrDualConnectivityState expected NR dual connectivity state
6311 * This can be passed following states
6312 * <ol>
6313 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6314 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6315 * <li>Disable NR dual connectivity and force secondary cell to be released
6316 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6317 * </ol>
6318 * @return operation result.
6319 */
6320 @Override
6321 public int setNrDualConnectivityState(int subId,
6322 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006325 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006326 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6327 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6328 }
6329
Sooraj Sasindran37444802020-08-11 10:40:43 -07006330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6331 final long identity = Binder.clearCallingIdentity();
6332 try {
6333 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6334 nrDualConnectivityState, subId,
6335 workSource);
6336 if (DBG) log("enableNRDualConnectivity result: " + result);
6337 return result;
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
6341 }
6342
6343 /**
6344 * Is E-UTRA-NR Dual Connectivity enabled
6345 * @return true if dual connectivity is enabled else false
6346 */
6347 @Override
6348 public boolean isNrDualConnectivityEnabled(int subId) {
6349 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006350 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006351 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006352 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006353 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6354 return false;
6355 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6360 null, subId, workSource);
6361 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6362 return isEnabled;
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
6366 }
6367
6368 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006369 * Set the allowed network types of the device and
6370 * provide the reason triggering the allowed network change.
6371 *
6372 * @param subId the id of the subscription.
6373 * @param reason the reason the allowed network type change is taking place
6374 * @param allowedNetworkTypes the allowed network types.
6375 * @return true on success; false on any failure.
6376 */
6377 @Override
6378 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006379 @TelephonyManager.AllowedNetworkTypesReason int reason,
6380 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006383 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006384 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6385 return false;
6386 }
6387 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6388 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006389 return false;
6390 }
6391
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006392 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6393 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6394
6395
6396 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6397 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6398 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006399 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006400
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006401 final long identity = Binder.clearCallingIdentity();
6402 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006403 Boolean success = (Boolean) sendRequest(
6404 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6405 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6406
6407 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6408 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
6412 }
6413
6414 /**
Miaoa84611c2019-03-15 09:21:10 +08006415 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006416 *
Miaoa84611c2019-03-15 09:21:10 +08006417 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006418 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006419 * @hide
6420 */
6421 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006422 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006423 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006425 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 try {
Miaoa84611c2019-03-15 09:21:10 +08006427 if (phone != null) {
6428 return phone.hasMatchedTetherApnSetting();
6429 } else {
6430 return false;
6431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006434 }
Junda Liu475951f2014-11-07 16:45:03 -08006435 }
6436
6437 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006438 * Enable or disable always reporting signal strength changes from radio.
6439 *
6440 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6441 */
6442 @Override
6443 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6444 enforceModifyPermission();
6445 enforceSystemCaller();
6446
6447 final long identity = Binder.clearCallingIdentity();
6448 final Phone phone = getPhone(subId);
6449 try {
6450 if (phone != null) {
6451 if (DBG) {
6452 log("setAlwaysReportSignalStrength: subId=" + subId
6453 + " isEnable=" + isEnable);
6454 }
6455 phone.setAlwaysReportSignalStrength(isEnable);
6456 } else {
6457 loge("setAlwaysReportSignalStrength: no phone found for subId="
6458 + subId);
6459 }
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
6465 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006466 * Get the user enabled state of Mobile Data.
6467 *
6468 * TODO: remove and use isUserDataEnabled.
6469 * This can't be removed now because some vendor codes
6470 * calls through ITelephony directly while they should
6471 * use TelephonyManager.
6472 *
6473 * @return true on enabled
6474 */
6475 @Override
6476 public boolean getDataEnabled(int subId) {
6477 return isUserDataEnabled(subId);
6478 }
6479
6480 /**
6481 * Get whether mobile data is enabled per user setting.
6482 *
6483 * There are other factors deciding whether mobile data is actually enabled, but they are
6484 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006485 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006486 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006487 *
6488 * @return {@code true} if data is enabled else {@code false}
6489 */
6490 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006491 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006492 try {
6493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6494 null);
6495 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6497 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499
6500 final long identity = Binder.clearCallingIdentity();
6501 try {
6502 int phoneId = mSubscriptionController.getPhoneId(subId);
6503 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6504 Phone phone = PhoneFactory.getPhone(phoneId);
6505 if (phone != null) {
6506 boolean retVal = phone.isUserDataEnabled();
6507 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6508 return retVal;
6509 } else {
6510 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6511 return false;
6512 }
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006515 }
6516 }
6517
6518 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006519 * Checks if the device is capable of mobile data by considering whether whether the
6520 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6521 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006522 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006523 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006524 */
6525 @Override
6526 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006527 try {
6528 try {
6529 mApp.enforceCallingOrSelfPermission(
6530 android.Manifest.permission.ACCESS_NETWORK_STATE,
6531 null);
6532 } catch (Exception e) {
6533 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6534 "isDataEnabled");
6535 }
6536 } catch (Exception e) {
6537 enforceReadPrivilegedPermission("isDataEnabled");
6538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539
6540 final long identity = Binder.clearCallingIdentity();
6541 try {
6542 int phoneId = mSubscriptionController.getPhoneId(subId);
6543 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6544 Phone phone = PhoneFactory.getPhone(phoneId);
6545 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006546 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6548 return retVal;
6549 } else {
6550 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6551 return false;
6552 }
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006555 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006556 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006557
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006558 /**
6559 * Check if data is enabled for a specific reason
6560 * @param subId Subscription index
6561 * @param reason the reason the data enable change is taking place
6562 * @return {@code true} if the overall data is enabled; {@code false} if not.
6563 */
6564 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006565 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006566 @TelephonyManager.DataEnabledReason int reason) {
6567 try {
6568 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6569 null);
6570 } catch (Exception e) {
6571 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006572 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006573 }
6574
6575
6576 final long identity = Binder.clearCallingIdentity();
6577 try {
6578 int phoneId = mSubscriptionController.getPhoneId(subId);
6579 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006580 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006581 + " reason=" + reason);
6582 }
6583 Phone phone = PhoneFactory.getPhone(phoneId);
6584 if (phone != null) {
6585 boolean retVal;
6586 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6587 retVal = phone.isUserDataEnabled();
6588 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006589 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006590 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006591 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006592 return retVal;
6593 } else {
6594 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006595 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006596 + subId + " retVal=false");
6597 }
6598 return false;
6599 }
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
6603 }
6604
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006605 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006606 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006607 if (uid == Process.PHONE_UID) {
6608 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6609 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6611 }
6612
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006613 //load access rules from carrier configs, and check those as well: b/139133814
6614 SubscriptionController subController = SubscriptionController.getInstance();
6615 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6616 || subController == null) return privilegeFromSim;
6617
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006618 PackageManager pkgMgr = phone.getContext().getPackageManager();
6619 String[] packages = pkgMgr.getPackagesForUid(uid);
6620
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006623 int subId = phone.getSubId();
6624 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6625 // A test override is in place for the privileges for this subId, so don't try to
6626 // read the subscription privileges.
6627 return privilegeFromSim;
6628 }
6629 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006630 SubscriptionManager subManager = (SubscriptionManager)
6631 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6632 for (String pkg : packages) {
6633 if (subManager.canManageSubscription(subInfo, pkg)) {
6634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6635 }
6636 }
6637 return privilegeFromSim;
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
6640 }
6641 }
6642
6643 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6644 String pkgName) {
6645 //load access rules from carrier configs, and check those as well: b/139133814
6646 SubscriptionController subController = SubscriptionController.getInstance();
6647 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6648 || subController == null) return privilegeFromSim;
6649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006652 int subId = phone.getSubId();
6653 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6654 // A test override is in place for the privileges for this subId, so don't try to
6655 // read the subscription privileges.
6656 return privilegeFromSim;
6657 }
6658 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006659 SubscriptionManager subManager = (SubscriptionManager)
6660 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6661 return subManager.canManageSubscription(subInfo, pkgName)
6662 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
6667
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006668 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006669 public int getCarrierPrivilegeStatus(int subId) {
6670 final Phone phone = getPhone(subId);
6671 if (phone == null) {
6672 loge("getCarrierPrivilegeStatus: Invalid subId");
6673 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6674 }
6675 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006676 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006677 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006678 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6679 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006680
6681 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6682 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006683 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006684 }
Junda Liu29340342014-07-10 15:23:27 -07006685
6686 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006687 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006688 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006689 final Phone phone = getPhone(subId);
6690 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006691 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006692 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6693 }
6694 UiccProfile profile =
6695 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6696 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006697 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6699 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006700 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006701 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006702 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006703 }
6704
6705 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006706 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006707 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006708 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006709 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006710 }
6711
6712 int phoneId = SubscriptionManager.getPhoneId(subId);
6713 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006714 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006715 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006716 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6717 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006718 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6719 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6720 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006721 }
6722
6723 @Override
6724 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006725 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006726 if (TextUtils.isEmpty(pkgName))
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006728 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6729 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6730 UiccCard card = UiccController.getInstance().getUiccCard(i);
6731 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006732 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006733 continue;
6734 }
6735
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006736 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6737 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6738 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006739 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6740 break;
6741 }
6742 }
6743
6744 return result;
Junda Liu29340342014-07-10 15:23:27 -07006745 }
Derek Tan89e89d42014-07-08 17:00:10 -07006746
6747 @Override
Junda Liue64de782015-04-16 17:19:16 -07006748 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006749 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006750 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6751 loge("phoneId " + phoneId + " is not valid.");
6752 return null;
6753 }
6754 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006755 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006756 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006757 return null ;
6758 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006759 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006760 }
6761
Amith Yamasani6e118872016-02-19 12:53:51 -08006762 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006763 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006764 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006765 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006766 List<String> privilegedPackages = new ArrayList<>();
6767 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006768 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6769 // has UICC in that slot.
6770 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006771 if (card.hasCarrierPrivilegeRules()) {
6772 if (packages == null) {
6773 // Only check packages in user 0 for now
6774 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006775 PackageManager.MATCH_DISABLED_COMPONENTS
6776 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006777 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006778 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006779 }
6780 for (int p = packages.size() - 1; p >= 0; p--) {
6781 PackageInfo pkgInfo = packages.get(p);
6782 if (pkgInfo != null && pkgInfo.packageName != null
6783 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006784 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 privilegedPackages.add(pkgInfo.packageName);
6786 }
6787 }
6788 }
6789 }
6790 return privilegedPackages;
6791 }
6792
chen xuf7e9fe82019-05-09 19:31:02 -07006793 @Override
6794 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006795 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6796
6797 final long identity = Binder.clearCallingIdentity();
6798
chen xuf7e9fe82019-05-09 19:31:02 -07006799 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006800 try {
6801 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6802 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6803 }
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006806 }
6807 return privilegedPackages;
6808 }
6809
Wink Savilleb564aae2014-10-23 10:18:09 -07006810 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006811 final Phone phone = getPhone(subId);
6812 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006813 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006814 return null;
6815 }
6816 String iccId = card.getIccId();
6817 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006818 return null;
6819 }
6820 return iccId;
6821 }
6822
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006823 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006824 public void setCallComposerStatus(int subId, int status) {
6825 enforceModifyPermission();
6826
6827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 Phone phone = getPhone(subId);
6830 if (phone != null) {
6831 Phone defaultPhone = phone.getImsPhone();
6832 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6833 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6834 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006835 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6836 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006837 }
6838 }
Shuo Qian284ae752020-12-22 19:10:14 -08006839 } catch (ImsException e) {
6840 throw new ServiceSpecificException(e.getCode());
6841 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006842 Binder.restoreCallingIdentity(identity);
6843 }
6844 }
6845
6846 @Override
6847 public int getCallComposerStatus(int subId) {
6848 enforceReadPrivilegedPermission("getCallComposerStatus");
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 Phone phone = getPhone(subId);
6853 if (phone != null) {
6854 Phone defaultPhone = phone.getImsPhone();
6855 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6856 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6857 return imsPhone.getCallComposerStatus();
6858 }
6859 }
6860 } finally {
6861 Binder.restoreCallingIdentity(identity);
6862 }
6863 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6864 }
6865
6866 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006867 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6868 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006870 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 final long identity = Binder.clearCallingIdentity();
6873 try {
6874 final String iccId = getIccId(subId);
6875 final Phone phone = getPhone(subId);
6876 if (phone == null) {
6877 return false;
6878 }
6879 final String subscriberId = phone.getSubscriberId();
6880
6881 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006882 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 + subscriberId + " to " + number);
6884 }
6885
6886 if (TextUtils.isEmpty(iccId)) {
6887 return false;
6888 }
6889
6890 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6891
6892 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6893 if (alphaTag == null) {
6894 editor.remove(alphaTagPrefKey);
6895 } else {
6896 editor.putString(alphaTagPrefKey, alphaTag);
6897 }
6898
6899 // Record both the line number and IMSI for this ICCID, since we need to
6900 // track all merged IMSIs based on line number
6901 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6902 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6903 if (number == null) {
6904 editor.remove(numberPrefKey);
6905 editor.remove(subscriberPrefKey);
6906 } else {
6907 editor.putString(numberPrefKey, number);
6908 editor.putString(subscriberPrefKey, subscriberId);
6909 }
6910
6911 editor.commit();
6912 return true;
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006915 }
Derek Tan7226c842014-07-02 17:42:23 -07006916 }
6917
6918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006919 public String getLine1NumberForDisplay(int subId, String callingPackage,
6920 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006921 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006923 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006924 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006925 return null;
6926 }
Derek Tan97ebb422014-09-05 16:55:38 -07006927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 String iccId = getIccId(subId);
6931 if (iccId != null) {
6932 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6933 if (DBG_MERGE) {
6934 log("getLine1NumberForDisplay returning "
6935 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6936 }
6937 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6940 return null;
6941 } finally {
6942 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006943 }
Derek Tan7226c842014-07-02 17:42:23 -07006944 }
6945
6946 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006947 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6948 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006950 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006951 return null;
6952 }
Derek Tan97ebb422014-09-05 16:55:38 -07006953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 final long identity = Binder.clearCallingIdentity();
6955 try {
6956 String iccId = getIccId(subId);
6957 if (iccId != null) {
6958 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6959 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6960 }
6961 return null;
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006964 }
Derek Tan7226c842014-07-02 17:42:23 -07006965 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006966
6967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006968 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6969 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006970 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6971 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006973 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006974 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006975 return null;
6976 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006977
Jordan Liub49b04b2019-05-06 14:45:15 -07006978 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6979 // the process, where TelephonyManager was instantiated.
6980 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006981 final long identity = Binder.clearCallingIdentity();
6982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006983 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 final TelephonyManager tele = TelephonyManager.from(context);
6985 final SubscriptionManager sub = SubscriptionManager.from(context);
6986
6987 // Figure out what subscribers are currently active
6988 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006989
Jordan Liub49b04b2019-05-06 14:45:15 -07006990 // Only consider subs which match the current subId
6991 // This logic can be simplified. See b/131189269 for progress.
6992 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006993 activeSubscriberIds.add(tele.getSubscriberId(subId));
6994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 // First pass, find a number override for an active subscriber
6997 String mergeNumber = null;
6998 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6999 for (String key : prefs.keySet()) {
7000 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7001 final String subscriberId = (String) prefs.get(key);
7002 if (activeSubscriberIds.contains(subscriberId)) {
7003 final String iccId = key.substring(
7004 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7005 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7006 mergeNumber = (String) prefs.get(numberKey);
7007 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007008 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007009 + " for active subscriber " + subscriberId);
7010 }
7011 if (!TextUtils.isEmpty(mergeNumber)) {
7012 break;
7013 }
7014 }
7015 }
7016 }
7017
7018 // Shortcut when no active merged subscribers
7019 if (TextUtils.isEmpty(mergeNumber)) {
7020 return null;
7021 }
7022
7023 // Second pass, find all subscribers under that line override
7024 final ArraySet<String> result = new ArraySet<>();
7025 for (String key : prefs.keySet()) {
7026 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7027 final String number = (String) prefs.get(key);
7028 if (mergeNumber.equals(number)) {
7029 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7030 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7031 final String subscriberId = (String) prefs.get(subscriberKey);
7032 if (!TextUtils.isEmpty(subscriberId)) {
7033 result.add(subscriberId);
7034 }
7035 }
7036 }
7037 }
7038
7039 final String[] resultArray = result.toArray(new String[result.size()]);
7040 Arrays.sort(resultArray);
7041 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007042 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7044 }
7045 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007046 } finally {
7047 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007048 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007049 }
7050
7051 @Override
zoey chen38003472019-12-13 17:16:31 +08007052 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7053 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007054
7055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 final TelephonyManager telephonyManager = mApp.getSystemService(
7058 TelephonyManager.class);
7059 String subscriberId = telephonyManager.getSubscriberId(subId);
7060 if (subscriberId == null) {
7061 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007062 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007063 + subId);
7064 }
7065 return null;
7066 }
7067
7068 final SubscriptionInfo info = SubscriptionController.getInstance()
7069 .getSubscriptionInfo(subId);
7070 final ParcelUuid groupUuid = info.getGroupUuid();
7071 // If it doesn't belong to any group, return just subscriberId of itself.
7072 if (groupUuid == null) {
7073 return new String[]{subscriberId};
7074 }
7075
7076 // Get all subscriberIds from the group.
7077 final List<String> mergedSubscriberIds = new ArrayList<>();
7078 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007079 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007080 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007081 for (SubscriptionInfo subInfo : groupInfos) {
7082 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7083 if (subscriberId != null) {
7084 mergedSubscriberIds.add(subscriberId);
7085 }
7086 }
7087
7088 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
7091
7092 }
7093 }
7094
7095 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007096 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007097 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 final Phone phone = getPhone(subId);
7103 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007107 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007108
7109 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007110 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007111 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7112 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007113 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7114 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115
7116 final long identity = Binder.clearCallingIdentity();
7117 try {
7118 final Phone phone = getPhone(subId);
7119 if (phone == null) {
7120 return false;
7121 }
7122 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7123 cdmaNonRoamingList);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007126 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007127 }
7128
7129 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007130 @Deprecated
7131 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7132 enforceModifyPermission();
7133
7134 int returnValue = 0;
7135 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007136 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007137 if(result.exception == null) {
7138 if (result.result != null) {
7139 byte[] responseData = (byte[])(result.result);
7140 if(responseData.length > oemResp.length) {
7141 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7142 responseData.length + "bytes. Buffer Size is " +
7143 oemResp.length + "bytes.");
7144 }
7145 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7146 returnValue = responseData.length;
7147 }
7148 } else {
7149 CommandException ex = (CommandException) result.exception;
7150 returnValue = ex.getCommandError().ordinal();
7151 if(returnValue > 0) returnValue *= -1;
7152 }
7153 } catch (RuntimeException e) {
7154 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7155 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7156 if(returnValue > 0) returnValue *= -1;
7157 }
7158
7159 return returnValue;
7160 }
7161
7162 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007163 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007164 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007165 try {
7166 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007167 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007168 mApp, phone.getSubId(), "getRadioAccessFamily");
7169 } catch (SecurityException e) {
7170 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7171 throw e;
7172 }
chen xub97461a2018-10-26 14:17:57 -07007173 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007174 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007175 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 final long identity = Binder.clearCallingIdentity();
7178 try {
chen xub97461a2018-10-26 14:17:57 -07007179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007180 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007181 mApp, phone.getSubId(), "getRadioAccessFamily");
7182 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
chen xub97461a2018-10-26 14:17:57 -07007186 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007187 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007188
7189 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007190 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007191 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007192 try {
7193 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7194 Binder.getCallingUid())) {
7195 throw new SecurityException("Package uid and package name do not match: "
7196 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7197 }
7198 } catch (PackageManager.NameNotFoundException e) {
7199 throw new SecurityException("Package name invalid:" + callingPackage);
7200 }
7201 RoleManager rm = mApp.getSystemService(RoleManager.class);
7202 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7203 if (!dialerRoleHolders.contains(callingPackage)) {
7204 throw new SecurityException("App must be the dialer role holder to"
7205 + " upload a call composer pic");
7206 }
7207
7208 Executors.newSingleThreadExecutor().execute(() -> {
7209 ByteArrayOutputStream output = new ByteArrayOutputStream(
7210 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7211 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7212 boolean readUntilEnd = false;
7213 int totalBytesRead = 0;
7214 byte[] buffer = new byte[16 * 1024];
7215 while (true) {
7216 int numRead;
7217 try {
7218 numRead = input.read(buffer);
7219 } catch (IOException e) {
7220 try {
7221 fd.checkError();
7222 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7223 null);
7224 } catch (IOException e1) {
7225 // This means that the other side closed explicitly with an error. If this
7226 // happens, log and ignore.
7227 loge("Remote end of call composer picture pipe closed: " + e1);
7228 }
7229 break;
7230 }
7231 if (numRead == -1) {
7232 readUntilEnd = true;
7233 break;
7234 }
7235 totalBytesRead += numRead;
7236 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7237 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7238 try {
7239 input.close();
7240 } catch (IOException e) {
7241 // ignore
7242 }
7243 break;
7244 }
7245 output.write(buffer, 0, numRead);
7246 }
7247 // Generally, the remote end will close the file descriptors. The only case where we
7248 // close is above, where the picture size is too big.
7249
7250 try {
7251 fd.checkError();
7252 } catch (IOException e) {
7253 loge("Remote end for call composer closed with an error: " + e);
7254 return;
7255 }
7256
Hall Liuaa4211e2021-01-20 15:43:39 -08007257 if (!readUntilEnd) {
7258 loge("Did not finish reading entire image; aborting");
7259 return;
7260 }
Hall Liu82694d52020-12-11 18:22:04 -08007261
Hall Liuaa4211e2021-01-20 15:43:39 -08007262 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7263 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7264 new CallComposerPictureTransfer.Factory() {},
7265 imageData,
7266 (result) -> {
7267 if (result.first != null) {
7268 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7269 Bundle outputResult = new Bundle();
7270 outputResult.putParcelable(
7271 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7272 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7273 outputResult);
7274 } else {
7275 callback.send(result.second, null);
7276 }
7277 }
7278 );
Hall Liu82694d52020-12-11 18:22:04 -08007279 });
7280 }
7281
7282 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007283 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007284 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007285 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286
7287 final long identity = Binder.clearCallingIdentity();
7288 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007289 ImsManager.getInstance(defaultPhone.getContext(),
7290 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007294 }
7295
7296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007297 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7300 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007301 return false;
7302 }
Svet Ganovb320e182015-04-16 12:30:10 -07007303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 final long identity = Binder.clearCallingIdentity();
7305 try {
7306 // Check the user preference and the system-level IMS setting. Even if the user has
7307 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7308 // In the long run, we may instead need to check if there exists a connection service
7309 // which can support video calling.
7310 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007311 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 return imsManager.isVtEnabledByPlatform()
7313 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7314 && imsManager.isVtEnabledByUser();
7315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007318 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007319
Andrew Leea1239f22015-03-02 17:44:07 -08007320 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007321 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7322 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007324 mApp, subId, callingPackage, callingFeatureId,
7325 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 return false;
7327 }
7328
7329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 CarrierConfigManager configManager =
7332 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007333 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
Andrew Leea1239f22015-03-02 17:44:07 -08007338 }
7339
7340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 return false;
7345 }
7346
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 CarrierConfigManager configManager =
7350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
Andrew Leea1239f22015-03-02 17:44:07 -08007356 }
7357
Andrew Lee9431b832015-03-09 18:46:45 -07007358 @Override
7359 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007360 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007361 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007362 }
7363
7364 @Override
7365 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007368 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
Andrew Lee9431b832015-03-09 18:46:45 -07007372 }
7373
Hall Liuf6668912018-10-31 17:05:23 -07007374 /**
7375 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7376 * support for the feature and device firmware support.
7377 *
7378 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7379 */
7380 @Override
7381 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 final Phone phone = getPhone(subscriptionId);
7384 if (phone == null) {
7385 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7386 return false;
7387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007389 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7391 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 return isCarrierSupported && isDeviceSupported;
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
Hall Liu98187582018-01-22 19:15:32 -08007397 }
7398
Hall Liuf6668912018-10-31 17:05:23 -07007399 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007400 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7401 * RTT setting, will return true if the device and carrier both support RTT.
7402 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007403 */
7404 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
7406 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007407 boolean isRttSupported = isRttSupported(subscriptionId);
7408 boolean isUserRttSettingOn = Settings.Secure.getInt(
7409 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7410 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7411 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7412 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007416 }
7417
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 @Deprecated
7419 @Override
7420 public String getDeviceId(String callingPackage) {
7421 return getDeviceIdWithFeature(callingPackage, null);
7422 }
7423
Sanket Padawe7310cc72015-01-14 09:53:20 -08007424 /**
7425 * Returns the unique device ID of phone, for example, the IMEI for
7426 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7427 *
7428 * <p>Requires Permission:
7429 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7430 */
7431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007432 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007433 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007434 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007435 return null;
7436 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007437 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007438 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007440 return null;
7441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 return phone.getDeviceId();
7446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007449 }
7450
Ping Sunc67b7c22016-03-02 19:16:45 +08007451 /**
7452 * {@hide}
7453 * Returns the IMS Registration Status on a particular subid
7454 *
7455 * @param subId
7456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007457 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007458 Phone phone = getPhone(subId);
7459 if (phone != null) {
7460 return phone.isImsRegistered();
7461 } else {
7462 return false;
7463 }
7464 }
7465
Santos Cordon7a1885b2015-02-03 11:15:19 -08007466 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007467 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007468 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007470 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007471 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7472 }
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
7475 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
7479 }
7480
7481 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007482 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007483 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007484 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007485 mApp,
7486 subscriptionId,
7487 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 Phone phone = getPhone(subscriptionId);
7491 if (phone == null) {
7492 return null;
7493 }
7494 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7495 } finally {
7496 Binder.restoreCallingIdentity(identity);
7497 }
7498 }
7499
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007500 /**
7501 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007502 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007503 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
7506 Phone phone = getPhone(subId);
7507 if (phone != null) {
7508 return phone.isWifiCallingEnabled();
7509 } else {
7510 return false;
7511 }
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007514 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007515 }
7516
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007517 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007518 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007519 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007520 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = getPhone(subId);
7524 if (phone != null) {
7525 return phone.isVideoEnabled();
7526 } else {
7527 return false;
7528 }
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007531 }
7532 }
7533
7534 /**
7535 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7536 * defined in {@link ImsRegistrationImplBase}.
7537 */
7538 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 final long identity = Binder.clearCallingIdentity();
7540 try {
7541 Phone phone = getPhone(subId);
7542 if (phone != null) {
7543 return phone.getImsRegistrationTech();
7544 } else {
7545 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7546 }
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007549 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007550 }
7551
Stuart Scott8eef64f2015-04-08 15:13:54 -07007552 @Override
7553 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007554 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007555 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7556 return;
7557 }
Kai Shif70f46f2021-03-03 13:59:46 -08007558 Phone defaultPhone = getDefaultPhone();
7559 if (defaultPhone != null) {
7560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7561 mApp, getDefaultPhone().getSubId(), "factoryReset");
7562 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007563 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564
Svet Ganovcc087f82015-05-12 20:35:54 -07007565 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007566 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7567 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007568 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007569 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007570 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007571 Phone phone = getPhone(subId);
7572 if (phone != null) {
7573 SubscriptionManager.setSubscriptionProperty(subId,
7574 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7575 "user=" + RadioAccessFamily.getRafFromNetworkType(
7576 RILConstants.PREFERRED_NETWORK_MODE));
7577 phone.loadAllowedNetworksFromSubscriptionDatabase();
7578 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007579 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007580 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007581 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007582 // There has been issues when Sms raw table somehow stores orphan
7583 // fragments. They lead to garbled message when new fragments come
7584 // in and combined with those stale ones. In case this happens again,
7585 // user can reset all network settings which will clean up this table.
7586 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007587 // Clean up IMS settings as well here.
7588 int slotId = getSlotIndex(subId);
7589 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7590 ImsManager.getInstance(mApp, slotId).factoryReset();
7591 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007592
Kai Shif70f46f2021-03-03 13:59:46 -08007593 if (defaultPhone == null) {
7594 return;
7595 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007596 // Erase modem config if erase modem on network setting is enabled.
7597 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7598 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7599 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007600 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007601 }
Kai Shif70f46f2021-03-03 13:59:46 -08007602
7603 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007604 } finally {
7605 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007606 }
7607 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007608
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007609 private void cleanUpSmsRawTable(Context context) {
7610 ContentResolver resolver = context.getContentResolver();
7611 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7612 resolver.delete(uri, null, null);
7613 }
7614
Narayan Kamath1c496c22015-04-16 14:40:19 +01007615 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007616 public String getSimLocaleForSubscriber(int subId) {
7617 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7618 final Phone phone = getPhone(subId);
7619 if (phone == null) {
7620 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007621 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007622 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
7624 try {
chen xu5d3637b2019-01-21 23:31:38 -08007625 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007626 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007627 if (info == null) {
7628 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7629 return null;
7630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 // Try and fetch the locale from the carrier properties or from the SIM language
7632 // preferences (EF-PL and EF-LI)...
7633 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007635 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7636 if (localeFromDefaultSim != null) {
7637 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7638 if (DBG) log("Using locale from subId: " + subId + " locale: "
7639 + localeFromDefaultSim);
7640 return localeFromDefaultSim.toLanguageTag();
7641 } else {
7642 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 }
7644 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 // The SIM language preferences only store a language (e.g. fr = French), not an
7647 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7648 // the SIM and carrier preferences does not include a country we add the country
7649 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007650 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007652 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653 return mccLocale.toLanguageTag();
7654 }
7655
7656 if (DBG) log("No locale found - returning null");
7657 return null;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007661 }
7662
7663 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007664 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007665 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007666 }
7667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007668 /**
7669 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7670 */
7671 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007673 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007674 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007675
Chenjie Yu1ba97252018-01-11 18:16:20 -08007676 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007677 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007678
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007679 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007680 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7681 * representing the state of the modem.
7682 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007683 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7684 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007685 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007686 */
7687 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007688 public void requestModemActivityInfo(ResultReceiver result) {
7689 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007694 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007697 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007698 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007699
Siddharth Rayb8114062018-06-17 15:02:38 -07007700 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7701 // less than total activity duration.
7702 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7703 if (info == null) {
7704 return false;
7705 }
7706 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007707 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7708 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7709
Siddharth Rayb8114062018-06-17 15:02:38 -07007710 return (info.isValid()
7711 && (info.getSleepTimeMillis() <= activityDurationMs)
7712 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007713 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007714 && (totalTxTimeMs <= activityDurationMs));
7715 }
7716
Jack Yu85bd38a2015-11-09 11:34:32 -08007717 /**
7718 * {@hide}
7719 * Returns the service state information on specified subscription.
7720 */
7721 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007722 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007725 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007726 return null;
7727 }
7728
Hall Liuf19c44f2018-11-27 14:38:17 -08007729 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7730 LocationAccessPolicy.checkLocationPermission(mApp,
7731 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7732 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007733 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007734 .setCallingPid(Binder.getCallingPid())
7735 .setCallingUid(Binder.getCallingUid())
7736 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007737 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007738 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007739 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7740 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007741 .build());
7742
7743 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7744 LocationAccessPolicy.checkLocationPermission(mApp,
7745 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7746 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007747 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007748 .setCallingPid(Binder.getCallingPid())
7749 .setCallingUid(Binder.getCallingUid())
7750 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007751 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007752 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007753 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7754 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007755 .build());
7756 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7757 boolean hasFinePermission =
7758 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7759 boolean hasCoarsePermission =
7760 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7761
Jack Yu479f40e2020-10-27 21:29:25 -07007762 final Phone phone = getPhone(subId);
7763 if (phone == null) {
7764 return null;
7765 }
7766
Jordan Liu0f2bc442020-11-18 16:47:37 -08007767 final long identity = Binder.clearCallingIdentity();
7768
Jack Yu479f40e2020-10-27 21:29:25 -07007769 boolean isCallingPackageDataService = phone.getDataServicePackages()
7770 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007772 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7773 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7774 Rlog.d(LOG_TAG,
7775 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7776 return null;
7777 }
7778
Hall Liuf19c44f2018-11-27 14:38:17 -08007779 ServiceState ss = phone.getServiceState();
7780
7781 // Scrub out the location info in ServiceState depending on what level of access
7782 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007783 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007784 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7785 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 } finally {
7787 Binder.restoreCallingIdentity(identity);
7788 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007789 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007790
7791 /**
7792 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7793 *
7794 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7795 * voicemail ringtone.
7796 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7797 * PhoneAccount.
7798 */
7799 @Override
7800 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 final long identity = Binder.clearCallingIdentity();
7802 try {
7803 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7804 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007805 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007812 }
7813
7814 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007815 * Sets the per-account voicemail ringtone.
7816 *
7817 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7818 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7819 *
7820 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7821 * voicemail ringtone.
7822 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7823 * PhoneAccount.
7824 */
7825 @Override
7826 public void setVoicemailRingtoneUri(String callingPackage,
7827 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007828 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007829 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007830 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7831 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7833 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7834 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7840 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007841 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 }
7843 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007846 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007847 }
7848
7849 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007850 * Returns whether vibration is set for voicemail notification in Phone settings.
7851 *
7852 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7853 * voicemail vibration setting.
7854 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7855 */
7856 @Override
7857 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7861 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007862 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007869 }
7870
Youhan Wange64578a2016-05-02 15:32:42 -07007871 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007872 * Sets the per-account voicemail vibration.
7873 *
7874 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7875 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7876 *
7877 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7878 * voicemail vibration setting.
7879 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7880 * specific PhoneAccount.
7881 */
7882 @Override
7883 public void setVoicemailVibrationEnabled(String callingPackage,
7884 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007885 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007886 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007887 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7888 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7890 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7891 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007892 }
7893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 final long identity = Binder.clearCallingIdentity();
7895 try {
7896 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7897 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007898 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 }
7900 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7901 } finally {
7902 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007903 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007904 }
7905
7906 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007907 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7908 *
7909 * @throws SecurityException if the caller does not have the required permission
7910 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007911 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007913 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007914 }
7915
7916 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007917 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7918 * permission.
7919 *
7920 * @throws SecurityException if the caller does not have the required permission
7921 */
7922 private void enforceSendSmsPermission() {
7923 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7924 }
7925
7926 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007927 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007928 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007929 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007930 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007931 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 final long identity = Binder.clearCallingIdentity();
7933 try {
7934 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007935 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 if (componentName == null) {
7937 throw new SecurityException(
7938 "Caller not current active visual voicemail package[null]");
7939 }
7940 String vvmPackage = componentName.getPackageName();
7941 if (!callingPackage.equals(vvmPackage)) {
7942 throw new SecurityException("Caller not current active visual voicemail package["
7943 + vvmPackage + "]");
7944 }
7945 } finally {
7946 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007947 }
7948 }
7949
7950 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007951 * Return the application ID for the app type.
7952 *
7953 * @param subId the subscription ID that this request applies to.
7954 * @param appType the uicc app type.
7955 * @return Application ID for specificied app type, or null if no uicc.
7956 */
7957 @Override
7958 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007959 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007960 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007963 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 if (phone == null) {
7965 return null;
7966 }
7967 String aid = null;
7968 try {
7969 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7970 .getApplicationByType(appType).getAid();
7971 } catch (Exception e) {
7972 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7973 }
7974 return aid;
7975 } finally {
7976 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007977 }
Youhan Wange64578a2016-05-02 15:32:42 -07007978 }
7979
Youhan Wang4001d252016-05-11 10:29:41 -07007980 /**
7981 * Return the Electronic Serial Number.
7982 *
7983 * @param subId the subscription ID that this request applies to.
7984 * @return ESN or null if error.
7985 */
7986 @Override
7987 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007988 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007989 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990
7991 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007992 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 if (phone == null) {
7994 return null;
7995 }
7996 String esn = null;
7997 try {
7998 esn = phone.getEsn();
7999 } catch (Exception e) {
8000 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8001 }
8002 return esn;
8003 } finally {
8004 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008005 }
Youhan Wang4001d252016-05-11 10:29:41 -07008006 }
8007
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008008 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008009 * Return the Preferred Roaming List Version.
8010 *
8011 * @param subId the subscription ID that this request applies to.
8012 * @return PRLVersion or null if error.
8013 */
8014 @Override
8015 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008016 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008017 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018
8019 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008020 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008021 if (phone == null) {
8022 return null;
8023 }
8024 String cdmaPrlVersion = null;
8025 try {
8026 cdmaPrlVersion = phone.getCdmaPrlVersion();
8027 } catch (Exception e) {
8028 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8029 }
8030 return cdmaPrlVersion;
8031 } finally {
8032 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008033 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008034 }
8035
8036 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008037 * Get snapshot of Telephony histograms
8038 * @return List of Telephony histograms
8039 * @hide
8040 */
8041 @Override
8042 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8044 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045
8046 final long identity = Binder.clearCallingIdentity();
8047 try {
8048 return RIL.getTelephonyRILTimingHistograms();
8049 } finally {
8050 Binder.restoreCallingIdentity(identity);
8051 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008052 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008053
8054 /**
8055 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008056 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8057 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008058 * Require system privileges. In the future we may add this to carrier APIs.
8059 *
Michele Berionne482f8202018-11-27 18:57:59 -08008060 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008061 */
8062 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008063 @TelephonyManager.SetCarrierRestrictionResult
8064 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008065 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008067
Michele Berionne482f8202018-11-27 18:57:59 -08008068 if (carrierRestrictionRules == null) {
8069 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008070 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 final long identity = Binder.clearCallingIdentity();
8073 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008074 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008075 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008079 }
8080
8081 /**
8082 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008083 * Get the allowed carrier list and the excluded carrier list, including the priority between
8084 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008085 * Require system privileges. In the future we may add this to carrier APIs.
8086 *
Michele Berionne482f8202018-11-27 18:57:59 -08008087 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008088 */
8089 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008090 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008091 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093
8094 final long identity = Binder.clearCallingIdentity();
8095 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008096 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8097 if (response instanceof CarrierRestrictionRules) {
8098 return (CarrierRestrictionRules) response;
8099 }
8100 // Response is an Exception of some kind,
8101 // which is signalled to the user as a NULL retval
8102 return null;
8103 } catch (Exception e) {
8104 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8105 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 } finally {
8107 Binder.restoreCallingIdentity(identity);
8108 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008109 }
8110
fionaxu59545b42016-05-25 15:53:37 -07008111 /**
fionaxu59545b42016-05-25 15:53:37 -07008112 * Action set from carrier signalling broadcast receivers to enable/disable radio
8113 * @param subId the subscription ID that this action applies to.
8114 * @param enabled control enable or disable radio.
8115 * {@hide}
8116 */
8117 @Override
8118 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8119 enforceModifyPermission();
8120 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121
8122 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008123 if (phone == null) {
8124 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8125 return;
8126 }
8127 try {
8128 phone.carrierActionSetRadioEnabled(enabled);
8129 } catch (Exception e) {
8130 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 } finally {
8132 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008133 }
8134 }
8135
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008136 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008137 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8138 * network status based on which carrier apps could apply actions accordingly,
8139 * enable/disable default url handler for example.
8140 *
8141 * @param subId the subscription ID that this action applies to.
8142 * @param report control start/stop reporting the default network status.
8143 * {@hide}
8144 */
8145 @Override
8146 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8147 enforceModifyPermission();
8148 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008149
8150 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008151 if (phone == null) {
8152 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8153 return;
8154 }
8155 try {
8156 phone.carrierActionReportDefaultNetworkStatus(report);
8157 } catch (Exception e) {
8158 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 } finally {
8160 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008161 }
8162 }
8163
8164 /**
fionaxud9622282017-07-17 17:51:30 -07008165 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8166 * @param subId the subscription ID that this action applies to.
8167 * {@hide}
8168 */
8169 @Override
8170 public void carrierActionResetAll(int subId) {
8171 enforceModifyPermission();
8172 final Phone phone = getPhone(subId);
8173 if (phone == null) {
8174 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8175 return;
8176 }
8177 try {
8178 phone.carrierActionResetAll();
8179 } catch (Exception e) {
8180 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8181 }
8182 }
8183
8184 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008185 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8186 * bug report is being generated.
8187 */
8188 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008189 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8191 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008192 writer.println("Permission Denial: can't dump Phone from pid="
8193 + Binder.getCallingPid()
8194 + ", uid=" + Binder.getCallingUid()
8195 + "without permission "
8196 + android.Manifest.permission.DUMP);
8197 return;
8198 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008199 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008200 }
Jack Yueb89b242016-06-22 13:27:47 -07008201
Brad Ebingerdac2f002018-04-03 15:17:52 -07008202 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008203 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8204 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8205 @NonNull String[] args) {
8206 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8207 this, in.getFileDescriptor(), out.getFileDescriptor(),
8208 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008209 }
8210
Jack Yueb89b242016-06-22 13:27:47 -07008211 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008212 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008213 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008214 * @param reason the reason the data enable change is taking place
8215 * @param enabled True if enabling the data, otherwise disabling.
8216 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008217 */
8218 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008219 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008220 boolean enabled) {
8221 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8222 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8223 try {
8224 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008225 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008226 } catch (SecurityException se) {
8227 enforceModifyPermission();
8228 }
8229 } else {
8230 enforceModifyPermission();
8231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 Phone phone = getPhone(subId);
8236 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008237 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8238 phone.carrierActionSetMeteredApnsEnabled(enabled);
8239 } else {
8240 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 }
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008245 }
8246 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008247
8248 /**
8249 * Get Client request stats
8250 * @return List of Client Request Stats
8251 * @hide
8252 */
8253 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008254 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8255 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008257 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008258 return null;
8259 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008260 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 if (phone != null) {
8265 return phone.getClientRequestStats();
8266 }
8267
8268 return null;
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008272 }
8273
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008274 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008275 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008276 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008277 }
Jack Yueb4124c2017-02-16 15:32:43 -08008278
8279 /**
Grace Chen70990072017-03-24 17:21:30 -07008280 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008281 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008282 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008283 * @param state State of SIM (power down, power up, pass through)
8284 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8285 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8286 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008287 *
8288 **/
8289 @Override
Grace Chen70990072017-03-24 17:21:30 -07008290 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008291 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008292 Phone phone = PhoneFactory.getPhone(slotIndex);
8293
vagdeviaf9a5b92018-08-15 16:01:53 -07008294 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008299 phone.setSimPowerState(state, null, workSource);
8300 }
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
8305
8306 /**
8307 * Set SIM card power state.
8308 *
8309 * @param slotIndex SIM slot id.
8310 * @param state State of SIM (power down, power up, pass through)
8311 * @param callback callback to trigger after success or failure
8312 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8313 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8314 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8315 *
8316 **/
8317 @Override
8318 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8319 IIntegerConsumer callback) {
8320 enforceModifyPermission();
8321 Phone phone = PhoneFactory.getPhone(slotIndex);
8322
8323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8324
8325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 if (phone != null) {
8328 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8329 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 }
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008333 }
8334 }
Shuo Qiandd210312017-04-12 22:11:33 +00008335
Tyler Gunn65d45c22017-06-05 11:22:26 -07008336 private boolean isUssdApiAllowed(int subId) {
8337 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008339 if (configManager == null) {
8340 return false;
8341 }
8342 PersistableBundle pb = configManager.getConfigForSubId(subId);
8343 if (pb == null) {
8344 return false;
8345 }
8346 return pb.getBoolean(
8347 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8348 }
8349
Shuo Qiandd210312017-04-12 22:11:33 +00008350 /**
8351 * Check if phone is in emergency callback mode
8352 * @return true if phone is in emergency callback mode
8353 * @param subId sub id
8354 */
goneil9c5f4872017-12-05 14:07:56 -08008355 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008356 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008357 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008358 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359
8360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 if (phone != null) {
8363 return phone.isInEcm();
8364 } else {
8365 return false;
8366 }
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008369 }
8370 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008371
8372 /**
8373 * Get the current signal strength information for the given subscription.
8374 * Because this information is not updated when the device is in a low power state
8375 * it should not be relied-upon to be current.
8376 * @param subId Subscription index
8377 * @return the most recent cached signal strength info from the modem
8378 */
8379 @Override
8380 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 Phone p = getPhone(subId);
8384 if (p == null) {
8385 return null;
8386 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 return p.getSignalStrength();
8389 } finally {
8390 Binder.restoreCallingIdentity(identity);
8391 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008392 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008393
Pengquan Meng77b7f132018-08-22 14:49:57 -07008394 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008395 * Get the current modem radio state for the given slot.
8396 * @param slotIndex slot index.
8397 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008398 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008399 * @return the current radio power state from the modem
8400 */
8401 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008402 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008403 Phone phone = PhoneFactory.getPhone(slotIndex);
8404 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8406 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008407 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8408 }
8409
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 return phone.getRadioPowerState();
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 }
8417 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8418 }
8419
8420 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008421 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8422 *
8423 * <p>Requires one of the following permissions:
8424 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8425 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8426 * privileges.
8427 *
8428 * @param subId subscription id
8429 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8430 * {@code false}.
8431 */
8432 @Override
8433 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008434 try {
8435 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8436 null);
8437 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008438 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008439 mApp, subId, "isDataRoamingEnabled");
8440 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008441
Pengquan Menga1bb6272018-09-06 09:59:22 -07008442 boolean isEnabled = false;
8443 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008444 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008445 Phone phone = getPhone(subId);
8446 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008447 } finally {
8448 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008449 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008450 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008451 }
8452
8453
8454 /**
8455 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8456 *
8457 * <p> Requires permission:
8458 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8459 * privileges.
8460 *
8461 * @param subId subscription id
8462 * @param isEnabled {@code true} means enable, {@code false} means disable.
8463 */
8464 @Override
8465 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8467 mApp, subId, "setDataRoamingEnabled");
8468
Pengquan Menga1bb6272018-09-06 09:59:22 -07008469 final long identity = Binder.clearCallingIdentity();
8470 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008471 Phone phone = getPhone(subId);
8472 if (phone != null) {
8473 phone.setDataRoamingEnabled(isEnabled);
8474 }
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008477 }
8478 }
8479
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008480 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008481 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008482 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008483 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008484 mApp, subId, "isManualNetworkSelectionAllowed");
8485
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008486 boolean isAllowed = true;
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008489 Phone phone = getPhone(subId);
8490 if (phone != null) {
8491 isAllowed = phone.isCspPlmnEnabled();
8492 }
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
8496 return isAllowed;
8497 }
8498
8499 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008500 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008501 // Verify that tha callingPackage belongs to the calling UID
8502 mApp.getSystemService(AppOpsManager.class)
8503 .checkPackage(Binder.getCallingUid(), callingPackage);
8504
Jordan Liu1e142fc2019-04-22 15:10:43 -07008505 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008506 try {
8507 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008508 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008509 } catch (SecurityException e) {
8510 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8511 // has carrier privileges on an active UICC
8512 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8513 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008514 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008515 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008516 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008517
8518 final long identity = Binder.clearCallingIdentity();
8519 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008520 UiccController uiccController = UiccController.getInstance();
8521 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008522 if (hasReadPermission) {
8523 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008524 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008525
8526 // Remove private info if the caller doesn't have access
8527 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8528 for (UiccCardInfo cardInfo : cardInfos) {
8529 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8530 // is available
8531 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8532 if (card == null || card.getUiccProfile() == null) {
8533 // assume no access if the card or profile is unavailable
8534 filteredInfos.add(cardInfo.getUnprivileged());
8535 continue;
8536 }
8537 UiccProfile profile = card.getUiccProfile();
8538 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8539 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8540 filteredInfos.add(cardInfo);
8541 } else {
8542 filteredInfos.add(cardInfo.getUnprivileged());
8543 }
8544 }
8545 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008552 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008553 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8558 if (slots == null) {
8559 Rlog.i(LOG_TAG, "slots is null.");
8560 return null;
8561 }
8562
8563 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8564 for (int i = 0; i < slots.length; i++) {
8565 UiccSlot slot = slots[i];
8566 if (slot == null) {
8567 continue;
8568 }
8569
Jordan Liu7be7e652019-05-06 18:55:02 +00008570 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571 UiccCard card = slot.getUiccCard();
8572 if (card != null) {
8573 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008574 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008575 cardId = slot.getEid();
8576 if (TextUtils.isEmpty(cardId)) {
8577 cardId = slot.getIccId();
8578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 }
8580
Jordan Liu857451f2019-05-09 16:35:35 -07008581 if (cardId != null) {
8582 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8583 // if cardId is an EID, it's all digits so this is fine
8584 cardId = IccUtils.stripTrailingFs(cardId);
8585 }
8586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 int cardState = 0;
8588 switch (slot.getCardState()) {
8589 case CARDSTATE_ABSENT:
8590 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8591 break;
8592 case CARDSTATE_PRESENT:
8593 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8594 break;
8595 case CARDSTATE_ERROR:
8596 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8597 break;
8598 case CARDSTATE_RESTRICTED:
8599 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8600 break;
8601 default:
8602 break;
8603
8604 }
8605
8606 infos[i] = new UiccSlotInfo(
8607 slot.isActive(),
8608 slot.isEuicc(),
8609 cardId,
8610 cardState,
8611 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008612 slot.isExtendedApduSupported(),
8613 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 }
8615 return infos;
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008618 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008619 }
8620
8621 @Override
8622 public boolean switchSlots(int[] physicalSlots) {
8623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008631 }
Jack Yu4c988042018-02-27 15:30:01 -08008632
8633 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008634 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008635 final long identity = Binder.clearCallingIdentity();
8636 try {
8637 return UiccController.getInstance().getCardIdForDefaultEuicc();
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
Pengquan Meng85728fb2018-03-12 16:31:21 -07008643 /**
goneil47ffb6e2018-04-06 15:40:58 -07008644 * A test API to reload the UICC profile.
8645 *
8646 * <p>Requires that the calling app has permission
8647 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8648 * @hide
8649 */
8650 @Override
8651 public void refreshUiccProfile(int subId) {
8652 enforceModifyPermission();
8653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
8656 Phone phone = getPhone(subId);
8657 if (phone == null) {
8658 return;
8659 }
8660 UiccCard uiccCard = phone.getUiccCard();
8661 if (uiccCard == null) {
8662 return;
8663 }
8664 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8665 if (uiccProfile == null) {
8666 return;
8667 }
8668 uiccProfile.refresh();
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 }
8673
8674 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008675 * Returns false if the mobile data is disabled by default, otherwise return true.
8676 */
8677 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008678 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008679 }
8680
8681 /**
8682 * Returns true if the data roaming is enabled by default, i.e the system property
8683 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8684 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8685 */
8686 private boolean getDefaultDataRoamingEnabled(int subId) {
8687 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008688 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008689 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008690 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8691 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8692 return isDataRoamingEnabled;
8693 }
8694
8695 /**
8696 * Returns the default network type for the given {@code subId}, if the default network type is
8697 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8698 */
8699 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008700 List<Integer> list = TelephonyProperties.default_network();
8701 int phoneId = mSubscriptionController.getPhoneId(subId);
8702 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8703 return list.get(phoneId);
8704 }
8705 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008706 }
fionaxua13278b2018-03-21 00:08:13 -07008707
8708 @Override
8709 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008710 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008711 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008712
8713 final long identity = Binder.clearCallingIdentity();
8714 try {
8715 final Phone phone = getPhone(subId);
8716 if (phone == null) {
8717 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8718 return;
8719 }
chen xueaba88a2019-03-15 13:15:10 -07008720 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8721 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008722 if (carrierPrivilegeRules == null) {
8723 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8724 } else {
8725 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8726 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008727 } finally {
8728 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008729 }
fionaxua13278b2018-03-21 00:08:13 -07008730 }
8731
8732 @Override
8733 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008734 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008735
8736 final long identity = Binder.clearCallingIdentity();
8737 try {
8738 final Phone phone = getPhone(subId);
8739 if (phone == null) {
8740 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8741 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8742 }
8743 return phone.getCarrierIdListVersion();
8744 } finally {
8745 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008746 }
fionaxua13278b2018-03-21 00:08:13 -07008747 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008748
8749 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008750 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8751 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008753 mApp, subId, callingPackage, callingFeatureId,
8754 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008755 return -1;
8756 }
8757
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008765
8766 @Override
8767 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008768 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008769 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008770 mApp, subId, "getCdmaRoamingMode");
8771
8772 final long identity = Binder.clearCallingIdentity();
8773 try {
8774 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
8777 }
8778 }
8779
8780 @Override
8781 public boolean setCdmaRoamingMode(int subId, int mode) {
8782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8783 mApp, subId, "setCdmaRoamingMode");
8784
8785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
8792
8793 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008794 public int getCdmaSubscriptionMode(int subId) {
8795 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008796 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008797 mApp, subId, "getCdmaSubscriptionMode");
8798
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8802 } finally {
8803 Binder.restoreCallingIdentity(identity);
8804 }
8805 }
8806
8807 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008808 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8810 mApp, subId, "setCdmaSubscriptionMode");
8811
8812 final long identity = Binder.clearCallingIdentity();
8813 try {
8814 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8815 } finally {
8816 Binder.restoreCallingIdentity(identity);
8817 }
8818 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008819
sqianc5eccab2018-10-19 18:46:41 -07008820 @Override
sqian8c685422019-02-22 15:55:18 -08008821 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008822 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008824 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8825 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008826 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8827 }
8828 final long identity = Binder.clearCallingIdentity();
8829 try {
sqian854d44b2018-12-12 16:48:18 -08008830 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8831 for (Phone phone: PhoneFactory.getPhones()) {
8832 if (phone.getEmergencyNumberTracker() != null
8833 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8834 emergencyNumberListInternal.put(
8835 phone.getSubId(),
8836 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8837 }
sqian11b7a0e2018-12-05 18:48:28 -08008838 }
sqian854d44b2018-12-12 16:48:18 -08008839 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
sqianc5eccab2018-10-19 18:46:41 -07008843 }
8844
8845 @Override
sqian8c685422019-02-22 15:55:18 -08008846 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008847 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008848 if (!exactMatch) {
8849 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008850 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008851 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008852 }
8853 final long identity = Binder.clearCallingIdentity();
8854 try {
sqian854d44b2018-12-12 16:48:18 -08008855 for (Phone phone: PhoneFactory.getPhones()) {
8856 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008857 && phone.getEmergencyNumberTracker()
8858 .isEmergencyNumber(number, exactMatch)) {
8859 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008860 }
sqian11b7a0e2018-12-05 18:48:28 -08008861 }
8862 return false;
8863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
8866 }
8867
sqianf4ca7ed2019-01-15 18:32:07 -08008868 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008869 * Start emergency callback mode for GsmCdmaPhone for testing.
8870 */
8871 @Override
8872 public void startEmergencyCallbackMode() {
8873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8874 "startEmergencyCallbackMode");
8875 enforceModifyPermission();
8876 final long identity = Binder.clearCallingIdentity();
8877 try {
8878 for (Phone phone : PhoneFactory.getPhones()) {
8879 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8880 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8881 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8882 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8883 gsmCdmaPhone.obtainMessage(
8884 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8885 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8886 }
8887 }
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
8893 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008894 * Update emergency number list for test mode.
8895 */
8896 @Override
8897 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8899 "updateEmergencyNumberListTestMode");
8900
8901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 for (Phone phone: PhoneFactory.getPhones()) {
8904 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8905 if (tracker != null) {
8906 tracker.executeEmergencyNumberTestModeCommand(action, num);
8907 }
8908 }
8909 } finally {
8910 Binder.restoreCallingIdentity(identity);
8911 }
8912 }
8913
8914 /**
8915 * Get the full emergency number list for test mode.
8916 */
8917 @Override
8918 public List<String> getEmergencyNumberListTestMode() {
8919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8920 "getEmergencyNumberListTestMode");
8921
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 Set<String> emergencyNumbers = new HashSet<>();
8925 for (Phone phone: PhoneFactory.getPhones()) {
8926 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8927 if (tracker != null) {
8928 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8929 emergencyNumbers.add(num.getNumber());
8930 }
8931 }
8932 }
8933 return new ArrayList<>(emergencyNumbers);
8934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
8938
chen xud6b45bd2018-10-30 22:27:10 -07008939 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008940 public int getEmergencyNumberDbVersion(int subId) {
8941 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8942
8943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 final Phone phone = getPhone(subId);
8946 if (phone == null) {
8947 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8948 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8949 }
8950 return phone.getEmergencyNumberDbVersion();
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
8953 }
8954 }
8955
8956 @Override
8957 public void notifyOtaEmergencyNumberDbInstalled() {
8958 enforceModifyPermission();
8959
8960 final long identity = Binder.clearCallingIdentity();
8961 try {
8962 for (Phone phone: PhoneFactory.getPhones()) {
8963 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8964 if (tracker != null) {
8965 tracker.updateOtaEmergencyNumberDatabase();
8966 }
8967 }
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
8970 }
8971 }
8972
8973 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008974 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008975 enforceActiveEmergencySessionPermission();
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 for (Phone phone: PhoneFactory.getPhones()) {
8980 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8981 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008982 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8983 }
8984 }
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
8989
8990 @Override
8991 public void resetOtaEmergencyNumberDbFilePath() {
8992 enforceActiveEmergencySessionPermission();
8993
8994 final long identity = Binder.clearCallingIdentity();
8995 try {
8996 for (Phone phone: PhoneFactory.getPhones()) {
8997 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8998 if (tracker != null) {
8999 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009000 }
9001 }
9002 } finally {
9003 Binder.restoreCallingIdentity(identity);
9004 }
9005 }
9006
9007 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009008 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9009 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9010 Phone phone = getPhone(subId);
9011 if (phone == null) {
9012 return null;
9013 }
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 UiccProfile profile = UiccController.getInstance()
9017 .getUiccProfileForPhone(phone.getPhoneId());
9018 if (profile != null) {
9019 return profile.getCertsFromCarrierPrivilegeAccessRules();
9020 }
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 return null;
9025 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009026
9027 /**
9028 * Enable or disable a modem stack.
9029 */
9030 @Override
9031 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9032 enforceModifyPermission();
9033
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 Phone phone = PhoneFactory.getPhone(slotIndex);
9037 if (phone == null) {
9038 return false;
9039 } else {
9040 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9041 }
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
Michelecea4cf22018-12-21 15:00:11 -08009046
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009047 /**
9048 * Whether a modem stack is enabled or not.
9049 */
9050 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009051 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9052 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009053 Phone phone = PhoneFactory.getPhone(slotIndex);
9054 if (phone == null) return false;
9055
9056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009057 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9058 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009059 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9060 }
9061
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009064 try {
9065 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9066 } catch (NoSuchElementException ex) {
9067 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9068 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
Michelecea4cf22018-12-21 15:00:11 -08009074 @Override
Michele0ea7d782019-03-19 14:58:42 -07009075 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009076 enforceModifyPermission();
9077
9078 final long identity = Binder.clearCallingIdentity();
9079 try {
9080 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009081 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009082 .commit();
9083 } finally {
9084 Binder.restoreCallingIdentity(identity);
9085 }
9086 }
9087
9088 @Override
Michele0ea7d782019-03-19 14:58:42 -07009089 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009090 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009092 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9093 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009094 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009095 }
Michelecea4cf22018-12-21 15:00:11 -08009096
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
Michele0ea7d782019-03-19 14:58:42 -07009099 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009104
Michele0ea7d782019-03-19 14:58:42 -07009105 @TelephonyManager.IsMultiSimSupportedResult
9106 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009107 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9108 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9109 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009110 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9111 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009112 }
9113 // Check if the hardware supports multisim functionality. If usage of multisim is not
9114 // supported by the modem, indicate that it is restricted.
9115 PhoneCapability staticCapability =
9116 mPhoneConfigurationManager.getStaticPhoneCapability();
9117 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009118 loge("isMultiSimSupportedInternal: no static configuration available");
9119 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009120 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009121 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009122 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9123 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009124 }
9125 // Check if support of multiple SIMs is restricted by carrier
9126 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009127 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009128 }
9129
Michele0ea7d782019-03-19 14:58:42 -07009130 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009131 }
9132
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009133 /**
9134 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009135 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9136 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9137 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009138 * @param numOfSims number of active sims we want to switch to
9139 */
9140 @Override
9141 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009142 if (numOfSims == 1) {
9143 enforceModifyPermission();
9144 } else {
9145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9146 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9147 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009148 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009149
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009150 try {
Michele30b57b22019-03-01 12:01:14 -08009151 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009152 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009153 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9154 return;
9155 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009156 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
9161
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009162 @Override
9163 public boolean isApplicationOnUicc(int subId, int appType) {
9164 enforceReadPrivilegedPermission("isApplicationOnUicc");
9165 Phone phone = getPhone(subId);
9166 if (phone == null) {
9167 return false;
9168 }
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 UiccCard uiccCard = phone.getUiccCard();
9172 if (uiccCard == null) {
9173 return false;
9174 }
9175 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9176 if (uiccProfile == null) {
9177 return false;
9178 }
9179 if (TelephonyManager.APPTYPE_SIM <= appType
9180 && appType <= TelephonyManager.APPTYPE_ISIM) {
9181 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9182 }
9183 return false;
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009189 /**
chen xub4baa772019-04-03 10:23:41 -07009190 * Get whether making changes to modem configurations will trigger reboot.
9191 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009192 */
9193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009194 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9195 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009197 mApp, subId, callingPackage, callingFeatureId,
9198 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009199 return false;
9200 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
9207 }
9208
Nathan Harold29f5f052019-02-15 13:41:57 -08009209 private void updateModemStateMetrics() {
9210 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9211 // TODO: check the state for each modem if the api is ready.
9212 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9213 }
9214
Pengquan Meng3889a572019-01-23 11:16:29 -08009215 @Override
9216 public int[] getSlotsMapping() {
9217 enforceReadPrivilegedPermission("getSlotsMapping");
9218
9219 final long identity = Binder.clearCallingIdentity();
9220 try {
9221 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9222 // All logical slots should have a mapping to a physical slot.
9223 int[] logicalSlotsMapping = new int[phoneCount];
9224 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9225 for (int i = 0; i < slotInfos.length; i++) {
9226 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9227 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9228 }
9229 }
9230 return logicalSlotsMapping;
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009235
9236 /**
9237 * Get the IRadio HAL Version
9238 */
9239 @Override
9240 public int getRadioHalVersion() {
9241 Phone phone = getDefaultPhone();
9242 if (phone == null) return -1;
9243 HalVersion hv = phone.getHalVersion();
9244 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9245 return hv.major * 100 + hv.minor;
9246 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009247
9248 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009249 * Get the current calling package name.
9250 * @return the current calling package name
9251 */
9252 @Override
9253 public String getCurrentPackageName() {
9254 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9255 }
9256
9257 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009258 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9259 * corresponding network requests on a subId.
9260 *
9261 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009262 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009263 * 2) APN is un-metered for this subscription, or
9264 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009265 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009266 *
9267 * @return whether data is allowed for a apn type.
9268 *
9269 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009270 */
9271 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009272 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009273 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9274 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009275
9276 // Now that all security checks passes, perform the operation as ourselves.
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
9279 Phone phone = getPhone(subId);
9280 if (phone == null) return false;
9281
Jack Yu41407ee2019-05-13 16:54:09 -07009282 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009283 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009290 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009291 enforceReadPrivilegedPermission("isApnMetered");
9292
9293 // Now that all security checks passes, perform the operation as ourselves.
9294 final long identity = Binder.clearCallingIdentity();
9295 try {
9296 Phone phone = getPhone(subId);
9297 if (phone == null) return true; // By default return true.
9298
Jack Yu41407ee2019-05-13 16:54:09 -07009299 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009304
9305 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009306 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9307 int subscriptionId, IBooleanConsumer resultCallback) {
9308 enforceModifyPermission();
9309 long token = Binder.clearCallingIdentity();
9310 try {
9311 Phone phone = getPhone(subscriptionId);
9312 if (phone == null) {
9313 try {
9314 if (resultCallback != null) {
9315 resultCallback.accept(false);
9316 }
9317 } catch (RemoteException e) {
9318 // ignore
9319 }
9320 return;
9321 }
9322 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9323 Pair.create(specifiers, (x) -> {
9324 try {
9325 if (resultCallback != null) {
9326 resultCallback.accept(x);
9327 }
9328 } catch (RemoteException e) {
9329 // ignore
9330 }
9331 });
9332 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9333 } finally {
9334 Binder.restoreCallingIdentity(token);
9335 }
9336 }
9337
9338 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009339 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9340 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009341 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009342 mApp, subId, "getSystemSelectionChannels");
9343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9344 final long identity = Binder.clearCallingIdentity();
9345 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009346 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9347 if (result instanceof IllegalStateException) {
9348 throw (IllegalStateException) result;
9349 }
9350 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009351 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9352 return specifiers;
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
9357
9358 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009359 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009360 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009361 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9362 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9363 if (iccRecords == null) {
9364 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9365 return false;
9366 }
9367 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9368 }
9369
9370 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009371 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9372 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009373 if (callingPackage == null) {
9374 callingPackage = getCurrentPackageName();
9375 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009376 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9377 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009378 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9379 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009380 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9381 }
9382 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9383 Intent intent = new Intent();
9384 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9385 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9386 // Bring up choose default SMS subscription dialog right now
9387 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9388 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9389 mApp.startActivity(intent);
9390 }
chen xud5ca2d52019-05-28 15:20:57 -07009391
9392 @Override
9393 public String getMmsUAProfUrl(int subId) {
9394 //TODO investigate if this API should require proper permission check in R b/133791609
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009397 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9398 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9399 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9400 return carrierUAProfUrl;
9401 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009402 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9403 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 }
9408
9409 @Override
9410 public String getMmsUserAgent(int subId) {
9411 //TODO investigate if this API should require proper permission check in R b/133791609
9412 final long identity = Binder.clearCallingIdentity();
9413 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009414 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9415 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9416 if (!TextUtils.isEmpty(carrierUserAgent)) {
9417 return carrierUserAgent;
9418 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009419 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9420 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009421 } finally {
9422 Binder.restoreCallingIdentity(identity);
9423 }
9424 }
Jack Yub07d4972019-05-28 16:12:25 -07009425
9426 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009427 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9428 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009429
Jack Yub07d4972019-05-28 16:12:25 -07009430 final long identity = Binder.clearCallingIdentity();
9431 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009432 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009433 if (phone == null) return false;
9434
Hall Liua62f5da2020-09-25 10:42:19 -07009435 switch (policy) {
9436 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9437 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9438 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9439 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9440 default:
9441 throw new IllegalArgumentException(policy + " is not a valid policy");
9442 }
Jack Yub07d4972019-05-28 16:12:25 -07009443 } finally {
9444 Binder.restoreCallingIdentity(identity);
9445 }
9446 }
9447
9448 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009449 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009450 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009451 enforceModifyPermission();
9452
changbettyd5c246e2019-12-24 15:40:37 +08009453 final long identity = Binder.clearCallingIdentity();
9454 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009455 Phone phone = getPhone(subscriptionId);
9456 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009457
Hall Liua62f5da2020-09-25 10:42:19 -07009458 switch (policy) {
9459 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9460 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9461 break;
9462 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9463 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9464 break;
9465 default:
9466 throw new IllegalArgumentException(policy + " is not a valid policy");
9467 }
changbettyd5c246e2019-12-24 15:40:37 +08009468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
9472
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009473 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009474 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009475 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9476 * otherwise.
9477 */
9478 @Override
9479 public void setCepEnabled(boolean isCepEnabled) {
9480 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9481
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9485 for (Phone phone : PhoneFactory.getPhones()) {
9486 Phone defaultPhone = phone.getImsPhone();
9487 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9488 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9489 ImsPhoneCallTracker imsPhoneCallTracker =
9490 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9491 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9492 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9493 + imsPhone.getMsisdn());
9494 }
9495 }
9496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
9499 }
allenwtsu46dcc572020-01-08 18:24:03 +08009500
9501 /**
9502 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9503 *
9504 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9505 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9506 * before being read.
9507 */
9508 @Override
9509 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9510 isCompressed) {
9511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9512 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009513 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9514 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9515 }
9516 if (!isImsAvailableOnDevice()) {
9517 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9518 "IMS not available on device.");
9519 }
9520
9521 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009522 try {
Hui Wang761a6682020-10-31 05:12:53 +00009523 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9524 } finally {
9525 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009526 }
9527 }
zoey chene02881a2019-12-30 16:11:23 +08009528
9529 @Override
9530 public boolean isIccLockEnabled(int subId) {
9531 enforceReadPrivilegedPermission("isIccLockEnabled");
9532
9533 // Now that all security checks passes, perform the operation as ourselves.
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 Phone phone = getPhone(subId);
9537 if (phone != null && phone.getIccCard() != null) {
9538 return phone.getIccCard().getIccLockEnabled();
9539 } else {
9540 return false;
9541 }
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 /**
9548 * Set the ICC pin lock enabled or disabled.
9549 *
9550 * @return an integer representing the status of IccLock enabled or disabled in the following
9551 * three cases:
9552 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9553 * successfully.
9554 * - Positive number and zero for remaining password attempts.
9555 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9556 *
9557 */
9558 @Override
9559 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9560 enforceModifyPermission();
9561
9562 Phone phone = getPhone(subId);
9563 if (phone == null) {
9564 return 0;
9565 }
9566 // Now that all security checks passes, perform the operation as ourselves.
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9570 new Pair<Boolean, String>(enabled, password), phone, null);
9571 return attemptsRemaining;
9572
9573 } catch (Exception e) {
9574 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 return 0;
9579 }
9580
9581 /**
9582 * Change the ICC password used in ICC pin lock.
9583 *
9584 * @return an integer representing the status of IccLock changed in the following three cases:
9585 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9586 * - Positive number and zero for remaining password attempts.
9587 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9588 *
9589 */
9590 @Override
9591 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9592 enforceModifyPermission();
9593
9594 Phone phone = getPhone(subId);
9595 if (phone == null) {
9596 return 0;
9597 }
9598 // Now that all security checks passes, perform the operation as ourselves.
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9602 new Pair<String, String>(oldPassword, newPassword), phone, null);
9603 return attemptsRemaining;
9604
9605 } catch (Exception e) {
9606 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 return 0;
9611 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009612
9613 /**
9614 * Request for receiving user activity notification
9615 */
9616 @Override
9617 public void requestUserActivityNotification() {
9618 if (!mNotifyUserActivity.get()
9619 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9620 mNotifyUserActivity.set(true);
9621 }
9622 }
9623
9624 /**
9625 * Called when userActivity is signalled in the power manager.
9626 * This is safe to call from any thread, with any window manager locks held or not.
9627 */
9628 @Override
9629 public void userActivity() {
9630 // ***************************************
9631 // * Inherited from PhoneWindowManager *
9632 // ***************************************
9633 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9634 // WITH ITS LOCKS HELD.
9635 //
9636 // This code must be VERY careful about the locks
9637 // it acquires.
9638 // In fact, the current code acquires way too many,
9639 // and probably has lurking deadlocks.
9640
9641 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9642 throw new SecurityException("Only the OS may call notifyUserActivity()");
9643 }
9644
9645 if (mNotifyUserActivity.getAndSet(false)) {
9646 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9647 USER_ACTIVITY_NOTIFICATION_DELAY);
9648 }
9649 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009650
9651 @Override
9652 public boolean canConnectTo5GInDsdsMode() {
9653 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9654 }
Jack Yud10cdd42020-09-28 20:28:01 -07009655
9656 @Override
9657 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9658 String callingFeatureId) {
9659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9660 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9661 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9662 }
9663
9664 Phone phone = getPhone(subId);
9665 if (phone == null) {
9666 throw new RuntimeException("phone is not available");
9667 }
9668 // Now that all security checks passes, perform the operation as ourselves.
9669 final long identity = Binder.clearCallingIdentity();
9670 try {
9671 return phone.getEquivalentHomePlmns();
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
Daniel Bright59e67312020-11-13 11:49:37 -08009676
9677 @Override
9678 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009679 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9680 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009681 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009682 if (radioInterfaceCapabilities == null) {
9683 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009684 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009685 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009686 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009687
Hui Wang641e81c2020-10-12 12:14:23 -07009688 @Override
9689 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9690 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009691 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9692 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9693 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9694 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9695 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009696 if (DBG) {
9697 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9698 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9699 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9700 }
9701
9702 if (!SubscriptionManager.isValidSubscriptionId(subId)
9703 || appType < TelephonyManager.APPTYPE_UNKNOWN
9704 || appType > TelephonyManager.APPTYPE_ISIM
9705 || nafUrl == null || securityProtocol == null || callback == null) {
9706 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9707 if (callback != null) {
9708 try {
9709 callback.onAuthenticationFailure(
9710 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9711 } catch (RemoteException exception) {
9712 log("Fail to notify onAuthenticationFailure due to " + exception);
9713 }
9714 return;
9715 }
9716 }
9717
9718 final long token = Binder.clearCallingIdentity();
9719 try {
9720 getGbaManager(subId).bootstrapAuthenticationRequest(
9721 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9722 forceBootStrapping, callback));
9723 } finally {
9724 Binder.restoreCallingIdentity(token);
9725 }
9726 }
9727
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009728 /**
9729 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9730 * requested radio power state will actually be set. See {@link
9731 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9732 *
9733 * @param subId the subscription ID of the phone requesting to set the radio power state.
9734 * @param enable {@code true} if trying to turn radio on.
9735 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9736 * false}.
9737 */
9738 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9739 Phone phone = getPhone(subId);
9740 if (phone != null) {
9741 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9742 return true;
9743 }
9744 return false;
9745 }
9746
9747 private int handleDataThrottlingRequest(int subId,
9748 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009749 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9750 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9751 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9752 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9753 throw new IllegalArgumentException("modem does not support data throttling");
9754 }
9755
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009756 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9757 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9758 if (!setRadioPowerForThermal(subId, true)) {
9759 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9760 }
9761
9762 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9763
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009764 if (isDataThrottlingSupported) {
9765 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009766 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009767 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9768 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9769 } else if (thermalMitigationResult
9770 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9771 throw new IllegalArgumentException("modem does not support data throttling");
9772 }
9773 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009774 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009775
9776 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009777 }
9778
Jack Nudelman644b91a2021-03-12 14:09:48 -08009779 private static List<String> getThermalMitigationAllowlist(Context context) {
9780 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9781 for (String pckg : context.getResources()
9782 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9783 sThermalMitigationAllowlistedPackages.add(pckg);
9784 }
9785 }
9786
9787 return sThermalMitigationAllowlistedPackages;
9788 }
9789
9790 /**
9791 * Used by shell commands to add an authorized package name for thermal mitigation.
9792 * @param packageName name of package to be allowlisted
9793 * @param context
9794 */
9795 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9796 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9797 sThermalMitigationAllowlistedPackages.add(packageName);
9798 }
9799
9800 /**
9801 * Used by shell commands to remove an authorized package name for thermal mitigation.
9802 * @param packageName name of package to remove from allowlist
9803 * @param context
9804 */
9805 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9806 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9807 sThermalMitigationAllowlistedPackages.remove(packageName);
9808 }
9809
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009810 /**
9811 * Thermal mitigation request to control functionalities at modem.
9812 *
9813 * @param subId the id of the subscription.
9814 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009815 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009816 *
9817 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9818 */
9819 @Override
9820 @ThermalMitigationResult
9821 public int sendThermalMitigationRequest(
9822 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009823 ThermalMitigationRequest thermalMitigationRequest,
9824 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009825 enforceModifyPermission();
9826
Jack Nudelman644b91a2021-03-12 14:09:48 -08009827 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9828 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9829 .contains(callingPackage)) {
9830 throw new SecurityException("Calling package must be configured in the device config. "
9831 + "calling package: " + callingPackage);
9832 }
9833
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9835 final long identity = Binder.clearCallingIdentity();
9836
9837 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9838 try {
9839 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9840 switch (thermalMitigationAction) {
9841 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9842 thermalMitigationResult =
9843 handleDataThrottlingRequest(subId,
9844 thermalMitigationRequest.getDataThrottlingRequest());
9845 break;
9846 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9847 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9848 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9849 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9850 }
9851
9852 // Ensure that radio is on. If not able to power on due to phone being
9853 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9854 if (!setRadioPowerForThermal(subId, true)) {
9855 thermalMitigationResult =
9856 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9857 break;
9858 }
9859
9860 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9861 false);
9862 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9863 break;
9864 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9865 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9866 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9867 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9868 }
9869
9870 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9871 if (registry != null) {
9872 TelephonyConnectionService service =
9873 registry.getTelephonyConnectionService();
9874 Phone phone = getPhone(subId);
9875 if (phone == null) {
9876 thermalMitigationResult =
9877 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9878 break;
9879 }
9880
9881 if (PhoneConstantConversions.convertCallState(phone.getState())
9882 != TelephonyManager.CALL_STATE_IDLE
9883 || phone.isInEmergencySmsMode() || phone.isInEcm()
9884 || (service != null && service.isEmergencyCallPending())) {
9885 String errorMessage = "Phone state is not valid. call state = "
9886 + PhoneConstantConversions.convertCallState(phone.getState())
9887 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9888 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9889 errorMessage += service == null
9890 ? " TelephonyConnectionService is null"
9891 : " isEmergencyCallPending = "
9892 + service.isEmergencyCallPending();
9893 Log.e(LOG_TAG, errorMessage);
9894 thermalMitigationResult =
9895 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9896 break;
9897 }
9898 } else {
9899 thermalMitigationResult =
9900 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9901 break;
9902 }
9903
9904 // Turn radio off. If not able to power off due to phone being unavailable,
9905 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9906 if (!setRadioPowerForThermal(subId, false)) {
9907 thermalMitigationResult =
9908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9909 break;
9910 }
9911 thermalMitigationResult =
9912 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9913 break;
9914 default:
9915 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9916 + "not exist. Requested action: " + thermalMitigationAction);
9917 }
9918 } catch (IllegalArgumentException e) {
9919 throw e;
9920 } catch (Exception e) {
9921 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9922 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926
9927 if (DBG) {
9928 log("thermalMitigationRequest returning with thermalMitigationResult: "
9929 + thermalMitigationResult);
9930 }
9931
9932 return thermalMitigationResult;
9933 }
Hui Wang641e81c2020-10-12 12:14:23 -07009934
9935 /**
9936 * Set the GbaService Package Name that Telephony will bind to.
9937 *
9938 * @param subId The sim that the GbaService is associated with.
9939 * @param packageName The name of the package to be replaced with.
9940 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9941 */
9942 @Override
9943 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9944 enforceModifyPermission();
9945
9946 final long identity = Binder.clearCallingIdentity();
9947 try {
9948 return getGbaManager(subId).overrideServicePackage(packageName);
9949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
9954 /**
9955 * Return the package name of the currently bound GbaService.
9956 *
9957 * @param subId The sim that the GbaService is associated with.
9958 * @return the package name of the GbaService configuration, null if GBA is not supported.
9959 */
9960 @Override
9961 public String getBoundGbaService(int subId) {
9962 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9963
9964 final long identity = Binder.clearCallingIdentity();
9965 try {
9966 return getGbaManager(subId).getServicePackage();
9967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 }
9971
9972 /**
9973 * Set the release time for telephony to unbind GbaService.
9974 *
9975 * @param subId The sim that the GbaService is associated with.
9976 * @param interval The release time to unbind GbaService by millisecond.
9977 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9978 */
9979 @Override
9980 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9981 enforceModifyPermission();
9982
9983 final long identity = Binder.clearCallingIdentity();
9984 try {
9985 return getGbaManager(subId).overrideReleaseTime(interval);
9986 } finally {
9987 Binder.restoreCallingIdentity(identity);
9988 }
9989 }
9990
9991 /**
9992 * Return the release time for telephony to unbind GbaService.
9993 *
9994 * @param subId The sim that the GbaService is associated with.
9995 * @return The release time to unbind GbaService by millisecond.
9996 */
9997 @Override
9998 public int getGbaReleaseTime(int subId) {
9999 enforceReadPrivilegedPermission("getGbaReleaseTime");
10000
10001 final long identity = Binder.clearCallingIdentity();
10002 try {
10003 return getGbaManager(subId).getReleaseTime();
10004 } finally {
10005 Binder.restoreCallingIdentity(identity);
10006 }
10007 }
10008
10009 private GbaManager getGbaManager(int subId) {
10010 GbaManager instance = GbaManager.getInstance(subId);
10011 if (instance == null) {
10012 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10013 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10014 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10015 }
10016 return instance;
10017 }
Hui Wang761a6682020-10-31 05:12:53 +000010018
10019 /**
10020 * indicate whether the device and the carrier can support
10021 * RCS VoLTE single registration.
10022 */
10023 @Override
10024 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010025 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10026 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10027 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10028 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010029
10030 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10031 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10032 }
10033
10034 final long identity = Binder.clearCallingIdentity();
10035 try {
10036 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10037 if (rpm != null) {
10038 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
10039 }
10040 return false;
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
10045
10046 /**
10047 * Register RCS provisioning callback.
10048 */
10049 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010050 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010051 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010052 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010053 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010054 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10055 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010056
10057 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10058 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10059 }
10060 if (!isImsAvailableOnDevice()) {
10061 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10062 "IMS not available on device.");
10063 }
10064
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010067 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010068 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -080010069 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10070 "Service not available for the subscription.");
10071 }
Hui Wang761a6682020-10-31 05:12:53 +000010072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 /**
10078 * Unregister RCS provisioning callback.
10079 */
10080 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010081 public void unregisterRcsProvisioningCallback(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(), "unregisterRcsProvisioningCallback",
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 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010099 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
10104
10105 /**
10106 * trigger RCS reconfiguration.
10107 */
10108 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010109 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10110 "triggerRcsReconfiguration",
10111 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010112
10113 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10114 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10115 }
10116 if (!isImsAvailableOnDevice()) {
10117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10118 "IMS not available on device.");
10119 }
10120
10121 final long identity = Binder.clearCallingIdentity();
10122 try {
10123 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10124 } finally {
10125 Binder.restoreCallingIdentity(identity);
10126 }
10127 }
10128
10129 /**
10130 * Provide the client configuration parameters of the RCS application.
10131 */
10132 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010133 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10134 "setRcsClientConfiguration",
10135 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010136
10137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10139 }
10140 if (!isImsAvailableOnDevice()) {
10141 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10142 "IMS not available on device.");
10143 }
10144
10145 final long identity = Binder.clearCallingIdentity();
10146
10147 try {
10148 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10149 if (configBinder == null) {
10150 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10151 } else {
10152 configBinder.setRcsClientConfiguration(rcc);
10153 }
10154 } catch (RemoteException e) {
10155 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10156 } finally {
10157 Binder.restoreCallingIdentity(identity);
10158 }
10159 }
10160
10161 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010162 * Enables or disables the test mode for RCS VoLTE single registration.
10163 */
10164 @Override
10165 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10167 "setRcsSingleRegistrationTestModeEnabled");
10168
10169 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10170 }
10171
10172 /**
10173 * Gets the test mode for RCS VoLTE single registration.
10174 */
10175 @Override
10176 public boolean getRcsSingleRegistrationTestModeEnabled() {
10177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10178 "getRcsSingleRegistrationTestModeEnabled");
10179
10180 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10181 }
10182
10183 /**
Hui Wang761a6682020-10-31 05:12:53 +000010184 * Overrides the config of RCS VoLTE single registration enabled for the device.
10185 */
10186 @Override
10187 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10188 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10189 "setDeviceSingleRegistrationEnabledOverride");
10190 enforceModifyPermission();
10191
10192 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10193 : Boolean.parseBoolean(enabledStr);
10194 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010195 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010196 }
10197
10198 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010199 * Sends a device to device communication message. Only usable via shell.
10200 * @param message message to send.
10201 * @param value message value.
10202 */
10203 @Override
10204 public void sendDeviceToDeviceMessage(int message, int value) {
10205 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010206 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010207 enforceModifyPermission();
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 TelephonyConnectionService service =
10212 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10213 if (service == null) {
10214 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10215 return;
10216 }
10217 service.sendTestDeviceToDeviceMessage(message, value);
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
10222
Tyler Gunnbabbda02021-02-10 11:05:02 -080010223 /**
10224 * Sets the specified device to device transport active.
10225 * @param transport The transport to set active.
10226 */
10227 @Override
10228 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10230 "setActiveDeviceToDeviceTransport");
10231 enforceModifyPermission();
10232
10233 final long identity = Binder.clearCallingIdentity();
10234 try {
10235 TelephonyConnectionService service =
10236 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10237 if (service == null) {
10238 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10239 return;
10240 }
10241 service.setActiveDeviceToDeviceTransport(transport);
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
Tyler Gunn92479152021-01-20 16:30:10 -080010246
10247 /**
Hui Wang761a6682020-10-31 05:12:53 +000010248 * Gets the config of RCS VoLTE single registration enabled for the device.
10249 */
10250 @Override
10251 public boolean getDeviceSingleRegistrationEnabled() {
10252 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10253 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10254 }
10255
10256 /**
10257 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10258 */
10259 @Override
10260 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10262 "setCarrierSingleRegistrationEnabledOverride");
10263 enforceModifyPermission();
10264
10265 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10266 : Boolean.parseBoolean(enabledStr);
10267 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10268 subId, enabled);
10269 }
10270
10271 /**
10272 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10273 */
10274 @Override
10275 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10276 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10277 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10278 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010279
10280 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010281 * Overrides the ims feature validation result
10282 */
10283 @Override
10284 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10285 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10286 "setImsFeatureValidationOverride");
10287
10288 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10289 : Boolean.parseBoolean(enabledStr);
10290 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10291 subId, enabled);
10292 }
10293
10294 /**
10295 * Gets the ims feature validation override value
10296 */
10297 @Override
10298 public boolean getImsFeatureValidationOverride(int subId) {
10299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10300 "getImsFeatureValidationOverride");
10301 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10302 }
10303
10304 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010305 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10306 * their mobile plan.
10307 */
10308 @Override
10309 public String getMobileProvisioningUrl() {
10310 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return getDefaultPhone().getMobileProvisioningUrl();
10314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010318
James.cf Linbcdf8b32021-01-14 16:44:13 +080010319 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010320 * Get the EAB contact from the EAB database.
10321 */
10322 @Override
10323 public String getContactFromEab(String contact) {
10324 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10325 enforceModifyPermission();
10326 final long identity = Binder.clearCallingIdentity();
10327 try {
10328 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10329 } finally {
10330 Binder.restoreCallingIdentity(identity);
10331 }
10332 }
10333
10334 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010335 * Remove the EAB contacts from the EAB database.
10336 */
10337 @Override
10338 public int removeContactFromEab(int subId, String contacts) {
10339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10340 enforceModifyPermission();
10341 final long identity = Binder.clearCallingIdentity();
10342 try {
10343 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010349 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010350 public boolean getDeviceUceEnabled() {
10351 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 return mApp.getDeviceUceEnabled();
10355 } finally {
10356 Binder.restoreCallingIdentity(identity);
10357 }
10358 }
10359
10360 @Override
10361 public void setDeviceUceEnabled(boolean isEnabled) {
10362 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 mApp.setDeviceUceEnabled(isEnabled);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
Brad Ebinger14d467f2021-02-12 06:18:28 +000010371 /**
10372 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10373 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10374 */
10375 // Used for SHELL command only right now.
10376 @Override
10377 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10378 List<String> featureTags) {
10379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10380 "addUceRegistrationOverrideShell");
10381 final long identity = Binder.clearCallingIdentity();
10382 try {
10383 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10384 new ArraySet<>(featureTags));
10385 } catch (ImsException e) {
10386 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10387 } finally {
10388 Binder.restoreCallingIdentity(identity);
10389 }
10390 }
10391
10392 /**
10393 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10394 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10395 */
10396 // Used for SHELL command only right now.
10397 @Override
10398 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10399 List<String> featureTags) {
10400 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10401 "removeUceRegistrationOverrideShell");
10402 final long identity = Binder.clearCallingIdentity();
10403 try {
10404 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10405 new ArraySet<>(featureTags));
10406 } catch (ImsException e) {
10407 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
10411 }
10412
10413 /**
10414 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10415 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10416 */
10417 // Used for SHELL command only right now.
10418 @Override
10419 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10420 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10421 "clearUceRegistrationOverrideShell");
10422 final long identity = Binder.clearCallingIdentity();
10423 try {
10424 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10425 } catch (ImsException e) {
10426 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10427 } finally {
10428 Binder.restoreCallingIdentity(identity);
10429 }
10430 }
10431
10432 /**
10433 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10434 */
10435 // Used for SHELL command only right now.
10436 @Override
10437 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10438 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10439 "getLatestRcsContactUceCapabilityShell");
10440 final long identity = Binder.clearCallingIdentity();
10441 try {
10442 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10443 } catch (ImsException e) {
10444 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 /**
10451 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10452 * device does not have an active PUBLISH.
10453 */
10454 // Used for SHELL command only right now.
10455 @Override
10456 public String getLastUcePidfXmlShell(int subId) {
10457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10458 final long identity = Binder.clearCallingIdentity();
10459 try {
10460 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10461 } catch (ImsException e) {
10462 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10463 } finally {
10464 Binder.restoreCallingIdentity(identity);
10465 }
10466 }
10467
James.cf Line8713a42021-04-29 16:04:26 +080010468 /**
10469 * Remove UCE requests cannot be sent to the network status.
10470 */
10471 // Used for SHELL command only right now.
10472 @Override
10473 public boolean removeUceRequestDisallowedStatus(int subId) {
10474 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10475 final long identity = Binder.clearCallingIdentity();
10476 try {
10477 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10478 } catch (ImsException e) {
10479 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
10484
Brad Ebinger14d467f2021-02-12 06:18:28 +000010485
James.cf Lin4b784aa2021-01-31 03:25:15 +080010486 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010487 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10488 String callingPackage) {
10489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10490 mApp, subId, "setSignalStrengthUpdateRequest");
10491
10492 final int callingUid = Binder.getCallingUid();
10493 // Verify that tha callingPackage belongs to the calling UID
10494 mApp.getSystemService(AppOpsManager.class)
10495 .checkPackage(callingUid, callingPackage);
10496
10497 validateSignalStrengthUpdateRequest(request, callingUid);
10498
10499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10502 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10503
10504 if (result instanceof IllegalStateException) {
10505 throw (IllegalStateException) result;
10506 }
10507 } finally {
10508 Binder.restoreCallingIdentity(identity);
10509 }
10510 }
10511
10512 @Override
10513 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10514 String callingPackage) {
10515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10516 mApp, subId, "clearSignalStrengthUpdateRequest");
10517
10518 final int callingUid = Binder.getCallingUid();
10519 // Verify that tha callingPackage belongs to the calling UID
10520 mApp.getSystemService(AppOpsManager.class)
10521 .checkPackage(callingUid, callingPackage);
10522
10523 final long identity = Binder.clearCallingIdentity();
10524 try {
10525 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10526 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10527
10528 if (result instanceof IllegalStateException) {
10529 throw (IllegalStateException) result;
10530 }
10531 } finally {
10532 Binder.restoreCallingIdentity(identity);
10533 }
10534 }
10535
10536 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10537 int callingUid) {
10538 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10539 // phone/system process do not have further restriction on request
10540 return;
10541 }
10542
10543 // Applications has restrictions on how to use the request:
10544 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10545 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10546 // This is not system caller which has been checked above
10547 throw new IllegalArgumentException(
10548 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10549 }
10550
10551 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10552 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10553 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10554 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10555 || info.isEnabled()) {
10556 throw new IllegalArgumentException(
10557 "Only system can set hide fields in SignalThresholdInfo");
10558 }
10559
10560 // Thresholds length for each RAN need in range. This has been validated in
10561 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10562 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10563 final int[] thresholds = info.getThresholds();
10564 Objects.requireNonNull(thresholds);
10565 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10566 || thresholds.length
10567 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10568 throw new IllegalArgumentException(
10569 "thresholds length is out of range: " + thresholds.length);
10570 }
10571 }
10572 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010573
10574 /**
10575 * Gets the current phone capability.
10576 *
10577 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10578 * @return the PhoneCapability which describes the data connection capability of modem.
10579 * It's used to evaluate possible phone config change, for example from single
10580 * SIM device to multi-SIM device.
10581 */
10582 @Override
10583 public PhoneCapability getPhoneCapability() {
10584 enforceReadPrivilegedPermission("getPhoneCapability");
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10588 } finally {
10589 Binder.restoreCallingIdentity(identity);
10590 }
10591 }
Michele Berionne5e411512020-11-13 02:36:59 +000010592
10593 /**
10594 * Prepare TelephonyManager for an unattended reboot. The reboot is
10595 * required to be done shortly after the API is invoked.
10596 */
10597 @Override
10598 @TelephonyManager.PrepareUnattendedRebootResult
10599 public int prepareForUnattendedReboot() {
10600 enforceRebootPermission();
10601
10602 final long identity = Binder.clearCallingIdentity();
10603 try {
10604 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010609
10610 /**
10611 * Request to get the current slicing configuration including URSP rules and
10612 * NSSAIs (configured, allowed and rejected).
10613 *
10614 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10615 */
10616 @Override
10617 public void getSlicingConfig(ResultReceiver callback) {
10618 enforceReadPrivilegedPermission("getSlicingConfig");
10619
10620 final long identity = Binder.clearCallingIdentity();
10621 try {
10622 Phone phone = getDefaultPhone();
10623 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10624 } finally {
10625 Binder.restoreCallingIdentity(identity);
10626 }
10627 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010628}