blob: 03b0be98c96364048bf531aec685a8037b44d364 [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;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700344 private static final int CMD_ENABLE_VONR = 113;
345 private static final int EVENT_ENABLE_VONR_DONE = 114;
346 private static final int CMD_IS_VONR_ENABLED = 115;
347 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800349 // Parameters of select command.
350 private static final int SELECT_COMMAND = 0xA4;
351 private static final int SELECT_P1 = 0x04;
352 private static final int SELECT_P2 = 0;
353 private static final int SELECT_P3 = 0x10;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /** The singleton instance. */
356 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800357 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800361 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700362 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700364 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800366 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700368 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800369 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 /** User Activity */
372 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
374
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700375 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
376
Derek Tan97ebb422014-09-05 16:55:38 -0700377 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
378 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800379 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800380 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700381
Michelecea4cf22018-12-21 15:00:11 -0800382 // String to store multi SIM allowed
383 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
384
Derek Tan740e1672017-06-27 14:56:27 -0700385 // The AID of ISD-R.
386 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
387
yinxub1bed742017-04-17 11:45:04 -0700388 private NetworkScanRequestTracker mNetworkScanRequestTracker;
389
David Kelly5e06a7f2018-03-12 14:10:59 +0000390 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
391 private static final int MANUFACTURER_CODE_LENGTH = 8;
392
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800393 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800394 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395
Derek Tan89e89d42014-07-08 17:00:10 -0700396 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 * Experiment flag to enable erase modem config on reset network, default value is false
398 */
399 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
400 "reset_network_erase_modem_config_enabled";
401
Rambo Wang0f050d82021-02-12 11:43:36 -0800402 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
403
Naina Nallurid63128d2019-09-17 14:10:30 -0700404 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class IccAPDUArgument {
408 public int channel, cla, command, p1, p2, p3;
409 public String data;
410
411 public IccAPDUArgument(int channel, int cla, int command,
412 int p1, int p2, int p3, String data) {
413 this.channel = channel;
414 this.cla = cla;
415 this.command = command;
416 this.p1 = p1;
417 this.p2 = p2;
418 this.p3 = p3;
419 this.data = data;
420 }
421 }
422
423 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class ManualNetworkSelectionArgument {
427 public OperatorInfo operatorInfo;
428 public boolean persistSelection;
429
430 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
431 this.operatorInfo = operatorInfo;
432 this.persistSelection = persistSelection;
433 }
434 }
435
436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
438 * request after sending. The main thread will notify the request when it is complete.
439 */
440 private static final class MainThreadRequest {
441 /** The argument to use for the request */
442 public Object argument;
443 /** The result of the request that is run on the main thread */
444 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 // The subscriber id that this request applies to. Defaults to
446 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
447 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 // In cases where subId is unavailable, the caller needs to specify the phone.
450 public Phone phone;
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 public WorkSource workSource;
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 public MainThreadRequest(Object argument) {
455 this.argument = argument;
456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457
Nathan Harold92bed182018-10-12 18:16:49 -0700458 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
459 this.argument = argument;
460 if (phone != null) {
461 this.phone = phone;
462 }
463 this.workSource = workSource;
464 }
465
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 if (subId != null) {
469 this.subId = subId;
470 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800475 private static final class IncomingThirdPartyCallArgs {
476 public final ComponentName component;
477 public final String callId;
478 public final String callerDisplayName;
479
480 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
481 String callerDisplayName) {
482 this.component = component;
483 this.callId = callId;
484 this.callerDisplayName = callerDisplayName;
485 }
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
489 * A handler that processes messages on the main thread in the phone process. Since many
490 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
491 * inbound binder threads to the main thread in the phone process. The Binder thread
492 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
493 * on, which will be notified when the operation completes and will contain the result of the
494 * request.
495 *
496 * <p>If a MainThreadRequest object is provided in the msg.obj field,
497 * note that request.result must be set to something non-null for the calling thread to
498 * unblock.
499 */
500 private final class MainThreadHandler extends Handler {
501 @Override
502 public void handleMessage(Message msg) {
503 MainThreadRequest request;
504 Message onCompleted;
505 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800508 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
510 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 case CMD_HANDLE_USSD_REQUEST: {
512 request = (MainThreadRequest) msg.obj;
513 final Phone phone = getPhoneFromRequest(request);
514 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
515 String ussdRequest = ussdObject.first;
516 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 if (!isUssdApiAllowed(request.subId)) {
519 // Carrier does not support use of this API, return failure.
520 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
521 UssdResponse response = new UssdResponse(ussdRequest, null);
522 Bundle returnData = new Bundle();
523 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
524 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 request.result = true;
527 notifyRequester(request);
528 return;
529 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700530
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 try {
532 request.result = phone != null
533 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
534 } catch (CallStateException cse) {
535 request.result = false;
536 }
537 // Wake up the requesting thread
538 notifyRequester(request);
539 break;
pkanwar32d516d2016-10-14 19:37:38 -0700540 }
541
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 final Phone phone = getPhoneFromRequest(request);
545 request.result = phone != null ?
546 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
547 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduLogicalChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
563 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 iccArgument.channel, iccArgument.cla, iccArgument.command,
566 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
578 if (ar.result == null) {
579 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800580 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800582 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
584 loge("iccTransmitApduLogicalChannel: Unknown exception");
585 }
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
592 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (uiccCard == null) {
595 loge("iccTransmitApduBasicChannel: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
600 request);
601 uiccCard.iccTransmitApduBasicChannel(
602 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
603 iccArgument.p3, iccArgument.data, onCompleted);
604 }
605 break;
606
607 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
612 } else {
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("iccTransmitApduBasicChannel: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("iccTransmitApduBasicChannel: CommandException: " +
618 ar.exception);
619 } else {
620 loge("iccTransmitApduBasicChannel: Unknown exception");
621 }
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
626 case CMD_EXCHANGE_SIM_IO:
627 request = (MainThreadRequest) msg.obj;
628 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (uiccCard == null) {
631 loge("iccExchangeSimIO: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
636 request);
637 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
638 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
639 iccArgument.data, onCompleted);
640 }
641 break;
642
643 case EVENT_EXCHANGE_SIM_IO_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
649 request.result = new IccIoResult(0x6f, 0, (byte[])null);
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 break;
653
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 case CMD_SEND_ENVELOPE:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("sendEnvelopeWithStatus: No UICC");
659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
663 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
667 case EVENT_SEND_ENVELOPE_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 request.result = new IccIoResult(0x6F, 0, (byte[])null);
674 if (ar.result == null) {
675 loge("sendEnvelopeWithStatus: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("sendEnvelopeWithStatus: CommandException: " +
678 ar.exception);
679 } else {
680 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
681 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 case CMD_OPEN_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800692 request.result = new IccOpenLogicalChannelResponse(-1,
693 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800697 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
698 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case EVENT_OPEN_CHANNEL_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 int[] result = (int[]) ar.result;
708 int channelId = result[0];
709 byte[] selectResponse = null;
710 if (result.length > 1) {
711 selectResponse = new byte[result.length - 1];
712 for (int i = 1; i < result.length; ++i) {
713 selectResponse[i - 1] = (byte) result[i];
714 }
715 }
716 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 if (ar.result == null) {
720 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 if (ar.exception != null) {
723 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
724 }
725
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700727 if (ar.exception instanceof CommandException) {
728 CommandException.Error error =
729 ((CommandException) (ar.exception)).getCommandError();
730 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700731 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700732 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(
737 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700739 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case CMD_CLOSE_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800745 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 if (uiccCard == null) {
747 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900748 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
752 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800757 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
758 break;
759
760 case CMD_NV_READ_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800770 if (ar.exception == null && ar.result != null) {
771 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 request.result = "";
774 if (ar.result == null) {
775 loge("nvReadItem: Empty response");
776 } else if (ar.exception instanceof CommandException) {
777 loge("nvReadItem: CommandException: " +
778 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800780 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
Jake Hambye994d462014-02-03 13:10:13 -0800786 case CMD_NV_WRITE_ITEM:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
789 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700791 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_ITEM_DONE:
795 handleNullReturnEvent(msg, "nvWriteItem");
796 break;
797
798 case CMD_NV_WRITE_CDMA_PRL:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
804 case EVENT_NV_WRITE_CDMA_PRL_DONE:
805 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800809 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
chen xu6dac5ab2018-10-26 17:39:23 -0700814 case EVENT_RESET_MODEM_CONFIG_DONE:
815 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
Sooraj Sasindran37444802020-08-11 10:40:43 -0700818 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
821 request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
825 } else {
826 loge("isNRDualConnectivityEnabled: No phone object");
827 request.result = false;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 // request.result must be set to something non-null
840 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700841 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 request.result = ar.result;
843 } else {
844 request.result = false;
845 }
846 if (ar.result == null) {
847 loge("isNRDualConnectivityEnabled: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("isNRDualConnectivityEnabled: CommandException: "
850 + ar.exception);
851 } else {
852 loge("isNRDualConnectivityEnabled: Unknown exception");
853 }
854 }
855 notifyRequester(request);
856 break;
857
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700858 case CMD_IS_VONR_ENABLED: {
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
861 request);
862 Phone phone = getPhoneFromRequest(request);
863 if (phone != null) {
864 phone.isVoNrEnabled(onCompleted, request.workSource);
865 } else {
866 loge("isVoNrEnabled: No phone object");
867 request.result = false;
868 notifyRequester(request);
869 }
870 break;
871 }
872
873 case EVENT_IS_VONR_ENABLED_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 // request.result must be set to something non-null
880 // for the calling thread to unblock
881 if (ar.result != null) {
882 request.result = ar.result;
883 } else {
884 request.result = false;
885 }
886 if (ar.result == null) {
887 loge("isVoNrEnabled: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("isVoNrEnabled: CommandException: "
890 + ar.exception);
891 } else {
892 loge("isVoNrEnabled: Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
904 request.workSource);
905 } else {
906 loge("enableNrDualConnectivity: No phone object");
907 request.result =
908 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
909 notifyRequester(request);
910 }
911 break;
912 }
913
914 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null) {
918 request.result =
919 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
920 } else {
921 request.result =
922 TelephonyManager
923 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
924 if (ar.exception instanceof CommandException) {
925 CommandException.Error error =
926 ((CommandException) (ar.exception)).getCommandError();
927 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
928 request.result =
929 TelephonyManager
930 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000931 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700935 }
936 loge("enableNrDualConnectivity" + ": CommandException: "
937 + ar.exception);
938 } else {
939 loge("enableNrDualConnectivity" + ": Unknown exception");
940 }
941 }
942 notifyRequester(request);
943 break;
944 }
945
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700946 case CMD_ENABLE_VONR: {
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
952 request.workSource);
953 } else {
954 loge("setVoNrEnabled: No phone object");
955 request.result =
956 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_ENABLE_VONR_DONE: {
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
967 } else {
968 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
973 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
975 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
976 } else {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
978 }
979 loge("setVoNrEnabled" + ": CommandException: "
980 + ar.exception);
981 } else {
982 loge("setVoNrEnabled" + ": Unknown exception");
983 }
984 }
985 notifyRequester(request);
986 break;
987 }
988
SongFerngWang3ef3e072020-12-21 16:41:52 +0800989 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800990 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
992 request);
993 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 break;
995
SongFerngWang3ef3e072020-12-21 16:41:52 +0800996 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result; // Integer
1001 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001005 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001006 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: CommandException: "
1009 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 }
1013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1020 request);
1021 Pair<Integer, Long> reasonWithNetworkTypes =
1022 (Pair<Integer, Long>) request.argument;
1023 getPhoneFromRequest(request).setAllowedNetworkTypes(
1024 reasonWithNetworkTypes.first,
1025 reasonWithNetworkTypes.second,
1026 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 break;
1028
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1030 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001033 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1034 request = (MainThreadRequest)msg.obj;
1035 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001036 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 break;
1038
1039 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1040 ar = (AsyncResult)msg.obj;
1041 request = (MainThreadRequest)ar.userObj;
1042 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001044 break;
1045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001046 case CMD_SET_VOICEMAIL_NUMBER:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1049 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001050 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1051 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 break;
1053
1054 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1055 handleNullReturnEvent(msg, "setVoicemailNumber");
1056 break;
1057
Stuart Scott54788802015-03-30 13:18:01 -07001058 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1061 request);
1062 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1063 break;
1064
1065 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1066 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1067 break;
1068
Shishir Agrawal302c8692015-06-19 13:49:39 -07001069 case CMD_PERFORM_NETWORK_SCAN:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1072 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1073 break;
1074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1079 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1080 request.argument;
1081 int callForwardingReason = args.first;
1082 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 TelephonyManager.CallForwardingInfoCallback callback =
1089 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1090 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001092 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1094 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1095 // Service Class is a bit mask per 3gpp 27.007. Search for
1096 // any service for voice call.
1097 if ((callForwardInfo.serviceClass
1098 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001099 callForwardingInfo = new CallForwardingInfo(true,
1100 callForwardInfo.reason,
1101 callForwardInfo.number,
1102 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
1104 }
1105 }
1106 // Didn't find a call forward info for voice call.
1107 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001108 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1109 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001110 }
Hall Liu27d24262020-09-18 19:04:59 -07001111 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 } else {
1113 if (ar.result == null) {
1114 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1115 }
1116 if (ar.exception != null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1118 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001119 int errorCode = TelephonyManager
1120 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001125 errorCode = TelephonyManager
1126 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001141 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001142 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1143 request.argument).first;
1144 request.phone.setCallForwardingOption(
1145 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001146 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001147 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001148 callForwardingInfoToSet.getReason(),
1149 callForwardingInfoToSet.getNumber(),
1150 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1151 break;
Hall Liu27d24262020-09-18 19:04:59 -07001152 }
Shuo Qian4a594052020-01-23 11:59:30 -08001153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 Consumer<Integer> callback =
1158 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1159 request.argument).second;
1160 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001162 int errorCode = TelephonyManager.CallForwardingInfoCallback
1163 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001164 if (ar.exception instanceof CommandException) {
1165 CommandException.Error error =
1166 ((CommandException) (ar.exception)).getCommandError();
1167 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001168 errorCode = TelephonyManager.CallForwardingInfoCallback
1169 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001170 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
1174 }
1175 callback.accept(errorCode);
1176 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001177 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181
Hall Liu27d24262020-09-18 19:04:59 -07001182 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1185 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1186 break;
Hall Liu27d24262020-09-18 19:04:59 -07001187 }
Shuo Qian4a594052020-01-23 11:59:30 -08001188
Hall Liu27d24262020-09-18 19:04:59 -07001189 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001192 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1194 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001195 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 // Service Class is a bit mask per 3gpp 27.007.
1197 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 if (callForwardResults.length > 1
1199 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001200 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001202 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1203 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001205 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 }
1207 } else {
1208 if (ar.result == null) {
1209 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1210 }
1211 if (ar.exception != null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1213 }
1214 if (ar.exception instanceof CommandException) {
1215 CommandException.Error error =
1216 ((CommandException) (ar.exception)).getCommandError();
1217 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1218 callForwardingStatus =
1219 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1220 }
1221 }
1222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 break;
Hall Liu27d24262020-09-18 19:04:59 -07001225 }
Shuo Qian4a594052020-01-23 11:59:30 -08001226
Hall Liu27d24262020-09-18 19:04:59 -07001227 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001230 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1231 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1239 Consumer<Integer> callback =
1240 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1247 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1248 } else {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1250 }
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1256 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001260 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 CellNetworkScanResult cellScanResult;
1264 if (ar.exception == null && ar.result != null) {
1265 cellScanResult = new CellNetworkScanResult(
1266 CellNetworkScanResult.STATUS_SUCCESS,
1267 (List<OperatorInfo>) ar.result);
1268 } else {
1269 if (ar.result == null) {
1270 loge("getCellNetworkScanResults: Empty response");
1271 }
1272 if (ar.exception != null) {
1273 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1274 }
1275 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1280 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1281 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1283 }
1284 }
1285 cellScanResult = new CellNetworkScanResult(errorCode, null);
1286 }
1287 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001289 break;
1290
1291 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1292 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001293 ManualNetworkSelectionArgument selArg =
1294 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001295 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1296 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1298 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 break;
1300
1301 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null) {
1305 request.result = true;
1306 } else {
1307 request.result = false;
1308 loge("setNetworkSelectionModeManual " + ar.exception);
1309 }
1310 notifyRequester(request);
1311 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001314 case CMD_GET_MODEM_ACTIVITY_INFO:
1315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001317 if (defaultPhone != null) {
1318 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001319 } else {
1320 ResultReceiver result = (ResultReceiver) request.argument;
1321 Bundle bundle = new Bundle();
1322 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001323 new ModemActivityInfo(0, 0, 0,
1324 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001325 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001326 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001327 break;
1328
Hall Liud0f208c2020-10-14 16:54:44 -07001329 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001332 ResultReceiver result = (ResultReceiver) request.argument;
1333
Hall Liud0f208c2020-10-14 16:54:44 -07001334 ModemActivityInfo ret = null;
1335 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001337 // Update the last modem activity info and the result of the request.
1338 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1339 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001340 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 int[] txTimeMs = info.getTransmitTimeMillis();
1342 int[] lastModemTxTimeMs = mLastModemActivityInfo
1343 .getTransmitTimeMillis();
1344 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1345 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1346 }
Hall Liu49656c02020-10-09 19:00:11 -07001347 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1349 + mLastModemActivityInfo.getSleepTimeMillis());
1350 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1351 + mLastModemActivityInfo.getIdleTimeMillis());
1352 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1353 mLastModemActivityInfo.setReceiveTimeMillis(
1354 info.getReceiveTimeMillis()
1355 + mLastModemActivityInfo.getReceiveTimeMillis());
1356 }
Hall Liu49656c02020-10-09 19:00:11 -07001357 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 mLastModemActivityInfo.getSleepTimeMillis(),
1359 mLastModemActivityInfo.getIdleTimeMillis(),
1360 mLastModemActivityInfo.getTransmitTimeMillis(),
1361 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 } else {
1363 if (ar.result == null) {
1364 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001365 error = TelephonyManager.ModemActivityInfoException
1366 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001367 } else if (ar.exception instanceof CommandException) {
1368 loge("queryModemActivityInfo: CommandException: " +
1369 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001370 error = TelephonyManager.ModemActivityInfoException
1371 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001372 } else {
1373 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 }
1377 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001378 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001379 if (ret != null) {
1380 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1381 } else {
1382 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1383 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001385 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001387 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388
Meng Wang1a7c35a2016-05-05 20:56:15 -07001389 case CMD_SET_ALLOWED_CARRIERS:
1390 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001391 CarrierRestrictionRules argument =
1392 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001394 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 break;
1396
1397 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception == null && ar.result != null) {
1401 request.result = ar.result;
1402 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001403 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1404 if (ar.exception instanceof CommandException) {
1405 loge("setAllowedCarriers: CommandException: " + ar.exception);
1406 CommandException.Error error =
1407 ((CommandException) (ar.exception)).getCommandError();
1408 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1409 request.result =
1410 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1411 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 } else {
1413 loge("setAllowedCarriers: Unknown exception");
1414 }
1415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case CMD_GET_ALLOWED_CARRIERS:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001422 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001423 break;
1424
1425 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null && ar.result != null) {
1429 request.result = ar.result;
1430 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001431 request.result = new IllegalStateException(
1432 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 if (ar.result == null) {
1434 loge("getAllowedCarriers: Empty response");
1435 } else if (ar.exception instanceof CommandException) {
1436 loge("getAllowedCarriers: CommandException: " +
1437 ar.exception);
1438 } else {
1439 loge("getAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
Nathan Haroldb3014052017-01-25 15:57:32 -08001445 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null && ar.result != null) {
1449 request.result = ar.result;
1450 } else {
1451 request.result = new IllegalArgumentException(
1452 "Failed to retrieve Forbidden Plmns");
1453 if (ar.result == null) {
1454 loge("getForbiddenPlmns: Empty response");
1455 } else {
1456 loge("getForbiddenPlmns: Unknown exception");
1457 }
1458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001459 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001460 break;
1461
1462 case CMD_GET_FORBIDDEN_PLMNS:
1463 request = (MainThreadRequest) msg.obj;
1464 uiccCard = getUiccCardFromRequest(request);
1465 if (uiccCard == null) {
1466 loge("getForbiddenPlmns() UiccCard is null");
1467 request.result = new IllegalArgumentException(
1468 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001470 break;
1471 }
1472 Integer appType = (Integer) request.argument;
1473 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1474 if (uiccApp == null) {
1475 loge("getForbiddenPlmns() no app with specified type -- "
1476 + appType);
1477 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001479 break;
1480 } else {
1481 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1482 + " specified type -- " + appType);
1483 }
1484 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1485 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1486 onCompleted);
1487 break;
1488
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 case CMD_SWITCH_SLOTS:
1490 request = (MainThreadRequest) msg.obj;
1491 int[] physicalSlots = (int[]) request.argument;
1492 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1493 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1494 break;
1495
1496 case EVENT_SWITCH_SLOTS_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
1501 break;
1502 case CMD_GET_NETWORK_SELECTION_MODE:
1503 request = (MainThreadRequest) msg.obj;
1504 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1505 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1506 break;
1507
1508 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception != null) {
1512 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1513 } else {
1514 int mode = ((int[]) ar.result)[0];
1515 if (mode == 0) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1517 } else {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1519 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_CDMA_ROAMING_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1526 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1527 break;
1528 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception != null) {
1532 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1533 } else {
1534 request.result = ((int[]) ar.result)[0];
1535 }
1536 notifyRequester(request);
1537 break;
1538 case CMD_SET_CDMA_ROAMING_MODE:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1541 int mode = (int) request.argument;
1542 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1543 break;
1544 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 request.result = ar.exception == null;
1548 notifyRequester(request);
1549 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001550 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1553 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1554 break;
1555 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception != null) {
1559 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1560 } else {
1561 request.result = ((int[]) ar.result)[0];
1562 }
1563 notifyRequester(request);
1564 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1568 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001569 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1570 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 break;
1572 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = ar.exception == null;
1576 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001577 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001578 case CMD_GET_ALL_CELL_INFO:
1579 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001581 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 case EVENT_GET_ALL_CELL_INFO_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001586 // If a timeout occurs, the response will be null
1587 request.result = (ar.exception == null && ar.result != null)
1588 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001589 synchronized (request) {
1590 request.notifyAll();
1591 }
1592 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001593 case CMD_REQUEST_CELL_INFO_UPDATE:
1594 request = (MainThreadRequest) msg.obj;
1595 request.phone.requestCellInfoUpdate(request.workSource,
1596 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1597 break;
1598 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1602 try {
1603 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001604 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001605 cb.onError(
1606 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1607 ar.exception.getClass().getName(),
1608 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001611 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else {
1613 // use the result as returned
1614 cb.onCellInfo((List<CellInfo>) ar.result);
1615 }
1616 } catch (RemoteException re) {
1617 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1618 }
1619 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001620 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001621 request = (MainThreadRequest) msg.obj;
1622 WorkSource ws = (WorkSource) request.argument;
1623 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001624 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001626 }
1627 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null) {
1631 request.result = ar.result;
1632 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001633 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001634 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001635 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 }
1637
1638 synchronized (request) {
1639 request.notifyAll();
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 }
chen xu6dac5ab2018-10-26 17:39:23 -07001643 case CMD_MODEM_REBOOT:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001647 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001648 case EVENT_CMD_MODEM_REBOOT_DONE:
1649 handleNullReturnEvent(msg, "rebootModem");
1650 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001651 case CMD_REQUEST_ENABLE_MODEM:
1652 request = (MainThreadRequest) msg.obj;
1653 boolean enable = (boolean) request.argument;
1654 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001655 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001656 PhoneConfigurationManager.getInstance()
1657 .enablePhone(request.phone, enable, onCompleted);
1658 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001659 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001663 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001664 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 if ((boolean) request.result) {
1666 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1667 updateModemStateMetrics();
1668 } else {
1669 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1670 + ar.exception);
1671 }
1672 notifyRequester(request);
1673 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001674 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001675 case CMD_GET_MODEM_STATUS:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1678 PhoneConfigurationManager.getInstance()
1679 .getPhoneStatusFromModem(request.phone, onCompleted);
1680 break;
1681 case EVENT_GET_MODEM_STATUS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 int id = request.phone.getPhoneId();
1685 if (ar.exception == null && ar.result != null) {
1686 request.result = ar.result;
1687 //update the cache as modem status has changed
1688 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1689 (boolean) request.result);
1690 } else {
1691 // Return true if modem status cannot be retrieved. For most cases,
1692 // modem status is on. And for older version modems, GET_MODEM_STATUS
1693 // and disable modem are not supported. Modem is always on.
1694 // TODO: this should be fixed in R to support a third
1695 // status UNKNOWN b/131631629
1696 request.result = true;
1697 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1698 + ar.exception);
1699 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001700 notifyRequester(request);
1701 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001702 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1705 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1706 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1707 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1708 break;
1709 }
1710 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1714 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1715 args.second.accept(ar.exception == null);
1716 notifyRequester(request);
1717 break;
1718 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001719 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1722 Phone phone = getPhoneFromRequest(request);
1723 if (phone != null) {
1724 phone.getSystemSelectionChannels(onCompleted);
1725 } else {
1726 loge("getSystemSelectionChannels: No phone object");
1727 request.result = new ArrayList<RadioAccessSpecifier>();
1728 notifyRequester(request);
1729 }
1730 break;
1731 }
1732 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null && ar.result != null) {
1736 request.result = ar.result;
1737 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001738 request.result = new IllegalStateException(
1739 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 if (ar.result == null) {
1741 loge("getSystemSelectionChannels: Empty response");
1742 } else {
1743 loge("getSystemSelectionChannels: Unknown exception");
1744 }
1745 }
1746 notifyRequester(request);
1747 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001748 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null && ar.result != null) {
1752 request.result = ar.result;
1753 } else {
1754 request.result = -1;
1755 loge("Failed to set Forbidden Plmns");
1756 if (ar.result == null) {
1757 loge("setForbidenPlmns: Empty response");
1758 } else if (ar.exception != null) {
1759 loge("setForbiddenPlmns: Exception: " + ar.exception);
1760 request.result = -1;
1761 } else {
1762 loge("setForbiddenPlmns: Unknown exception");
1763 }
1764 }
1765 notifyRequester(request);
1766 break;
1767 case CMD_SET_FORBIDDEN_PLMNS:
1768 request = (MainThreadRequest) msg.obj;
1769 uiccCard = getUiccCardFromRequest(request);
1770 if (uiccCard == null) {
1771 loge("setForbiddenPlmns: UiccCard is null");
1772 request.result = -1;
1773 notifyRequester(request);
1774 break;
1775 }
1776 Pair<Integer, List<String>> setFplmnsArgs =
1777 (Pair<Integer, List<String>>) request.argument;
1778 appType = setFplmnsArgs.first;
1779 List<String> fplmns = setFplmnsArgs.second;
1780 uiccApp = uiccCard.getApplicationByType(appType);
1781 if (uiccApp == null) {
1782 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1783 request.result = -1;
1784 loge("Failed to get UICC App");
1785 notifyRequester(request);
1786 } else {
1787 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1788 ((SIMRecords) uiccApp.getIccRecords())
1789 .setForbiddenPlmns(onCompleted, fplmns);
1790 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001791 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001792 case CMD_ERASE_MODEM_CONFIG:
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1795 defaultPhone.eraseModemConfig(onCompleted);
1796 break;
1797 case EVENT_ERASE_MODEM_CONFIG_DONE:
1798 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001799 break;
zoey chene02881a2019-12-30 16:11:23 +08001800
Kai Shif70f46f2021-03-03 13:59:46 -08001801 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1802 request = (MainThreadRequest) msg.obj;
1803 request.result = defaultPhone.eraseDataInSharedPreferences();
1804 notifyRequester(request);
1805 break;
1806
zoey chene02881a2019-12-30 16:11:23 +08001807 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1810 Pair<String, String> changed = (Pair<String, String>) request.argument;
1811 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1812 changed.first, changed.second, onCompleted);
1813 break;
1814 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null) {
1818 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001819 // If the operation is successful, update the PIN storage
1820 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1821 int phoneId = getPhoneFromRequest(request).getPhoneId();
1822 UiccController.getInstance().getPinStorage()
1823 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001824 } else {
1825 request.result = msg.arg1;
1826 }
1827 notifyRequester(request);
1828 break;
1829
Michele Berionne5e411512020-11-13 02:36:59 +00001830 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1833 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1835 enabled.first, enabled.second, onCompleted);
1836 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001837 }
zoey chene02881a2019-12-30 16:11:23 +08001838 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null) {
1842 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 // If the operation is successful, update the PIN storage
1844 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1845 int phoneId = getPhoneFromRequest(request).getPhoneId();
1846 if (enabled.first) {
1847 UiccController.getInstance().getPinStorage()
1848 .storePin(enabled.second, phoneId);
1849 } else {
1850 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1851 }
zoey chene02881a2019-12-30 16:11:23 +08001852 } else {
1853 request.result = msg.arg1;
1854 }
Michele Berionne5e411512020-11-13 02:36:59 +00001855
1856
zoey chene02881a2019-12-30 16:11:23 +08001857 notifyRequester(request);
1858 break;
1859
Peter Wangdafb9ac2020-01-15 14:13:38 -08001860 case MSG_NOTIFY_USER_ACTIVITY:
1861 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001862 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001863 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1864 getDefaultPhone().getContext().sendBroadcastAsUser(
1865 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1866 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001867
1868 case CMD_SET_DATA_THROTTLING: {
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1871 DataThrottlingRequest dataThrottlingRequest =
1872 (DataThrottlingRequest) request.argument;
1873 Phone phone = getPhoneFromRequest(request);
1874 if (phone != null) {
1875 phone.setDataThrottling(onCompleted,
1876 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1877 dataThrottlingRequest.getCompletionDurationMillis());
1878 } else {
1879 loge("setDataThrottling: No phone object");
1880 request.result =
1881 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1882 notifyRequester(request);
1883 }
1884
1885 break;
1886 }
1887 case EVENT_SET_DATA_THROTTLING_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890
1891 if (ar.exception == null) {
1892 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1893 } else if (ar.exception instanceof CommandException) {
1894 loge("setDataThrottling: CommandException: " + ar.exception);
1895 CommandException.Error error =
1896 ((CommandException) (ar.exception)).getCommandError();
1897
1898 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1899 request.result = TelephonyManager
1900 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1901 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1902 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001903 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1904 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001905 } else {
1906 request.result =
1907 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1908 }
1909 } else {
1910 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1911 }
1912 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1913 notifyRequester(request);
1914 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001915
1916 case CMD_SET_SIM_POWER: {
1917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1919 request = (MainThreadRequest) msg.obj;
1920 int stateToSet =
1921 ((Pair<Integer, IIntegerConsumer>)
1922 request.argument).first;
1923 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1924 break;
1925 }
1926 case EVENT_SET_SIM_POWER_DONE: {
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 IIntegerConsumer callback =
1930 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1931 if (ar.exception != null) {
1932 loge("setSimPower exception: " + ar.exception);
1933 int errorCode = TelephonyManager.CallForwardingInfoCallback
1934 .RESULT_ERROR_UNKNOWN;
1935 if (ar.exception instanceof CommandException) {
1936 CommandException.Error error =
1937 ((CommandException) (ar.exception)).getCommandError();
1938 if (error == CommandException.Error.SIM_ERR) {
1939 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1940 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1941 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1942 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1944 } else {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1946 }
1947 }
1948 try {
1949 callback.accept(errorCode);
1950 } catch (RemoteException e) {
1951 // Ignore if the remote process is no longer available to call back.
1952 Log.w(LOG_TAG, "setSimPower: callback not available.");
1953 }
1954 } else {
1955 try {
1956 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1957 } catch (RemoteException e) {
1958 // Ignore if the remote process is no longer available to call back.
1959 Log.w(LOG_TAG, "setSimPower: callback not available.");
1960 }
1961 }
1962 break;
1963 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001964 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1965 request = (MainThreadRequest) msg.obj;
1966
1967 final Phone phone = getPhoneFromRequest(request);
1968 if (phone == null || phone.getServiceStateTracker() == null) {
1969 request.result = new IllegalStateException("Phone or SST is null");
1970 notifyRequester(request);
1971 break;
1972 }
1973
1974 Pair<Integer, SignalStrengthUpdateRequest> pair =
1975 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1976 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1977 request);
1978 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1979 request.subId, pair.first /*callingUid*/,
1980 pair.second /*request*/, onCompleted);
1981 break;
1982 }
1983 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 // request.result will be the exception of ar if present, true otherwise.
1987 // Be cautious not to leave result null which will wait() forever
1988 request.result = ar.exception != null ? ar.exception : true;
1989 notifyRequester(request);
1990 break;
1991 }
1992 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1993 request = (MainThreadRequest) msg.obj;
1994
1995 Phone phone = getPhoneFromRequest(request);
1996 if (phone == null || phone.getServiceStateTracker() == null) {
1997 request.result = new IllegalStateException("Phone or SST is null");
1998 notifyRequester(request);
1999 break;
2000 }
2001
2002 Pair<Integer, SignalStrengthUpdateRequest> pair =
2003 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2004 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2005 request);
2006 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2007 request.subId, pair.first /*callingUid*/,
2008 pair.second /*request*/, onCompleted);
2009 break;
2010 }
2011 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
Jordan Liu109698e2020-11-24 14:50:34 -08002018
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002019 case CMD_GET_SLICING_CONFIG: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2022 request.phone.getSlicingConfig(onCompleted);
2023 break;
2024 }
2025 case EVENT_GET_SLICING_CONFIG_DONE: {
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 ResultReceiver result = (ResultReceiver) request.argument;
2029
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002030 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002031 Bundle bundle = new Bundle();
2032 int resultCode = 0;
2033 if (ar.exception != null) {
2034 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2035 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002036 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002037 } else if (ar.result == null) {
2038 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else {
2041 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2043 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 }
2045
2046 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002047 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2050 result.send(resultCode, bundle);
2051 notifyRequester(request);
2052 break;
2053 }
2054
Michele Berionne5e411512020-11-13 02:36:59 +00002055 case CMD_PREPARE_UNATTENDED_REBOOT:
2056 request = (MainThreadRequest) msg.obj;
2057 request.result =
2058 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2059 notifyRequester(request);
2060 break;
2061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 default:
2063 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2064 break;
2065 }
2066 }
Jake Hambye994d462014-02-03 13:10:13 -08002067
Pengquan Menga1bb6272018-09-06 09:59:22 -07002068 private void notifyRequester(MainThreadRequest request) {
2069 synchronized (request) {
2070 request.notifyAll();
2071 }
2072 }
2073
Jake Hambye994d462014-02-03 13:10:13 -08002074 private void handleNullReturnEvent(Message msg, String command) {
2075 AsyncResult ar = (AsyncResult) msg.obj;
2076 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2077 if (ar.exception == null) {
2078 request.result = true;
2079 } else {
2080 request.result = false;
2081 if (ar.exception instanceof CommandException) {
2082 loge(command + ": CommandException: " + ar.exception);
2083 } else {
2084 loge(command + ": Unknown exception");
2085 }
2086 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002087 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
2091 /**
2092 * Posts the specified command to be executed on the main thread,
2093 * waits for the request to complete, and returns the result.
2094 * @see #sendRequestAsync
2095 */
2096 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002097 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2098 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002099 }
2100
2101 /**
2102 * Posts the specified command to be executed on the main thread,
2103 * waits for the request to complete, and returns the result.
2104 * @see #sendRequestAsync
2105 */
2106 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2107 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002108 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
2111 /**
2112 * Posts the specified command to be executed on the main thread,
2113 * waits for the request to complete, and returns the result.
2114 * @see #sendRequestAsync
2115 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002116 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002117 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2118 }
2119
2120 /**
2121 * Posts the specified command to be executed on the main thread,
2122 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2123 * if not timeout or null otherwise.
2124 * @see #sendRequestAsync
2125 */
2126 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2127 long timeoutInMs) {
2128 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002129 }
2130
2131 /**
2132 * Posts the specified command to be executed on the main thread,
2133 * waits for the request to complete, and returns the result.
2134 * @see #sendRequestAsync
2135 */
Nathan Harold92bed182018-10-12 18:16:49 -07002136 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002137 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002138 }
2139
2140 /**
2141 * Posts the specified command to be executed on the main thread,
2142 * waits for the request to complete, and returns the result.
2143 * @see #sendRequestAsync
2144 */
2145 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002146 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2147 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002148 }
2149
2150 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002151 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2152 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2153 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002154 * @see #sendRequestAsync
2155 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002156 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2157 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2159 throw new RuntimeException("This method will deadlock if called from the main thread.");
2160 }
2161
Nathan Harold92bed182018-10-12 18:16:49 -07002162 MainThreadRequest request = null;
2163 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2164 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2165 } else if (phone != null) {
2166 request = new MainThreadRequest(argument, phone, workSource);
2167 } else {
2168 request = new MainThreadRequest(argument, subId, workSource);
2169 }
2170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 Message msg = mMainThreadHandler.obtainMessage(command, request);
2172 msg.sendToTarget();
2173
Rambo Wang0f050d82021-02-12 11:43:36 -08002174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002176 if (timeoutInMs >= 0) {
2177 // Wait for at least timeoutInMs before returning null request result
2178 long now = SystemClock.elapsedRealtime();
2179 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002180 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 try {
2182 request.wait(deadline - now);
2183 } catch (InterruptedException e) {
2184 // Do nothing, go back and check if request is completed or timeout
2185 } finally {
2186 now = SystemClock.elapsedRealtime();
2187 }
2188 }
2189 } else {
2190 // Wait for the request to complete
2191 while (request.result == null) {
2192 try {
2193 request.wait();
2194 } catch (InterruptedException e) {
2195 // Do nothing, go back and wait until the request is complete
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198 }
2199 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 if (request.result == null) {
2201 Log.wtf(LOG_TAG,
2202 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 return request.result;
2205 }
2206
2207 /**
2208 * Asynchronous ("fire and forget") version of sendRequest():
2209 * Posts the specified command to be executed on the main thread, and
2210 * returns immediately.
2211 * @see #sendRequest
2212 */
2213 private void sendRequestAsync(int command) {
2214 mMainThreadHandler.sendEmptyMessage(command);
2215 }
2216
2217 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002218 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 */
2221 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002222 sendRequestAsync(command, argument, null, null);
2223 }
2224
2225 /**
2226 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2227 * @see {@link #sendRequest(int,Object)}
2228 */
2229 private void sendRequestAsync(
2230 int command, Object argument, Phone phone, WorkSource workSource) {
2231 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002232 Message msg = mMainThreadHandler.obtainMessage(command, request);
2233 msg.sendToTarget();
2234 }
2235
2236 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 * Initialize the singleton PhoneInterfaceManager instance.
2238 * This is only done once, at startup, from PhoneApp.onCreate().
2239 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002240 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 synchronized (PhoneInterfaceManager.class) {
2242 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 } else {
2245 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2246 }
2247 return sInstance;
2248 }
2249 }
2250
2251 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002252 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002255 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002256 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002258 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002260 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 mTelephonySharedPreferences =
2262 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002263 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002264 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002265 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002266 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 publish();
2269 }
2270
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002271 private Phone getDefaultPhone() {
2272 Phone thePhone = getPhone(getDefaultSubscription());
2273 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2274 }
2275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 private void publish() {
2277 if (DBG) log("publish: " + this);
2278
Peter Wangc035ce42020-01-08 21:00:22 -08002279 TelephonyFrameworkInitializer
2280 .getTelephonyServiceManager()
2281 .getTelephonyServiceRegisterer()
2282 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
Stuart Scott584921c2015-01-15 17:10:34 -08002285 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002286 if (request.phone != null) {
2287 return request.phone;
2288 } else {
2289 return getPhoneFromSubId(request.subId);
2290 }
2291 }
2292
2293 private Phone getPhoneFromSubId(int subId) {
2294 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2295 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002296 }
2297
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002298 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2299 Phone phone = getPhoneFromRequest(request);
2300 return phone == null ? null :
2301 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2302 }
2303
Wink Saville36469e72014-06-11 15:17:00 -07002304 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002305 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002306 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308
Kai Shif70f46f2021-03-03 13:59:46 -08002309 private void sendEraseModemConfig(@NonNull Phone phone) {
2310 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2311 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2312 }
2313
2314 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2315 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2316 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002317 }
2318
Peter Wang44b186e2020-01-13 23:33:09 -08002319 private boolean isImsAvailableOnDevice() {
2320 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2321 if (pm == null) {
2322 // For some reason package manger is not available.. This will fail internally anyway,
2323 // so do not throw error and allow.
2324 return true;
2325 }
2326 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2327 }
2328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002330 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 if (DBG) log("dial: " + number);
2335 // No permission check needed here: This is just a wrapper around the
2336 // ACTION_DIAL intent, which is available to any app since it puts up
2337 // the UI before it does anything.
2338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 String url = createTelUrl(number);
2342 if (url == null) {
2343 return;
2344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 // PENDING: should we just silently fail if phone is offhook or ringing?
2347 PhoneConstants.State state = mCM.getState(subId);
2348 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2349 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2350 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2351 mApp.startActivity(intent);
2352 }
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
2356 }
2357
2358 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002359 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002360 }
2361
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 if (DBG) log("call: " + number);
2364
2365 // This is just a wrapper around the ACTION_CALL intent, but we still
2366 // need to do a permission check since we're calling startActivity()
2367 // from the context of the phone app.
2368 enforceCallPermission();
2369
Jordan Liu1617b712019-07-10 15:06:26 -07002370 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 != AppOpsManager.MODE_ALLOWED) {
2372 return;
2373 }
2374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 String url = createTelUrl(number);
2378 if (url == null) {
2379 return;
2380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 boolean isValid = false;
2383 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2384 if (slist != null) {
2385 for (SubscriptionInfo subInfoRecord : slist) {
2386 if (subInfoRecord.getSubscriptionId() == subId) {
2387 isValid = true;
2388 break;
2389 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002390 }
Wink Saville08874612014-08-31 19:19:58 -07002391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 if (!isValid) {
2393 return;
2394 }
Wink Saville08874612014-08-31 19:19:58 -07002395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2397 intent.putExtra(SUBSCRIPTION_KEY, subId);
2398 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2399 mApp.startActivity(intent);
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Wink Savilleb564aae2014-10-23 10:18:09 -07002405 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002406 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002407 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2413 }
2414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002420 Phone phone = getPhone(subId);
2421 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 checkSimPin.start();
2423 return checkSimPin.unlockSim(null, pin);
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002434 Phone phone = getPhone(subId);
2435 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 checkSimPuk.start();
2437 return checkSimPuk.unlockSim(puk, pin);
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
2440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442
2443 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002444 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 * a synchronous one.
2446 */
2447 private static class UnlockSim extends Thread {
2448
2449 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002450 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
2452 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002453 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2454 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 // For replies from SimCard interface
2457 private Handler mHandler;
2458
2459 // For async handler to identify request type
2460 private static final int SUPPLY_PIN_COMPLETE = 100;
2461
Michele Berionne5e411512020-11-13 02:36:59 +00002462 UnlockSim(int phoneId, IccCard simCard) {
2463 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 mSimCard = simCard;
2465 }
2466
2467 @Override
2468 public void run() {
2469 Looper.prepare();
2470 synchronized (UnlockSim.this) {
2471 mHandler = new Handler() {
2472 @Override
2473 public void handleMessage(Message msg) {
2474 AsyncResult ar = (AsyncResult) msg.obj;
2475 switch (msg.what) {
2476 case SUPPLY_PIN_COMPLETE:
2477 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2478 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002479 mRetryCount = msg.arg1;
2480 if (ar.exception != null) {
2481 if (ar.exception instanceof CommandException &&
2482 ((CommandException)(ar.exception)).getCommandError()
2483 == CommandException.Error.PASSWORD_INCORRECT) {
2484 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002485 } //When UiccCardApp dispose,handle message and return exception
2486 else if (ar.exception instanceof CommandException &&
2487 ((CommandException) (ar.exception)).getCommandError()
2488 == CommandException.Error.ABORTED) {
2489 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002490 } else {
2491 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2492 }
2493 } else {
2494 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 mDone = true;
2497 UnlockSim.this.notifyAll();
2498 }
2499 break;
2500 }
2501 }
2502 };
2503 UnlockSim.this.notifyAll();
2504 }
2505 Looper.loop();
2506 }
2507
2508 /*
2509 * Use PIN or PUK to unlock SIM card
2510 *
2511 * If PUK is null, unlock SIM card with PIN
2512 *
2513 * If PUK is not null, unlock SIM card with PUK and set PIN code
2514 */
Wink Saville9de0f752013-10-22 19:04:03 -07002515 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
2517 while (mHandler == null) {
2518 try {
2519 wait();
2520 } catch (InterruptedException e) {
2521 Thread.currentThread().interrupt();
2522 }
2523 }
2524 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2525
2526 if (puk == null) {
2527 mSimCard.supplyPin(pin, callback);
2528 } else {
2529 mSimCard.supplyPuk(puk, pin, callback);
2530 }
2531
2532 while (!mDone) {
2533 try {
2534 Log.d(LOG_TAG, "wait for done");
2535 wait();
2536 } catch (InterruptedException e) {
2537 // Restore the interrupted status
2538 Thread.currentThread().interrupt();
2539 }
2540 }
2541 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002542 int[] resultArray = new int[2];
2543 resultArray[0] = mResult;
2544 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002545
2546 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2547 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2548 }
2549
Wink Saville9de0f752013-10-22 19:04:03 -07002550 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552 }
2553
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002554 /**
2555 * This method has been removed due to privacy and stability concerns.
2556 */
2557 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002559 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2560 return;
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Nathan Harold1f889d82020-06-04 17:05:26 -07002563 @Override
2564 public void updateServiceLocationWithPackageName(String callingPackage) {
2565 mApp.getSystemService(AppOpsManager.class)
2566 .checkPackage(Binder.getCallingUid(), callingPackage);
2567
Nathan Haroldf096d982020-11-18 17:18:06 -08002568 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002569 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2570 // Callers targeting S have no business invoking this method.
2571 return;
2572 }
2573
2574 LocationAccessPolicy.LocationPermissionResult locationResult =
2575 LocationAccessPolicy.checkLocationPermission(mApp,
2576 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2577 .setCallingPackage(callingPackage)
2578 .setCallingFeatureId(null)
2579 .setCallingPid(Binder.getCallingPid())
2580 .setCallingUid(Binder.getCallingUid())
2581 .setMethod("updateServiceLocation")
2582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2583 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2584 .build());
2585 // Apps that lack location permission have no business calling this method;
2586 // however, because no permission was declared in the public API, denials must
2587 // all be "soft".
2588 switch (locationResult) {
2589 case DENIED_HARD: /* fall through */
2590 case DENIED_SOFT:
2591 return;
2592 }
2593
2594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002597 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002599 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002606 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002607 @Override
2608 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 return isRadioOnWithFeature(callingPackage, null);
2610 }
2611
2612
2613 @Override
2614 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2615 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2616 callingFeatureId);
2617 }
2618
2619 @Deprecated
2620 @Override
2621 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2622 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002626 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2627 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 return false;
2631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return isRadioOnForSubscriber(subId);
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002639 }
2640
2641 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
2646 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2647 } else {
2648 return false;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
2655 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002656 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
Wink Saville36469e72014-06-11 15:17:00 -07002658
Wink Savilleb564aae2014-10-23 10:18:09 -07002659 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Wink Saville36469e72014-06-11 15:17:00 -07002671 }
2672
2673 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002674 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 final Phone phone = getPhone(subId);
2683 if (phone == null) {
2684 return false;
2685 }
2686 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2687 toggleRadioOnOffForSubscriber(subId);
2688 }
2689 return true;
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002695 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002696 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002697 /*
2698 * If any of the Radios are available, it will need to be
2699 * shutdown. So return true if any Radio is available.
2700 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2704 Phone phone = PhoneFactory.getPhone(i);
2705 if (phone != null && phone.isRadioAvailable()) return true;
2706 }
2707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2708 return false;
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002712 }
2713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 enforceModifyPermission();
2717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2721 logv("Shutting down Phone " + i);
2722 shutdownRadioUsingPhoneId(i);
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002726 }
2727 }
2728
2729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002730 Phone phone = PhoneFactory.getPhone(phoneId);
2731 if (phone != null && phone.isRadioAvailable()) {
2732 phone.shutdownRadio();
2733 }
2734 }
2735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2742 if (defaultPhone != null) {
2743 defaultPhone.setRadioPower(turnOn);
2744 return true;
2745 } else {
2746 loge("There's no default phone.");
2747 return false;
2748 }
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002751 }
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
Wink Savilleb564aae2014-10-23 10:18:09 -07002754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = getPhone(subId);
2760 if (phone != null) {
2761 phone.setRadioPower(turnOn);
2762 return true;
2763 } else {
2764 return false;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Wink Saville36469e72014-06-11 15:17:00 -07002771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 public boolean enableDataConnectivity() {
2774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 int subId = mSubscriptionController.getDefaultDataSubId();
2779 final Phone phone = getPhone(subId);
2780 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002781 phone.getDataEnabledSettings().setDataEnabled(
2782 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean disableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002814 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone phone = getPhone(subId);
2818 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002819 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 } else {
2821 return false;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
2828 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002829 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
pkanwarae03a6b2016-11-06 20:37:09 -08002832 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 enforceCallPermission();
2834
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2838 return;
2839 }
2840 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2841 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
pkanwar32d516d2016-10-14 19:37:38 -07002845 };
2846
Wink Savilleb564aae2014-10-23 10:18:09 -07002847 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2853 return false;
2854 }
2855 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002861 /**
2862 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2863 * tag on getCallState Binder call.
2864 */
2865 @Deprecated
2866 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002868 if (CompatChanges.isChangeEnabled(
2869 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2870 Binder.getCallingUid())) {
2871 // Do not allow this API to be called on API version 31+, it should only be
2872 // called on old apps using this Binder call directly.
2873 throw new SecurityException("This method can only be used for applications "
2874 + "targeting API version 30 or less.");
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002878 Phone phone = getPhone(getDefaultSubscription());
2879 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2880 PhoneConstantConversions.convertCallState(phone.getState());
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
2886 @Override
2887 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2888 if (CompatChanges.isChangeEnabled(
2889 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2890 Binder.getCallingUid())) {
2891 // Check READ_PHONE_STATE for API version 31+
2892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2893 featureId, "getCallStateForSubscription")) {
2894 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2895 + "targeting API level 31+.");
2896 }
2897 }
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2902 PhoneConstantConversions.convertCallState(phone.getState());
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002909 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002910 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2911 }
2912
2913 @Override
2914 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002917 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 if (phone != null) {
2919 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2920 } else {
2921 return PhoneConstantConversions.convertDataState(
2922 PhoneConstants.DataState.DISCONNECTED);
2923 }
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
2940 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2941 } else {
2942 return TelephonyManager.DATA_ACTIVITY_NONE;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002950 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002952 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002953
2954 LocationAccessPolicy.LocationPermissionResult locationResult =
2955 LocationAccessPolicy.checkLocationPermission(mApp,
2956 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2957 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002958 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002959 .setCallingPid(Binder.getCallingPid())
2960 .setCallingUid(Binder.getCallingUid())
2961 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002962 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2964 .build());
2965 switch (locationResult) {
2966 case DENIED_HARD:
2967 throw new SecurityException("Not allowed to access cell location");
2968 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002969 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2970 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002977 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002978 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
Svetoslav64fad262015-04-14 14:35:21 -07002982 }
2983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002985 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002986 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2987 // registered cell info, so return a NULL country instead.
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002990 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2991 // Get default phone in this case.
2992 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2993 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002994 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002996 if (phone == null) return "";
2997 ServiceStateTracker sst = phone.getServiceStateTracker();
2998 if (sst == null) return "";
2999 LocaleTracker lt = sst.getLocaleTracker();
3000 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003001 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003005 }
3006
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003007 /**
3008 * This method was removed due to potential issues caused by performing partial
3009 * updates of service state, and lack of a credible use case.
3010 *
3011 * This has the ability to break the telephony implementation by disabling notification of
3012 * changes in device connectivity. DO NOT USE THIS!
3013 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003014 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 public void enableLocationUpdates() {
3016 mApp.enforceCallingOrSelfPermission(
3017 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 }
3019
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003020 /**
3021 * This method was removed due to potential issues caused by performing partial
3022 * updates of service state, and lack of a credible use case.
3023 *
3024 * This has the ability to break the telephony implementation by disabling notification of
3025 * changes in device connectivity. DO NOT USE THIS!
3026 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 @Override
3028 public void disableLocationUpdates() {
3029 mApp.enforceCallingOrSelfPermission(
3030 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
3033 @Override
3034 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003035 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3036 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003037 try {
3038 mApp.getSystemService(AppOpsManager.class)
3039 .checkPackage(Binder.getCallingUid(), callingPackage);
3040 } catch (SecurityException e) {
3041 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3042 throw e;
3043 }
3044
Nathan Haroldf096d982020-11-18 17:18:06 -08003045 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003046 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3047 throw new SecurityException(
3048 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3049 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003050
Jordan Liu1617b712019-07-10 15:06:26 -07003051 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3053 return null;
3054 }
Svetoslav64fad262015-04-14 14:35:21 -07003055
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003056 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003058 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003059 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060
Nathan Haroldf180aac2018-06-01 18:43:55 -07003061 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3062 for (CellInfo ci : info) {
3063 if (ci instanceof CellInfoGsm) {
3064 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3065 } else if (ci instanceof CellInfoWcdma) {
3066 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003069 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
3071
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003072 private List<CellInfo> getCachedCellInfo() {
3073 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3074 for (Phone phone : PhoneFactory.getPhones()) {
3075 List<CellInfo> info = phone.getAllCellInfo();
3076 if (info != null) cellInfos.addAll(info);
3077 }
3078 return cellInfos;
3079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080
3081 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003082 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003083 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003084 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003085
3086 LocationAccessPolicy.LocationPermissionResult locationResult =
3087 LocationAccessPolicy.checkLocationPermission(mApp,
3088 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3089 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003090 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003091 .setCallingPid(Binder.getCallingPid())
3092 .setCallingUid(Binder.getCallingUid())
3093 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003094 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003095 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3096 .build());
3097 switch (locationResult) {
3098 case DENIED_HARD:
3099 throw new SecurityException("Not allowed to access cell info");
3100 case DENIED_SOFT:
3101 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
3103
Nathan Haroldf096d982020-11-18 17:18:06 -08003104 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003105 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3106 return getCachedCellInfo();
3107 }
3108
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003109 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3114 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003115 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003116 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 if (info != null) cellInfos.addAll(info);
3118 }
3119 return cellInfos;
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123 }
3124
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003125 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003126 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3127 String callingFeatureId) {
3128 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3129 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003130 }
3131
3132 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3134 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003135 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003136 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 }
3138
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3140 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003143
3144 LocationAccessPolicy.LocationPermissionResult locationResult =
3145 LocationAccessPolicy.checkLocationPermission(mApp,
3146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3147 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003149 .setCallingPid(Binder.getCallingPid())
3150 .setCallingUid(Binder.getCallingUid())
3151 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003152 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3153 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003154 .build());
3155 switch (locationResult) {
3156 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003157 if (TelephonyPermissions
3158 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003159 // Safetynet logging for b/154934934
3160 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3161 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003162 throw new SecurityException("Not allowed to access cell info");
3163 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003164 if (TelephonyPermissions
3165 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003166 // Safetynet logging for b/154934934
3167 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3168 }
Nathan Harold5320c422019-05-09 10:26:08 -07003169 try {
3170 cb.onCellInfo(new ArrayList<CellInfo>());
3171 } catch (RemoteException re) {
3172 // Drop without consequences
3173 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003174 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003175 }
3176
Nathan Harolda939a962019-05-09 10:13:47 -07003177
3178 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003179 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3180
3181 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3182 }
3183
3184 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003186 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003187 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Shishir Agrawala9f32182016-04-12 12:00:16 -07003197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003198 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003199 Phone phone = PhoneFactory.getPhone(slotIndex);
3200 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003201 return null;
3202 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003203 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003204 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003205 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003206 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003207 return null;
3208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 return phone.getImei();
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003216 }
3217
3218 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003219 public String getTypeAllocationCodeForSlot(int slotIndex) {
3220 Phone phone = PhoneFactory.getPhone(slotIndex);
3221 String tac = null;
3222 if (phone != null) {
3223 String imei = phone.getImei();
3224 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3225 }
3226 return tac;
3227 }
3228
3229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003230 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003231 try {
3232 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3233 } catch (SecurityException se) {
3234 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3235 throw new SecurityException("Package " + callingPackage + " does not belong to "
3236 + Binder.getCallingUid());
3237 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003238 Phone phone = PhoneFactory.getPhone(slotIndex);
3239 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003240 return null;
3241 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003242
Jeff Davidson913390f2018-02-23 17:11:49 -08003243 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003244 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003245 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003246 return null;
3247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248
3249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 return phone.getMeid();
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
Jack Yu2af8d712017-03-15 17:14:14 -07003255 }
3256
3257 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003258 public String getManufacturerCodeForSlot(int slotIndex) {
3259 Phone phone = PhoneFactory.getPhone(slotIndex);
3260 String manufacturerCode = null;
3261 if (phone != null) {
3262 String meid = phone.getMeid();
3263 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3264 }
3265 return manufacturerCode;
3266 }
3267
3268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003269 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3270 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003273 return null;
3274 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 int subId = phone.getSubId();
3276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 mApp, subId, callingPackage, callingFeatureId,
3278 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 return null;
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return phone.getDeviceSvn();
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003288 }
3289
fionaxu43304da2017-11-27 22:51:16 -08003290 @Override
3291 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
fionaxu43304da2017-11-27 22:51:16 -08003299 }
3300
3301 @Override
3302 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 final Phone phone = getPhone(subId);
3306 return phone == null ? null : phone.getCarrierName();
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
fionaxu43304da2017-11-27 22:51:16 -08003310 }
3311
calvinpanffe225e2018-11-01 19:43:06 +08003312 @Override
chen xu0026ca62019-03-06 15:28:50 -08003313 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 final Phone phone = getPhone(subId);
3317 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003318 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
chen xu0026ca62019-03-06 15:28:50 -08003325 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003329 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
chen xu651eec72018-11-11 19:03:44 -08003335 @Override
chen xu864e11c2018-12-06 22:10:03 -08003336 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3337 if (!isSubscriptionMccMnc) {
3338 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3339 }
chen xu651eec72018-11-11 19:03:44 -08003340 final Phone phone = PhoneFactory.getPhone(slotIndex);
3341 if (phone == null) {
3342 return TelephonyManager.UNKNOWN_CARRIER_ID;
3343 }
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 //
3353 // Internal helper methods.
3354 //
3355
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003356 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003357 * Make sure the caller is the calling package itself
3358 *
3359 * @throws SecurityException if the caller is not the calling package
3360 */
3361 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3362 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003363 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3364 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003365 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003366 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003367 } catch (PackageManager.NameNotFoundException e) {
3368 // packageUid is -1
3369 }
3370 if (packageUid != callingUid) {
3371 throw new SecurityException(message + ": Package " + callingPackage
3372 + " does not belong to " + callingUid);
3373 }
3374 }
3375
3376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3378 *
3379 * @throws SecurityException if the caller does not have the required permission
3380 */
3381 private void enforceModifyPermission() {
3382 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3383 }
3384
Shuo Qiancd19c462020-01-16 20:51:11 -08003385 /**
3386 * Make sure the caller is system.
3387 *
3388 * @throws SecurityException if the caller is not system.
3389 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003390 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003391 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3392 throw new SecurityException("Caller must be system");
3393 }
3394 }
3395
Shuo Qian3b6ee772019-11-13 17:43:31 -08003396 private void enforceActiveEmergencySessionPermission() {
3397 mApp.enforceCallingOrSelfPermission(
3398 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3399 }
3400
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003401 /**
3402 * Make sure the caller has the CALL_PHONE permission.
3403 *
3404 * @throws SecurityException if the caller does not have the required permission
3405 */
3406 private void enforceCallPermission() {
3407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3408 }
3409
paulhu5a773602019-08-23 19:17:33 +08003410 private void enforceSettingsPermission() {
3411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003412 }
3413
Michele Berionne5e411512020-11-13 02:36:59 +00003414 private void enforceRebootPermission() {
3415 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3416 }
3417
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 private String createTelUrl(String number) {
3419 if (TextUtils.isEmpty(number)) {
3420 return null;
3421 }
3422
Jake Hambye994d462014-02-03 13:10:13 -08003423 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 }
3425
Ihab Awadf9e92732013-12-05 18:02:52 -08003426 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003427 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3428 }
3429
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003430 private static void logv(String msg) {
3431 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3432 }
3433
Ihab Awadf9e92732013-12-05 18:02:52 -08003434 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3436 }
3437
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003438 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003440 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003441 }
3442
Sanket Padawe356d7632015-06-22 14:03:32 -07003443 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003444 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 final Phone phone = PhoneFactory.getPhone(slotIndex);
3448 if (phone == null) {
3449 return PhoneConstants.PHONE_TYPE_NONE;
3450 } else {
3451 return phone.getPhoneType();
3452 }
3453 } finally {
3454 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003456 }
3457
3458 /**
3459 * Returns the CDMA ERI icon index to display
3460 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003462 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3463 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3464 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003465 }
3466
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003468 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3469 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003471 mApp, subId, callingPackage, callingFeatureId,
3472 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003473 return -1;
3474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 final Phone phone = getPhone(subId);
3479 if (phone != null) {
3480 return phone.getCdmaEriIconIndex();
3481 } else {
3482 return -1;
3483 }
3484 } finally {
3485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 }
3488
3489 /**
3490 * Returns the CDMA ERI icon mode,
3491 * 0 - ON
3492 * 1 - FLASHING
3493 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003495 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3496 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3497 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003498 }
3499
Sanket Padawe356d7632015-06-22 14:03:32 -07003500 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003501 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3502 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003504 mApp, subId, callingPackage, callingFeatureId,
3505 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003506 return -1;
3507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 final Phone phone = getPhone(subId);
3512 if (phone != null) {
3513 return phone.getCdmaEriIconMode();
3514 } else {
3515 return -1;
3516 }
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 }
3521
3522 /**
3523 * Returns the CDMA ERI text,
3524 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003525 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003526 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3527 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3528 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003532 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3533 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003535 mApp, subId, callingPackage, callingFeatureId,
3536 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 return null;
3538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539
3540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 final Phone phone = getPhone(subId);
3543 if (phone != null) {
3544 return phone.getCdmaEriText();
3545 } else {
3546 return null;
3547 }
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003551 }
3552
3553 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003554 * Returns the CDMA MDN.
3555 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003556 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003557 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3559 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003564 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 return phone.getLine1Number();
3566 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 return null;
3569 }
3570 } finally {
3571 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003572 }
3573 }
3574
3575 /**
3576 * Returns the CDMA MIN.
3577 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003578 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003579 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3581 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 final Phone phone = getPhone(subId);
3586 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3587 return phone.getCdmaMin();
3588 } else {
3589 return null;
3590 }
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003593 }
3594 }
3595
Hall Liud892bec2018-11-30 14:51:45 -08003596 @Override
3597 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3598 INumberVerificationCallback callback, String callingPackage) {
3599 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3600 != PERMISSION_GRANTED) {
3601 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3602 }
3603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3604
3605 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3606 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003607 throw new SecurityException("Calling package must be configured in the device config: "
3608 + "calling package: " + callingPackage
3609 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003610 }
3611
3612 if (range == null) {
3613 throw new NullPointerException("Range must be non-null");
3614 }
3615
3616 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003617 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003618
3619 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3620 }
3621
Junda Liuca05d5d2014-08-14 22:36:34 -07003622 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 * Returns true if CDMA provisioning needs to run.
3624 */
3625 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003628 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 } finally {
3630 Binder.restoreCallingIdentity(identity);
3631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 }
3633
3634 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003635 * Sets the voice mail number of a given subId.
3636 */
3637 @Override
3638 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003639 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3640 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641
3642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3645 new Pair<String, String>(alphaTag, number), new Integer(subId));
3646 return success;
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003650 }
3651
Ta-wei Yen87c49842016-05-13 21:19:52 -07003652 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003653 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003655 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3656 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003657 if (!TextUtils.equals(callingPackage, systemDialer)) {
3658 throw new SecurityException("caller must be system dialer");
3659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660
3661 final long identity = Binder.clearCallingIdentity();
3662 try {
3663 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3664 if (phoneAccountHandle == null) {
3665 return null;
3666 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003670 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003671 }
3672
3673 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003674 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3675 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003676 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003678 mApp, subId, callingPackage, callingFeatureId,
3679 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003680 return null;
3681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003683 final long identity = Binder.clearCallingIdentity();
3684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003685 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003689 }
3690
3691 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003692 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3693 VisualVoicemailSmsFilterSettings settings) {
3694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003695
3696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003699 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 } finally {
3701 Binder.restoreCallingIdentity(identity);
3702 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003703 }
3704
3705 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003706 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708
3709 final long identity = Binder.clearCallingIdentity();
3710 try {
3711 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003712 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003716 }
3717
3718 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003719 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3720 String callingPackage, int subId) {
3721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003730 }
3731
3732 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003733 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003743 }
3744
3745 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003746 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3747 String callingAttributionTag, int subId, String number, int port, String text,
3748 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003749 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003750 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003751 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003752 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003753 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3754 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003755 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003756
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003757 /**
fionaxu0152e512016-11-14 13:36:14 -08003758 * Sets the voice activation state of a given subId.
3759 */
3760 @Override
3761 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3763 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764
3765 final long identity = Binder.clearCallingIdentity();
3766 try {
3767 final Phone phone = getPhone(subId);
3768 if (phone != null) {
3769 phone.setVoiceActivationState(activationState);
3770 } else {
3771 loge("setVoiceActivationState fails with invalid subId: " + subId);
3772 }
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003775 }
3776 }
3777
3778 /**
3779 * Sets the data activation state of a given subId.
3780 */
3781 @Override
3782 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 phone.setDataActivationState(activationState);
3791 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003792 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003796 }
3797 }
3798
3799 /**
3800 * Returns the voice activation state of a given subId.
3801 */
3802 @Override
3803 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805
fionaxu0152e512016-11-14 13:36:14 -08003806 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 if (phone != null) {
3810 return phone.getVoiceActivationState();
3811 } else {
3812 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3813 }
3814 } finally {
3815 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003816 }
3817 }
3818
3819 /**
3820 * Returns the data activation state of a given subId.
3821 */
3822 @Override
3823 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825
fionaxu0152e512016-11-14 13:36:14 -08003826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 if (phone != null) {
3830 return phone.getDataActivationState();
3831 } else {
3832 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003836 }
3837 }
3838
3839 /**
Wink Saville36469e72014-06-11 15:17:00 -07003840 * Returns the unread count of voicemails for a subId
3841 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003843 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3844 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003846 mApp, subId, callingPackage, callingFeatureId,
3847 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003848 return 0;
3849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 final long identity = Binder.clearCallingIdentity();
3851 try {
3852 final Phone phone = getPhone(subId);
3853 if (phone != null) {
3854 return phone.getVoiceMessageCount();
3855 } else {
3856 return 0;
3857 }
3858 } finally {
3859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003861 }
3862
3863 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003864 * returns true, if the device is in a state where both voice and data
3865 * are supported simultaneously. This can change based on location or network condition.
3866 */
3867 @Override
3868 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003876 }
3877
3878 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003879 * Send the dialer code if called from the current default dialer or the caller has
3880 * carrier privilege.
3881 * @param inputCode The dialer code to send
3882 */
3883 @Override
3884 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003885 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003886 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003887 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3888 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003889 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003890 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003892 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893
3894 final long identity = Binder.clearCallingIdentity();
3895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003896 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
fionaxu235cc5e2017-03-06 22:25:57 -08003900 }
3901
Pengquan Menga1bb6272018-09-06 09:59:22 -07003902 @Override
3903 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003904 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003905 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003906 mApp, subId, "getNetworkSelectionMode");
3907 final long identity = Binder.clearCallingIdentity();
3908 try {
3909 if (!isActiveSubscription(subId)) {
3910 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3911 }
3912 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003916 }
3917
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003919 public boolean isInEmergencySmsMode() {
3920 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 for (Phone phone : PhoneFactory.getPhones()) {
3924 if (phone.isInEmergencySmsMode()) {
3925 return true;
3926 }
3927 }
3928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
3931 return false;
3932 }
3933
shilu366312e2019-12-17 09:28:10 -08003934 /**
3935 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3936 * @param subId The subscription to use to check the configuration.
3937 * @param c The callback that will be used to send the result.
3938 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003939 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003940 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3941 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003942 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003943 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003944
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003945 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3947 "IMS not available on device.");
3948 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 final long token = Binder.clearCallingIdentity();
3950 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003951 int slotId = getSlotIndexOrException(subId);
3952 verifyImsMmTelConfiguredOrThrow(slotId);
3953 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 } catch (ImsException e) {
3955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 } finally {
3957 Binder.restoreCallingIdentity(token);
3958 }
3959 }
3960
shilu366312e2019-12-17 09:28:10 -08003961 /**
3962 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3963 * @param subId The subscription to use to check the configuration.
3964 * @param c The callback that will be used to send the result.
3965 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003967 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003968 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003969 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003970 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3971 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3972 }
Meng Wangafbc5852019-09-19 17:37:13 -07003973 final long token = Binder.clearCallingIdentity();
3974 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003975 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3976 .removeRegistrationCallbackForSubscription(c, subId);
3977 } catch (ImsException e) {
3978 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3979 + "is inactive, ignoring unregister.");
3980 // If the subscription is no longer active, just return, since the callback
3981 // will already have been removed internally.
3982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 }
3986
Brad Ebingera34a6c22019-10-22 17:36:18 -07003987 /**
3988 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3989 */
3990 @Override
3991 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3992 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3993 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3994 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3995 "IMS not available on device.");
3996 }
3997 final long token = Binder.clearCallingIdentity();
3998 try {
3999 Phone phone = getPhone(subId);
4000 if (phone == null) {
4001 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4002 + subId + "'");
4003 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4004 }
4005 phone.getImsRegistrationState(regState -> {
4006 try {
4007 consumer.accept((regState == null)
4008 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4009 } catch (RemoteException e) {
4010 // Ignore if the remote process is no longer available to call back.
4011 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4012 }
4013 });
4014 } finally {
4015 Binder.restoreCallingIdentity(token);
4016 }
4017 }
4018
4019 /**
4020 * Get the transport type for the IMS service registration state.
4021 */
4022 @Override
4023 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004024 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004025 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004026 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4027 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4028 "IMS not available on device.");
4029 }
4030 final long token = Binder.clearCallingIdentity();
4031 try {
4032 Phone phone = getPhone(subId);
4033 if (phone == null) {
4034 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4035 + subId + "'");
4036 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4037 }
4038 phone.getImsRegistrationTech(regTech -> {
4039 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4040 int regTechConverted = (regTech == null)
4041 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4042 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4043 regTechConverted);
4044 try {
4045 consumer.accept(regTechConverted);
4046 } catch (RemoteException e) {
4047 // Ignore if the remote process is no longer available to call back.
4048 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4049 }
4050 });
4051 } finally {
4052 Binder.restoreCallingIdentity(token);
4053 }
4054 }
4055
shilu366312e2019-12-17 09:28:10 -08004056 /**
4057 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4058 * @param subId The subscription to use to check the configuration.
4059 * @param c The callback that will be used to send the result.
4060 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004062 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4063 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004064 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004065 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4068 "IMS not available on device.");
4069 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long token = Binder.clearCallingIdentity();
4071 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004072 int slotId = getSlotIndexOrException(subId);
4073 verifyImsMmTelConfiguredOrThrow(slotId);
4074 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 * @param c The callback that will be used to send the result.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004088 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004089 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004090 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004091 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4092 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4093 }
Meng Wangafbc5852019-09-19 17:37:13 -07004094
4095 final long token = Binder.clearCallingIdentity();
4096 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004097 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004098 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004099 } catch (ImsException e) {
4100 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4101 + "is inactive, ignoring unregister.");
4102 // If the subscription is no longer active, just return, since the callback
4103 // will already have been removed internally.
4104 } finally {
4105 Binder.restoreCallingIdentity(token);
4106 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 }
4108
4109 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004110 public boolean isCapable(int subId, int capability, int regTech) {
4111 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 final long token = Binder.clearCallingIdentity();
4113 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004114 int slotId = getSlotIndexOrException(subId);
4115 verifyImsMmTelConfiguredOrThrow(slotId);
4116 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4119 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004121 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4122 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 } finally {
4124 Binder.restoreCallingIdentity(token);
4125 }
4126 }
4127
4128 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004129 public boolean isAvailable(int subId, int capability, int regTech) {
4130 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 final long token = Binder.clearCallingIdentity();
4132 try {
4133 Phone phone = getPhone(subId);
4134 if (phone == null) return false;
4135 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004136 } catch (com.android.ims.ImsException e) {
4137 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4138 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(token);
4141 }
4142 }
4143
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004144 /**
4145 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4146 * subscription.
4147 * @param subId The subscription to use to check the configuration.
4148 * @param callback The callback that will be used to send the result.
4149 * @param capability The MmTelFeature capability that will be used to send the result.
4150 * @param transportType The transport type of the MmTelFeature capability.
4151 */
4152 @Override
4153 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4154 int transportType) {
4155 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4156 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4158 "IMS not available on device.");
4159 }
4160 final long token = Binder.clearCallingIdentity();
4161 try {
4162 int slotId = getSlotIndex(subId);
4163 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4164 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4165 + subId + "'");
4166 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4167 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004168 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004169 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4170 transportType, aBoolean -> {
4171 try {
4172 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4173 } catch (RemoteException e) {
4174 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4175 + "running. Ignore");
4176 }
4177 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004178 } catch (ImsException e) {
4179 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004180 } finally {
4181 Binder.restoreCallingIdentity(token);
4182 }
4183 }
4184
shilu366312e2019-12-17 09:28:10 -08004185 /**
4186 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4187 * @param subId The subscription to use to check the configuration.
4188 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 @Override
4190 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004191 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004192 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004193
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 final long token = Binder.clearCallingIdentity();
4195 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004196 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004197 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004198 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 } catch (ImsException e) {
4200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 } finally {
4202 Binder.restoreCallingIdentity(token);
4203 }
4204 }
4205
4206 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004207 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004209 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 final long identity = Binder.clearCallingIdentity();
4211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004213 // This setting doesn't require an active ImsService connection, so do not verify. The
4214 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004215 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004216 } catch (ImsException e) {
4217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
4221 }
4222
shilu366312e2019-12-17 09:28:10 -08004223 /**
4224 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4225 * @param subId The subscription to use to check the configuration.
4226 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004228 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004229 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004230 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 final long identity = Binder.clearCallingIdentity();
4232 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004233 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004234 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004235 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004236 } catch (ImsException e) {
4237 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
4241 }
4242
4243 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004244 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004246 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 final long identity = Binder.clearCallingIdentity();
4248 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004249 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004250 // This setting doesn't require an active ImsService connection, so do not verify. The
4251 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004252 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
shilu366312e2019-12-17 09:28:10 -08004260 /**
4261 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4262 * @param subId The subscription to use to check the configuration.
4263 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 @Override
4265 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004270 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004271 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004273 } catch (ImsException e) {
4274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
4280 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004281 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004283 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify. The
4288 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004289 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 } catch (ImsException e) {
4291 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
4295 }
4296
shilu366312e2019-12-17 09:28:10 -08004297 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004298 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4299 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4300 * @param subId The subscription to use to check the configuration.
4301 */
4302 @Override
4303 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004304 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004305 mApp, subId, "isCrossSimCallingEnabledByUser");
4306 final long identity = Binder.clearCallingIdentity();
4307 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004308 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004309 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004310 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004311 } catch (ImsException e) {
4312 throw new ServiceSpecificException(e.getCode());
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316 }
4317
4318 /**
4319 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4320 * Requires MODIFY_PHONE_STATE permission.
4321 * @param subId The subscription to use to check the configuration.
4322 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4323 * false otherwise
4324 */
4325 @Override
4326 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4328 "setCrossSimCallingEnabled");
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004332 // This setting doesn't require an active ImsService connection, so do not verify. The
4333 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
4337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
4342 /**
shilu366312e2019-12-17 09:28:10 -08004343 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4344 * @param subId The subscription to use to check the configuration.
4345 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004347
Brad Ebinger35c841c2018-10-01 10:40:55 -07004348 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004350 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004354 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004355 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
4363 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004364 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004366 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004370 // This setting doesn't require an active ImsService connection, so do not verify. The
4371 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004372 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004373 } catch (ImsException e) {
4374 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(identity);
4377 }
4378 }
4379
4380 @Override
4381 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4383 "setVoWiFiNonPersistent");
4384 final long identity = Binder.clearCallingIdentity();
4385 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004386 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004387 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004388 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004389 } catch (ImsException e) {
4390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
4394 }
4395
shilu366312e2019-12-17 09:28:10 -08004396 /**
4397 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4398 * @param subId The subscription to use to check the configuration.
4399 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004400 @Override
4401 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004402 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004403 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004404 final long identity = Binder.clearCallingIdentity();
4405 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004406 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004407 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004408 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004409 } catch (ImsException e) {
4410 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 }
4415
4416 @Override
4417 public void setVoWiFiModeSetting(int subId, int mode) {
4418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4419 "setVoWiFiModeSetting");
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004423 // This setting doesn't require an active ImsService connection, so do not verify. The
4424 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
4431 }
4432
4433 @Override
4434 public int getVoWiFiRoamingModeSetting(int subId) {
4435 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004439 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004440 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004441 } catch (ImsException e) {
4442 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
4448 @Override
4449 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4451 "setVoWiFiRoamingModeSetting");
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify. The
4456 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004458 } catch (ImsException e) {
4459 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 } finally {
4461 Binder.restoreCallingIdentity(identity);
4462 }
4463 }
4464
4465 @Override
4466 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4468 "setRttCapabilityEnabled");
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004471 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004472 // This setting doesn't require an active ImsService connection, so do not verify. The
4473 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004475 } catch (ImsException e) {
4476 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
shilu366312e2019-12-17 09:28:10 -08004482 /**
4483 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4484 * @param subId The subscription to use to check the configuration.
4485 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 @Override
4487 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004488 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004489 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004492 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004493 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (ImsException e) {
4496 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
4500 }
4501
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004502 @Override
4503 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4504 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4505 final long identity = Binder.clearCallingIdentity();
4506 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004507 if (!isImsAvailableOnDevice()) {
4508 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4509 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004510 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004511 int slotId = getSlotIndexOrException(subId);
4512 verifyImsMmTelConfiguredOrThrow(slotId);
4513 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004514 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004515 } catch (ImsException e) {
4516 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
4520 }
4521
4522 @Override
4523 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4524 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4525 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4527 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4528 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004529 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004530 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004531 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004532 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004533 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4534 + "is inactive, ignoring unregister.");
4535 // If the subscription is no longer active, just return, since the callback will already
4536 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
allenwtsu99c623b2020-01-03 18:24:23 +08004542
4543 private void checkModifyPhoneStatePermission(int subId, String message) {
4544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4545 message);
4546 }
4547
4548 private boolean isImsProvisioningRequired(int subId, int capability,
4549 boolean isMmtelCapability) {
4550 Phone phone = getPhone(subId);
4551 if (phone == null) {
4552 loge("phone instance null for subid " + subId);
4553 return false;
4554 }
4555 if (isMmtelCapability) {
4556 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4557 return false;
4558 }
4559 } else {
4560 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4561 return false;
4562 }
4563 }
4564 return true;
4565 }
4566
4567 @Override
4568 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4569 boolean isProvisioned) {
4570 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4571
4572 final long identity = Binder.clearCallingIdentity();
4573 try {
4574 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4575 if (!isImsProvisioningRequired(subId, capability, false)) {
4576 return;
4577 }
4578
4579 // this capability requires provisioning, route to the correct API.
4580 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4581 switch (capability) {
4582 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4583 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4584 ims.setEabProvisioned(isProvisioned);
4585 break;
4586 default: {
4587 throw new IllegalArgumentException("Tried to set provisioning for "
4588 + "rcs capability '" + capability + "', which does not require "
4589 + "provisioning.");
4590 }
4591 }
4592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
4595
4596 }
4597
4598
4599 @Override
4600 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4601 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4605 if (!isImsProvisioningRequired(subId, capability, false)) {
4606 return true;
4607 }
4608
4609 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4610 switch (capability) {
4611 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4612 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4613 return ims.isEabProvisionedOnDevice();
4614
4615 default: {
4616 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4617 + "capability '" + capability + "', which does not require "
4618 + "provisioning.");
4619 }
4620 }
4621
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
4625 }
4626
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4629 boolean isProvisioned) {
4630 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004631 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4632 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4633 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4635 }
allenwtsu99c623b2020-01-03 18:24:23 +08004636 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
4639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004640 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 return;
4642 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004643 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4644 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4645 loge("setImsProvisioningStatusForCapability: called for technology that does "
4646 + "not support provisioning - " + tech);
4647 return;
4648 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649
4650 // this capability requires provisioning, route to the correct API.
4651 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4652 switch (capability) {
4653 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4654 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4655 ims.setVolteProvisioned(isProvisioned);
4656 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4657 ims.setWfcProvisioned(isProvisioned);
4658 }
4659 break;
4660 }
4661 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4662 // There is currently no difference in VT provisioning type.
4663 ims.setVtProvisioned(isProvisioned);
4664 break;
4665 }
4666 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4667 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4668 // change the capability of the feature instead if needed.
4669 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4670 == isProvisioned) {
4671 // No change in provisioning.
4672 return;
4673 }
4674 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4675 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004676 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004677 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4679 + ", Exception" + e.getMessage());
4680 }
4681 break;
4682 }
4683 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004684 throw new IllegalArgumentException("Tried to set provisioning for "
4685 + "MmTel capability '" + capability + "', which does not require "
4686 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 }
4688 }
4689
4690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
4693 }
4694
4695 @Override
4696 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4697 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004698 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4699 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4700 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4702 }
4703 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004707 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 return true;
4709 }
4710
Brad Ebinger0d79c572021-04-17 15:20:49 -07004711 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4712 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4713 loge("getImsProvisioningStatusForCapability: called for technology that does "
4714 + "not support provisioning - " + tech);
4715 return true;
4716 }
4717
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4719 switch (capability) {
4720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4721 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4722 return ims.isVolteProvisionedOnDevice();
4723 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4724 return ims.isWfcProvisionedOnDevice();
4725 }
4726 // This should never happen, since we are checking tech above to make sure it
4727 // is either LTE or IWLAN.
4728 throw new IllegalArgumentException("Invalid radio technology for voice "
4729 + "capability.");
4730 }
4731 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4732 // There is currently no difference in VT provisioning type.
4733 return ims.isVtProvisionedOnDevice();
4734 }
4735 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4736 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4737 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4738 }
4739 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004740 throw new IllegalArgumentException(
4741 "Tried to get provisioning for MmTel capability '" + capability
4742 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004743 }
4744 }
4745
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
4751 @Override
4752 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4753 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4754 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4755 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4756 }
4757 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4758 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4759 return (provisionedBits & capability) > 0;
4760 }
4761
4762 @Override
4763 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4764 boolean isProvisioned) {
4765 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4766 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4767 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4768 }
4769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4770 "setProvisioningStatusForCapability");
4771 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4772 // If the current provisioning status for capability already matches isProvisioned,
4773 // do nothing.
4774 if (((provisionedBits & capability) > 0) == isProvisioned) {
4775 return;
4776 }
4777 if (isProvisioned) {
4778 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4779 } else {
4780 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4781 }
4782 }
4783
4784 /**
4785 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4786 * technology. The bitfield should mirror the bitfield defined by
4787 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4788 */
4789 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4790 String key = getMmTelProvisioningKey(subId, tech);
4791 // Default is no capabilities are provisioned.
4792 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4793 }
4794
4795 /**
4796 * Sets the MmTel capability provisioning bitfield (defined by
4797 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4798 * technology specified.
4799 *
4800 * Note: This is a synchronous command and should not be called on UI thread.
4801 */
4802 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4803 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4804 String key = getMmTelProvisioningKey(subId, tech);
4805 editor.putInt(key, newField);
4806 editor.commit();
4807 }
4808
4809 private static String getMmTelProvisioningKey(int subId, int tech) {
4810 // resulting key is provision_ims_mmtel_{subId}_{tech}
4811 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4812 }
4813
4814 /**
4815 * Query CarrierConfig to see if the specified capability requires provisioning for the
4816 * carrier associated with the subscription id.
4817 */
4818 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4819 int capability) {
4820 CarrierConfigManager configManager = new CarrierConfigManager(context);
4821 PersistableBundle c = configManager.getConfigForSubId(subId);
4822 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004823 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004824 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4825 false);
4826 boolean requireVoiceVtProvisioning = c.getBoolean(
4827 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4828
4829 // First check to make sure that the capability requires provisioning.
4830 switch (capability) {
4831 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4832 // intentional fallthrough
4833 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4834 if (requireVoiceVtProvisioning) {
4835 // Voice and Video requires provisioning
4836 return true;
4837 }
4838 break;
4839 }
4840 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4841 if (requireUtProvisioning) {
4842 // UT requires provisioning
4843 return true;
4844 }
4845 break;
4846 }
4847 }
4848 return false;
4849 }
4850
allenwtsu99c623b2020-01-03 18:24:23 +08004851 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4852 int capability) {
4853 CarrierConfigManager configManager = new CarrierConfigManager(context);
4854 PersistableBundle c = configManager.getConfigForSubId(subId);
4855
4856 boolean requireRcsProvisioning = c.getBoolean(
4857 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4858
4859 // First check to make sure that the capability requires provisioning.
4860 switch (capability) {
4861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4862 // intentional fallthrough
4863 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4864 if (requireRcsProvisioning) {
4865 // OPTION or PRESENCE requires provisioning
4866 return true;
4867 }
4868 break;
4869 }
4870 }
4871 return false;
4872 }
4873
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004874 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004875 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4877 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4878 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004879 enforceReadPrivilegedPermission("getImsProvisioningInt");
4880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 int slotId = getSlotIndex(subId);
4884 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4885 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4886 + subId + "' for key:" + key);
4887 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4888 }
calvinpanb5a34062021-02-08 19:59:36 +08004889 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004890 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004891 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4892 + subId + "' for key:" + key);
4893 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
4897 }
4898
4899 @Override
4900 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4902 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4903 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004904 enforceReadPrivilegedPermission("getImsProvisioningString");
4905 final long identity = Binder.clearCallingIdentity();
4906 try {
4907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 int slotId = getSlotIndex(subId);
4909 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4910 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4911 + subId + "' for key:" + key);
4912 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4913 }
calvinpanb5a34062021-02-08 19:59:36 +08004914 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004915 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4917 + subId + "' for key:" + key);
4918 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
4922 }
4923
4924 @Override
4925 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004926 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4927 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4928 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4930 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004934 int slotId = getSlotIndex(subId);
4935 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4936 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4937 + subId + "' for key:" + key);
4938 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4939 }
calvinpanb5a34062021-02-08 19:59:36 +08004940 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4941 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004943 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 @Override
4951 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004952 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4953 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4954 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4956 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 int slotId = getSlotIndex(subId);
4961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4962 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4963 + subId + "' for key:" + key);
4964 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4965 }
calvinpanb5a34062021-02-08 19:59:36 +08004966 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4967 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004969 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004971 } finally {
4972 Binder.restoreCallingIdentity(identity);
4973 }
4974 }
4975
Brad Ebinger919631e2021-06-02 17:46:35 -07004976 /**
4977 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4978 * for the given slot ID or no ImsResolver instance has been created.
4979 * @param slotId The slot ID that the IMS service is created for.
4980 * @throws ImsException If there is no ImsService configured for this slot.
4981 */
4982 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4983 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4984 ImsFeature.FEATURE_MMTEL)) {
4985 throw new ImsException("This subscription does not support MMTEL over IMS",
4986 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4987 }
4988 }
4989
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004990 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004991 int slotId = SubscriptionManager.getSlotIndex(subId);
4992 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4994 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004995 }
4996 return slotId;
4997 }
4998
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004999 private int getSlotIndex(int subId) {
5000 int slotId = SubscriptionManager.getSlotIndex(subId);
5001 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5002 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5003 }
5004 return slotId;
5005 }
5006
Wink Saville36469e72014-06-11 15:17:00 -07005007 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005008 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005009 */
5010 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005011 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5012 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005013 try {
5014 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5015 } catch (SecurityException se) {
5016 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5017 throw new SecurityException("Package " + callingPackage + " does not belong to "
5018 + Binder.getCallingUid());
5019 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005020 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005021 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005022 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005023 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005024 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005025 mApp, subId, callingPackage, callingFeatureId,
5026 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005027 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5028 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005029
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 final Phone phone = getPhone(subId);
5033 if (phone != null) {
5034 return phone.getServiceState().getDataNetworkType();
5035 } else {
5036 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005041 }
5042
5043 /**
5044 * Returns the data network type
5045 */
5046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005047 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005048 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5049 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005050 }
5051
5052 /**
5053 * Returns the data network type for a subId
5054 */
5055 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005056 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5057 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 mApp, subId, callingPackage, callingFeatureId,
5060 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005061 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5062 }
5063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 final Phone phone = getPhone(subId);
5067 if (phone != null) {
5068 return phone.getServiceState().getDataNetworkType();
5069 } else {
5070 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5071 }
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005075 }
5076
5077 /**
Wink Saville36469e72014-06-11 15:17:00 -07005078 * Returns the Voice network type for a subId
5079 */
5080 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005081 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5082 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005084 mApp, subId, callingPackage, callingFeatureId,
5085 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005086 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5087 }
5088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 final Phone phone = getPhone(subId);
5092 if (phone != null) {
5093 return phone.getServiceState().getVoiceNetworkType();
5094 } else {
5095 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5096 }
5097 } finally {
5098 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005100 }
5101
5102 /**
5103 * @return true if a ICC card is present
5104 */
5105 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005106 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005107 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5108 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005109 }
5110
5111 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005112 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005113 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005114 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005115 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 final Phone phone = PhoneFactory.getPhone(slotIndex);
5119 if (phone != null) {
5120 return phone.getIccCard().hasIccCard();
5121 } else {
5122 return false;
5123 }
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005127 }
5128
5129 /**
5130 * Return if the current radio is LTE on CDMA. This
5131 * is a tri-state return value as for a period of time
5132 * the mode may be unknown.
5133 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005134 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005135 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005136 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005137 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005139 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5140 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5141 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005142 }
5143
Sanket Padawe356d7632015-06-22 14:03:32 -07005144 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5146 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005147 try {
5148 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5149 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5151 }
5152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 final Phone phone = getPhone(subId);
5156 if (phone == null) {
5157 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5158 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005159 return TelephonyProperties.lte_on_cdma_device()
5160 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 }
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005164 }
Wink Saville36469e72014-06-11 15:17:00 -07005165 }
5166
Wink Saville36469e72014-06-11 15:17:00 -07005167 /**
5168 * {@hide}
5169 * Returns Default subId, 0 in the case of single standby.
5170 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005171 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005172 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005173 }
5174
Shishir Agrawala9f32182016-04-12 12:00:16 -07005175 private int getSlotForDefaultSubscription() {
5176 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5177 }
5178
Wink Savilleb564aae2014-10-23 10:18:09 -07005179 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005180 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005181 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005182
Pengquan Menge92a50d2018-09-21 15:54:48 -07005183 private boolean isActiveSubscription(int subId) {
5184 return mSubscriptionController.isActiveSubId(subId);
5185 }
5186
Ihab Awadf2177b72013-11-25 13:33:23 -08005187 /**
5188 * @see android.telephony.TelephonyManager.WifiCallingChoices
5189 */
5190 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005193 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5195 getWhenToMakeWifiCallsDefaultPreference());
5196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005199 }
5200
5201 /**
5202 * @see android.telephony.TelephonyManager.WifiCallingChoices
5203 */
5204 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005208 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005213 }
5214
Sailesh Nepald1e68152013-12-12 19:08:02 -08005215 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005216 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005217 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005218 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005219
Jordan Liu4c733742019-02-28 12:03:40 -08005220 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5221 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5222 if (phoneId == -1) {
5223 throw new IllegalArgumentException("Given slot index: " + slotIndex
5224 + " does not correspond to an active phone");
5225 }
5226 return PhoneFactory.getPhone(phoneId);
5227 }
5228
Shishir Agrawal566b7612013-10-28 14:41:00 -07005229 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005230 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5231 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5233 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005235 if (DBG) {
5236 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5237 }
5238 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5239 p2);
5240 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005241
Jordan Liu4c733742019-02-28 12:03:40 -08005242
5243 @Override
5244 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5245 int slotIndex, String callingPackage, String aid, int p2) {
5246 enforceModifyPermission();
5247 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5248 if (DBG) {
5249 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5250 }
5251 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5252 callingPackage, aid, p2);
5253 }
5254
5255 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5256 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 final long identity = Binder.clearCallingIdentity();
5258 try {
5259 if (TextUtils.equals(ISDR_AID, aid)) {
5260 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005261 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5262 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 if (bestComponent == null
5264 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5265 loge("The calling package is not allowed to access ISD-R.");
5266 throw new SecurityException(
5267 "The calling package is not allowed to access ISD-R.");
5268 }
Derek Tan740e1672017-06-27 14:56:27 -07005269 }
Derek Tan740e1672017-06-27 14:56:27 -07005270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005272 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5273 null /* workSource */);
5274 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 return response;
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005279 }
5280
5281 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005282 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5284 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005285 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5286 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5287 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005288
Jordan Liu4c733742019-02-28 12:03:40 -08005289 @Override
5290 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5291 enforceModifyPermission();
5292 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5293 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5294 channel);
5295 }
5296
5297 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 final long identity = Binder.clearCallingIdentity();
5299 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 if (channel < 0) {
5301 return false;
5302 }
Jordan Liu4c733742019-02-28 12:03:40 -08005303 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5304 null /* workSource */);
5305 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 return success;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005309 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005310 }
5311
5312 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005313 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5316 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005317 if (DBG) {
5318 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5319 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5320 + p3 + " data=" + data);
5321 }
5322 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5323 command, p1, p2, p3, data);
5324 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325
Jordan Liu4c733742019-02-28 12:03:40 -08005326 @Override
5327 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5328 int command, int p1, int p2, int p3, String data) {
5329 enforceModifyPermission();
5330 if (DBG) {
5331 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5332 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5333 + p3 + " data=" + data);
5334 }
5335 return iccTransmitApduLogicalChannelWithPermission(
5336 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5337 data);
5338 }
5339
5340 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5341 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 final long identity = Binder.clearCallingIdentity();
5343 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005344 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 return "";
5346 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005349 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5350 null /* workSource */);
5351 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 // Append the returned status code to the end of the response payload.
5354 String s = Integer.toHexString(
5355 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5356 if (response.payload != null) {
5357 s = IccUtils.bytesToHexString(response.payload) + s;
5358 }
5359 return s;
5360 } finally {
5361 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363 }
Jake Hambye994d462014-02-03 13:10:13 -08005364
Evan Charltonc66da362014-05-16 14:06:40 -07005365 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005366 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5367 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5369 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005371 if (DBG) {
5372 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5373 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5374 }
5375 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5376 cla, command, p1, p2, p3, data);
5377 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005378
Jordan Liu4c733742019-02-28 12:03:40 -08005379 @Override
5380 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5381 int command, int p1, int p2, int p3, String data) {
5382 enforceModifyPermission();
5383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5384 if (DBG) {
5385 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5386 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5387 + " data=" + data);
5388 }
5389
5390 return iccTransmitApduBasicChannelWithPermission(
5391 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5392 p2, p3, data);
5393 }
5394
5395 // open APDU basic channel assuming the caller has sufficient permissions
5396 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5397 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5401 && TextUtils.equals(ISDR_AID, data)) {
5402 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005403 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5404 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 if (bestComponent == null
5406 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5407 loge("The calling package is not allowed to select ISD-R.");
5408 throw new SecurityException(
5409 "The calling package is not allowed to select ISD-R.");
5410 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005411 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005414 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5415 null /* workSource */);
5416 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 // Append the returned status code to the end of the response payload.
5419 String s = Integer.toHexString(
5420 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5421 if (response.payload != null) {
5422 s = IccUtils.bytesToHexString(response.payload) + s;
5423 }
5424 return s;
5425 } finally {
5426 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005427 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005428 }
5429
5430 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005431 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005432 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5434 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
5438 if (DBG) {
5439 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5440 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5441 }
5442
5443 IccIoResult response =
5444 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5445 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5446 subId);
5447
5448 if (DBG) {
5449 log("Exchange SIM_IO [R]" + response);
5450 }
5451
5452 byte[] result = null;
5453 int length = 2;
5454 if (response.payload != null) {
5455 length = 2 + response.payload.length;
5456 result = new byte[length];
5457 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5458 } else {
5459 result = new byte[length];
5460 }
5461
5462 result[length - 1] = (byte) response.sw2;
5463 result[length - 2] = (byte) response.sw1;
5464 return result;
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005467 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005468 }
5469
Nathan Haroldb3014052017-01-25 15:57:32 -08005470 /**
5471 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5472 * on a particular subscription
5473 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005474 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5475 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005477 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005478 return null;
5479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480
5481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 if (appType != TelephonyManager.APPTYPE_USIM
5484 && appType != TelephonyManager.APPTYPE_SIM) {
5485 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5486 return null;
5487 }
5488 Object response = sendRequest(
5489 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5490 if (response instanceof String[]) {
5491 return (String[]) response;
5492 }
yincheng zhao2737e882019-09-06 17:06:54 -07005493 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005495 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005498 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005499 }
5500
yincheng zhao2737e882019-09-06 17:06:54 -07005501 /**
5502 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5503 * subscription.
5504 *
5505 * @param subId the id of the subscription.
5506 * @param appType the uicc app type, must be USIM or SIM.
5507 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5508 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005509 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005510 * @return number of fplmns that is successfully written to the SIM.
5511 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005512 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5513 String callingFeatureId) {
5514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5515 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005516 if (DBG) logv("no permissions for setForbiddenplmns");
5517 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5518 }
5519 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5520 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5521 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5522 }
5523 if (fplmns == null) {
5524 throw new IllegalArgumentException("Fplmn List provided is null");
5525 }
5526 for (String fplmn : fplmns) {
5527 if (!CellIdentity.isValidPlmn(fplmn)) {
5528 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5529 }
5530 }
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 Object response = sendRequest(
5534 CMD_SET_FORBIDDEN_PLMNS,
5535 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5536 subId);
5537 return (int) response;
5538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
5541 }
5542
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005543 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005544 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5546 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5551 if (response.payload == null) {
5552 return "";
5553 }
Evan Charltonc66da362014-05-16 14:06:40 -07005554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 // Append the returned status code to the end of the response payload.
5556 String s = Integer.toHexString(
5557 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5558 s = IccUtils.bytesToHexString(response.payload) + s;
5559 return s;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Evan Charltonc66da362014-05-16 14:06:40 -07005563 }
5564
Jake Hambye994d462014-02-03 13:10:13 -08005565 /**
5566 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5567 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5568 *
5569 * @param itemID the ID of the item to read
5570 * @return the NV item as a String, or null on error.
5571 */
5572 @Override
5573 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005574 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5576 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005581 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5583 return value;
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Jake Hambye994d462014-02-03 13:10:13 -08005587 }
5588
5589 /**
5590 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5591 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5592 *
5593 * @param itemID the ID of the item to read
5594 * @param itemValue the value to write, as a String
5595 * @return true on success; false on any failure
5596 */
5597 @Override
5598 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5606 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005607 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5609 return success;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
Jake Hambye994d462014-02-03 13:10:13 -08005613 }
5614
5615 /**
5616 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5617 * Used for device configuration by some CDMA operators.
5618 *
5619 * @param preferredRoamingList byte array containing the new PRL
5620 * @return true on success; false on any failure
5621 */
5622 @Override
5623 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5625 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5630 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5631 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5632 return success;
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Jake Hambye994d462014-02-03 13:10:13 -08005636 }
5637
5638 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005639 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005640 * Used for device configuration by some CDMA operators.
5641 *
chen xu6dac5ab2018-10-26 17:39:23 -07005642 * @param slotIndex - device slot.
5643 *
Jake Hambye994d462014-02-03 13:10:13 -08005644 * @return true on success; false on any failure
5645 */
5646 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005647 public boolean resetModemConfig(int slotIndex) {
5648 Phone phone = PhoneFactory.getPhone(slotIndex);
5649 if (phone != null) {
5650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652
chen xu6dac5ab2018-10-26 17:39:23 -07005653 final long identity = Binder.clearCallingIdentity();
5654 try {
5655 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5656 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5657 return success;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 }
chen xu6dac5ab2018-10-26 17:39:23 -07005662 return false;
5663 }
5664
5665 /**
5666 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5667 *
5668 * @param slotIndex - device slot.
5669 *
5670 * @return true on success; false on any failure
5671 */
5672 @Override
5673 public boolean rebootModem(int slotIndex) {
5674 Phone phone = PhoneFactory.getPhone(slotIndex);
5675 if (phone != null) {
5676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5677 mApp, phone.getSubId(), "rebootModem");
5678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5682 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5683 return success;
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
5687 }
5688 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005689 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005690
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005691 public String[] getPcscfAddress(String apnType, String callingPackage,
5692 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5695 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005696 return new String[0];
5697 }
5698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 final long identity = Binder.clearCallingIdentity();
5700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005701 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Wink Saville36469e72014-06-11 15:17:00 -07005705 }
5706
Brad Ebinger51f743a2017-01-23 13:50:20 -08005707 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005708 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5709 * {@link #disableIms(int)}.
5710 * @param slotIndex device slot.
5711 */
5712 public void resetIms(int slotIndex) {
5713 enforceModifyPermission();
5714
5715 final long identity = Binder.clearCallingIdentity();
5716 try {
5717 if (mImsResolver == null) {
5718 // may happen if the does not support IMS.
5719 return;
5720 }
5721 mImsResolver.disableIms(slotIndex);
5722 mImsResolver.enableIms(slotIndex);
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
5726 }
5727
5728 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005729 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5730 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005731 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005732 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005733 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
5736 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005738 // may happen if the device does not support IMS.
5739 return;
5740 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005741 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005745 }
5746
5747 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5749 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005750 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005751 public void disableIms(int slotId) {
5752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005756 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005757 // may happen if the device does not support IMS.
5758 return;
5759 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005760 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 } finally {
5762 Binder.restoreCallingIdentity(identity);
5763 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 }
5765
5766 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005767 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5768 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005769 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005770 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005771 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005772 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773
5774 final long identity = Binder.clearCallingIdentity();
5775 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005776 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5778 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005779 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005780 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005784 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005785 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005786 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5787 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005788 @Override
5789 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005790 enforceModifyPermission();
5791
5792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005795 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
5799 }
5800
5801 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005802 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005803 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005804 */
5805 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005811 // may happen if the device does not support IMS.
5812 return null;
5813 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005814 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005818 }
5819
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005820 /**
5821 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005822 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005823 */
5824 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826
5827 final long identity = Binder.clearCallingIdentity();
5828 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005830 // may happen if the device does not support IMS.
5831 return null;
5832 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005833 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 } finally {
5835 Binder.restoreCallingIdentity(identity);
5836 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005837 }
5838
Brad Ebinger884c07b2018-02-15 16:17:40 -08005839 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005840 * Sets the ImsService Package Name that Telephony will bind to.
5841 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 * @param slotIndex the slot ID that the ImsService should bind for.
5843 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005844 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 * @param featureTypes An integer array of feature types associated with a packageName.
5846 * @param packageName The name of the package that the current configuration will be replaced
5847 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005848 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005849 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5851 int[] featureTypes, String packageName) {
5852 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5855 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005856 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 final long identity = Binder.clearCallingIdentity();
5859 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005860 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005861 // may happen if the device does not support IMS.
5862 return false;
5863 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005864 Map<Integer, String> featureConfig = new HashMap<>();
5865 for (int featureType : featureTypes) {
5866 featureConfig.put(featureType, packageName);
5867 }
5868 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5869 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005873 }
5874
5875 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005876 * Clears any carrier ImsService overrides for the slot index specified that were previously
5877 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5878 *
5879 * This should only be used for testing.
5880 *
5881 * @param slotIndex the slot ID that the ImsService should bind for.
5882 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5883 */
5884 @Override
5885 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5886 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5888 "clearCarrierImsServiceOverride");
5889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5890 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5891 "clearCarrierImsServiceOverride");
5892
5893 final long identity = Binder.clearCallingIdentity();
5894 try {
5895 if (mImsResolver == null) {
5896 // may happen if the device does not support IMS.
5897 return false;
5898 }
5899 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
5903 }
5904
5905 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005906 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005907 *
5908 * @param slotId The slot that the ImsService is associated with.
5909 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5910 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005912 * @return the package name of the ImsService configuration.
5913 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005914 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5915 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005916 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005917 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005918 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5920 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 final long identity = Binder.clearCallingIdentity();
5923 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005925 // may happen if the device does not support IMS.
5926 return "";
5927 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005928 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5930 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005934 }
5935
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005936 /**
5937 * Get the MmTelFeature state associated with the requested subscription id.
5938 * @param subId The subscription that the MmTelFeature is associated with.
5939 * @param callback A callback with an integer containing the
5940 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5941 */
5942 @Override
5943 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5944 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5945 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5946 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5947 "IMS not available on device.");
5948 }
5949 final long token = Binder.clearCallingIdentity();
5950 try {
5951 int slotId = getSlotIndex(subId);
5952 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5953 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5954 + subId + "'");
5955 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5956 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005957 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005958 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5959 try {
5960 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5961 } catch (RemoteException e) {
5962 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5963 + "Ignore");
5964 }
5965 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005966 } catch (ImsException e) {
5967 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005968 } finally {
5969 Binder.restoreCallingIdentity(token);
5970 }
5971 }
5972
Daniel Brightbb5840b2021-01-12 15:48:18 -08005973 /**
5974 * Sets the ims registration state on all valid {@link Phone}s.
5975 */
5976 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005981 // NOTE: Before S, this method only set the default phone.
5982 for (final Phone phone : PhoneFactory.getPhones()) {
5983 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5984 phone.setImsRegistrationState(registered);
5985 }
5986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
Wink Saville36469e72014-06-11 15:17:00 -07005990 }
5991
5992 /**
Stuart Scott54788802015-03-30 13:18:01 -07005993 * Set the network selection mode to automatic.
5994 *
5995 */
5996 @Override
5997 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5999 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000
6001 final long identity = Binder.clearCallingIdentity();
6002 try {
shilufc958392020-01-20 11:36:01 -08006003 if (!isActiveSubscription(subId)) {
6004 return;
6005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006007 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6008 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
Stuart Scott54788802015-03-30 13:18:01 -07006012 }
6013
Jack Yud10cdd42020-09-28 20:28:01 -07006014 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006015 * Ask the radio to connect to the input network and change selection mode to manual.
6016 *
6017 * @param subId the id of the subscription.
6018 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6019 * the operator to attach to.
6020 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6021 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6022 * normal network selection next time.
6023 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006024 */
6025 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006026 public boolean setNetworkSelectionModeManual(
6027 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6029 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006030
6031 if (!isActiveSubscription(subId)) {
6032 return false;
6033 }
6034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 final long identity = Binder.clearCallingIdentity();
6036 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006037 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006039 if (DBG) {
6040 log("setNetworkSelectionModeManual: subId: " + subId
6041 + " operator: " + operatorInfo);
6042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006047 }
shilu84f6e8b2019-12-19 13:58:01 -08006048 /**
6049 * Get the manual network selection
6050 *
6051 * @param subId the id of the subscription.
6052 *
6053 * @return the previously saved user selected PLMN
6054 */
6055 @Override
6056 public String getManualNetworkSelectionPlmn(int subId) {
6057 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006058 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006059 mApp, subId, "getManualNetworkSelectionPlmn");
6060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006064 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006065 }
6066
6067 final Phone phone = getPhone(subId);
6068 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006069 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006070 }
6071 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6072 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6073 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
6077 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006078
6079 /**
6080 * Scans for available networks.
6081 */
6082 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006083 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6084 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6086 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006087 LocationAccessPolicy.LocationPermissionResult locationResult =
6088 LocationAccessPolicy.checkLocationPermission(mApp,
6089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6090 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006091 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006092 .setCallingPid(Binder.getCallingPid())
6093 .setCallingUid(Binder.getCallingUid())
6094 .setMethod("getCellNetworkScanResults")
6095 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006096 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6097 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006098 .build());
6099 switch (locationResult) {
6100 case DENIED_HARD:
6101 throw new SecurityException("Not allowed to access scan results -- location");
6102 case DENIED_SOFT:
6103 return null;
6104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105
Pengquan Menga1bb6272018-09-06 09:59:22 -07006106 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 try {
6108 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006109 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006114 }
6115
6116 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006117 * Get the call forwarding info, given the call forwarding reason.
6118 */
6119 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006120 public void getCallForwarding(int subId, int callForwardingReason,
6121 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006122 enforceReadPrivilegedPermission("getCallForwarding");
6123 long identity = Binder.clearCallingIdentity();
6124 try {
6125 if (DBG) {
6126 log("getCallForwarding: subId " + subId
6127 + " callForwardingReason" + callForwardingReason);
6128 }
Hall Liu27d24262020-09-18 19:04:59 -07006129
6130 Phone phone = getPhone(subId);
6131 if (phone == null) {
6132 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006133 callback.onError(
6134 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006135 } catch (RemoteException e) {
6136 // ignore
6137 }
6138 return;
6139 }
6140
6141 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6142 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6143 @Override
6144 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6145 try {
6146 callback.onCallForwardingInfoAvailable(info);
6147 } catch (RemoteException e) {
6148 // ignore
6149 }
6150 }
6151
6152 @Override
6153 public void onError(int error) {
6154 try {
6155 callback.onError(error);
6156 } catch (RemoteException e) {
6157 // ignore
6158 }
6159 }
6160 });
6161 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
6165 }
6166
6167 /**
6168 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6169 * reason, the number to forward, and the timeout before the forwarding is attempted.
6170 */
6171 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006172 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6173 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006174 enforceModifyPermission();
6175 long identity = Binder.clearCallingIdentity();
6176 try {
6177 if (DBG) {
6178 log("setCallForwarding: subId " + subId
6179 + " callForwardingInfo" + callForwardingInfo);
6180 }
Hall Liu27d24262020-09-18 19:04:59 -07006181
6182 Phone phone = getPhone(subId);
6183 if (phone == null) {
6184 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006185 callback.accept(
6186 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006187 } catch (RemoteException e) {
6188 // ignore
6189 }
6190 return;
6191 }
6192
6193 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6194 FunctionalUtils.ignoreRemoteException(callback::accept));
6195
6196 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006197 } finally {
6198 Binder.restoreCallingIdentity(identity);
6199 }
6200 }
6201
6202 /**
Hall Liu27d24262020-09-18 19:04:59 -07006203 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006204 */
6205 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006206 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006207 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006208 long identity = Binder.clearCallingIdentity();
6209 try {
Hall Liu27d24262020-09-18 19:04:59 -07006210 Phone phone = getPhone(subId);
6211 if (phone == null) {
6212 try {
6213 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6214 } catch (RemoteException e) {
6215 // ignore
6216 }
6217 return;
6218 }
SongFerngWang0e767992021-03-31 22:08:45 +08006219 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6220 PersistableBundle c = configManager.getConfigForSubId(subId);
6221 boolean requireUssd = c.getBoolean(
6222 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006223
Shuo Qian4a594052020-01-23 11:59:30 -08006224 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006225 if (requireUssd) {
6226 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6227 getSubscriptionCarrierId(subId));
6228 String newUssdCommand = "";
6229 try {
6230 newUssdCommand = carrierXmlParser.getFeature(
6231 CarrierXmlParser.FEATURE_CALL_WAITING)
6232 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6233 } catch (NullPointerException e) {
6234 loge("Failed to generate USSD number" + e);
6235 }
6236 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6237 mMainThreadHandler, callback, carrierXmlParser,
6238 CarrierXmlParser.SsEntry.SSAction.QUERY);
6239 final String ussdCommand = newUssdCommand;
6240 Executors.newSingleThreadExecutor().execute(() -> {
6241 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6242 });
6243 } else {
6244 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6245 callback::accept);
6246 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6247 }
Shuo Qian4a594052020-01-23 11:59:30 -08006248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
6251 }
6252
6253 /**
Hall Liu27d24262020-09-18 19:04:59 -07006254 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006255 */
6256 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006257 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006258 enforceModifyPermission();
6259 long identity = Binder.clearCallingIdentity();
6260 try {
Hall Liu27d24262020-09-18 19:04:59 -07006261 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6262
6263 Phone phone = getPhone(subId);
6264 if (phone == null) {
6265 try {
6266 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6267 } catch (RemoteException e) {
6268 // ignore
6269 }
6270 return;
6271 }
6272
SongFerngWang0e767992021-03-31 22:08:45 +08006273 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6274 PersistableBundle c = configManager.getConfigForSubId(subId);
6275 boolean requireUssd = c.getBoolean(
6276 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006277
SongFerngWang0e767992021-03-31 22:08:45 +08006278 if (DBG) log("getCallWaitingStatus: subId " + subId);
6279 if (requireUssd) {
6280 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6281 getSubscriptionCarrierId(subId));
6282 CarrierXmlParser.SsEntry.SSAction ssAction =
6283 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6284 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6285 String newUssdCommand = "";
6286 try {
6287 newUssdCommand = carrierXmlParser.getFeature(
6288 CarrierXmlParser.FEATURE_CALL_WAITING)
6289 .makeCommand(ssAction, null);
6290 } catch (NullPointerException e) {
6291 loge("Failed to generate USSD number" + e);
6292 }
6293 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6294 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6295 final String ussdCommand = newUssdCommand;
6296 Executors.newSingleThreadExecutor().execute(() -> {
6297 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6298 });
6299 } else {
6300 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6301 FunctionalUtils.ignoreRemoteException(callback::accept));
6302
6303 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6304 }
Shuo Qian4a594052020-01-23 11:59:30 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
6308 }
6309
6310 /**
yinxub1bed742017-04-17 11:45:04 -07006311 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006312 *
yinxub1bed742017-04-17 11:45:04 -07006313 * @param subId id of the subscription
6314 * @param request contains the radio access networks with bands/channels to scan
6315 * @param messenger callback messenger for scan results or errors
6316 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006317 * @return the id of the requested scan which can be used to stop the scan.
6318 */
6319 @Override
6320 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006321 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6323 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006324 LocationAccessPolicy.LocationPermissionResult locationResult =
6325 LocationAccessPolicy.checkLocationPermission(mApp,
6326 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6327 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006328 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006329 .setCallingPid(Binder.getCallingPid())
6330 .setCallingUid(Binder.getCallingUid())
6331 .setMethod("requestNetworkScan")
6332 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006333 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6334 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006335 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006336 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006337 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6338 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006339 if (e != null) {
6340 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6341 throw e;
6342 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006343 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006344 return TelephonyScanManager.INVALID_SCAN_ID;
6345 }
6346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 }
Hall Liu912dfd32019-04-25 14:02:26 -07006348 int callingUid = Binder.getCallingUid();
6349 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 return mNetworkScanRequestTracker.startNetworkScan(
6353 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006354 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
yinxu504e1392017-04-12 16:03:22 -07006358 }
6359
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006361 NetworkScanRequest request, int subId, String callingPackage) {
6362 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006363 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6364 boolean hasNetworkScanPermission =
6365 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6366 == PERMISSION_GRANTED;
6367
6368 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6369 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6370 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006371 }
6372
6373 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6374 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006375 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6376 return new SecurityException("Specific channels must not be"
6377 + " scanned without location access.");
6378 }
6379 }
6380 }
6381
Hall Liub2ac8ef2019-02-28 15:56:23 -08006382 return null;
6383 }
6384
yinxu504e1392017-04-12 16:03:22 -07006385 /**
6386 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006387 *
6388 * @param subId id of the subscription
6389 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006390 */
6391 @Override
6392 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6394 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395
Hall Liu912dfd32019-04-25 14:02:26 -07006396 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
6398 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006399 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
yinxu504e1392017-04-12 16:03:22 -07006403 }
6404
6405 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006407 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006408 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006409 */
6410 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006411 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006412 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006413 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006414 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006418 if (DBG) log("getAllowedNetworkTypesBitmask");
6419 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6420 int networkTypesBitmask = (result != null ? result[0] : -1);
6421 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6422 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006426 }
6427
6428 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006429 * Get the allowed network types for certain reason.
6430 *
6431 * @param subId the id of the subscription.
6432 * @param reason the reason the allowed network type change is taking place
6433 * @return the allowed network types.
6434 */
6435 @Override
6436 public long getAllowedNetworkTypesForReason(int subId,
6437 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006439 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447
6448 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006449 * Enable/Disable E-UTRA-NR Dual Connectivity
6450 * @param subId subscription id of the sim card
6451 * @param nrDualConnectivityState expected NR dual connectivity state
6452 * This can be passed following states
6453 * <ol>
6454 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6455 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6456 * <li>Disable NR dual connectivity and force secondary cell to be released
6457 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6458 * </ol>
6459 * @return operation result.
6460 */
6461 @Override
6462 public int setNrDualConnectivityState(int subId,
6463 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6465 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006466 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006467 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6468 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6469 }
6470
Sooraj Sasindran37444802020-08-11 10:40:43 -07006471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6475 nrDualConnectivityState, subId,
6476 workSource);
6477 if (DBG) log("enableNRDualConnectivity result: " + result);
6478 return result;
6479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
6482 }
6483
6484 /**
6485 * Is E-UTRA-NR Dual Connectivity enabled
6486 * @return true if dual connectivity is enabled else false
6487 */
6488 @Override
6489 public boolean isNrDualConnectivityEnabled(int subId) {
6490 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006491 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006492 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006493 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006494 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6495 return false;
6496 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006497 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6501 null, subId, workSource);
6502 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6503 return isEnabled;
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
6507 }
6508
6509 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006510 * Set the allowed network types of the device and
6511 * provide the reason triggering the allowed network change.
6512 *
6513 * @param subId the id of the subscription.
6514 * @param reason the reason the allowed network type change is taking place
6515 * @param allowedNetworkTypes the allowed network types.
6516 * @return true on success; false on any failure.
6517 */
6518 @Override
6519 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006520 @TelephonyManager.AllowedNetworkTypesReason int reason,
6521 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6523 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006524 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006525 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6526 return false;
6527 }
6528 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6529 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006530 return false;
6531 }
6532
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006533 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6534 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6535
6536
6537 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6538 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6539 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006540 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006541
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006542 final long identity = Binder.clearCallingIdentity();
6543 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006544 Boolean success = (Boolean) sendRequest(
6545 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6546 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6547
6548 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6549 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
6553 }
6554
6555 /**
Miaoa84611c2019-03-15 09:21:10 +08006556 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006557 *
Miaoa84611c2019-03-15 09:21:10 +08006558 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006559 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006560 * @hide
6561 */
6562 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006563 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006566 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006567 try {
Miaoa84611c2019-03-15 09:21:10 +08006568 if (phone != null) {
6569 return phone.hasMatchedTetherApnSetting();
6570 } else {
6571 return false;
6572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 } finally {
6574 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006575 }
Junda Liu475951f2014-11-07 16:45:03 -08006576 }
6577
6578 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006579 * Enable or disable always reporting signal strength changes from radio.
6580 *
6581 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6582 */
6583 @Override
6584 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6585 enforceModifyPermission();
6586 enforceSystemCaller();
6587
6588 final long identity = Binder.clearCallingIdentity();
6589 final Phone phone = getPhone(subId);
6590 try {
6591 if (phone != null) {
6592 if (DBG) {
6593 log("setAlwaysReportSignalStrength: subId=" + subId
6594 + " isEnable=" + isEnable);
6595 }
6596 phone.setAlwaysReportSignalStrength(isEnable);
6597 } else {
6598 loge("setAlwaysReportSignalStrength: no phone found for subId="
6599 + subId);
6600 }
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
6606 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006607 * Get the user enabled state of Mobile Data.
6608 *
6609 * TODO: remove and use isUserDataEnabled.
6610 * This can't be removed now because some vendor codes
6611 * calls through ITelephony directly while they should
6612 * use TelephonyManager.
6613 *
6614 * @return true on enabled
6615 */
6616 @Override
6617 public boolean getDataEnabled(int subId) {
6618 return isUserDataEnabled(subId);
6619 }
6620
6621 /**
6622 * Get whether mobile data is enabled per user setting.
6623 *
6624 * There are other factors deciding whether mobile data is actually enabled, but they are
6625 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006626 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006627 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006628 *
6629 * @return {@code true} if data is enabled else {@code false}
6630 */
6631 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006632 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006633 try {
6634 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6635 null);
6636 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6638 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006639 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
6643 int phoneId = mSubscriptionController.getPhoneId(subId);
6644 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6645 Phone phone = PhoneFactory.getPhone(phoneId);
6646 if (phone != null) {
6647 boolean retVal = phone.isUserDataEnabled();
6648 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6649 return retVal;
6650 } else {
6651 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6652 return false;
6653 }
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006656 }
6657 }
6658
6659 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006660 * Checks if the device is capable of mobile data by considering whether whether the
6661 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6662 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006663 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006664 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006665 */
6666 @Override
6667 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006668 try {
6669 try {
6670 mApp.enforceCallingOrSelfPermission(
6671 android.Manifest.permission.ACCESS_NETWORK_STATE,
6672 null);
6673 } catch (Exception e) {
6674 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6675 "isDataEnabled");
6676 }
6677 } catch (Exception e) {
6678 enforceReadPrivilegedPermission("isDataEnabled");
6679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 int phoneId = mSubscriptionController.getPhoneId(subId);
6684 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6685 Phone phone = PhoneFactory.getPhone(phoneId);
6686 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006687 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6689 return retVal;
6690 } else {
6691 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6692 return false;
6693 }
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006696 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006697 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006698
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 /**
6700 * Check if data is enabled for a specific reason
6701 * @param subId Subscription index
6702 * @param reason the reason the data enable change is taking place
6703 * @return {@code true} if the overall data is enabled; {@code false} if not.
6704 */
6705 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006706 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006707 @TelephonyManager.DataEnabledReason int reason) {
6708 try {
6709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6710 null);
6711 } catch (Exception e) {
6712 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006713 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006714 }
6715
6716
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 int phoneId = mSubscriptionController.getPhoneId(subId);
6720 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006721 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006722 + " reason=" + reason);
6723 }
6724 Phone phone = PhoneFactory.getPhone(phoneId);
6725 if (phone != null) {
6726 boolean retVal;
6727 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6728 retVal = phone.isUserDataEnabled();
6729 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006730 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006731 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006732 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006733 return retVal;
6734 } else {
6735 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006736 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006737 + subId + " retVal=false");
6738 }
6739 return false;
6740 }
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
6744 }
6745
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006746 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006747 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006748 if (uid == Process.PHONE_UID) {
6749 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6750 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6752 }
6753
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 //load access rules from carrier configs, and check those as well: b/139133814
6755 SubscriptionController subController = SubscriptionController.getInstance();
6756 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6757 || subController == null) return privilegeFromSim;
6758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 PackageManager pkgMgr = phone.getContext().getPackageManager();
6760 String[] packages = pkgMgr.getPackagesForUid(uid);
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006764 int subId = phone.getSubId();
6765 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6766 // A test override is in place for the privileges for this subId, so don't try to
6767 // read the subscription privileges.
6768 return privilegeFromSim;
6769 }
6770 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 SubscriptionManager subManager = (SubscriptionManager)
6772 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6773 for (String pkg : packages) {
6774 if (subManager.canManageSubscription(subInfo, pkg)) {
6775 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6776 }
6777 }
6778 return privilegeFromSim;
6779 } finally {
6780 Binder.restoreCallingIdentity(identity);
6781 }
6782 }
6783
6784 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6785 String pkgName) {
6786 //load access rules from carrier configs, and check those as well: b/139133814
6787 SubscriptionController subController = SubscriptionController.getInstance();
6788 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6789 || subController == null) return privilegeFromSim;
6790
6791 final long identity = Binder.clearCallingIdentity();
6792 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006793 int subId = phone.getSubId();
6794 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6795 // A test override is in place for the privileges for this subId, so don't try to
6796 // read the subscription privileges.
6797 return privilegeFromSim;
6798 }
6799 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006800 SubscriptionManager subManager = (SubscriptionManager)
6801 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6802 return subManager.canManageSubscription(subInfo, pkgName)
6803 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 }
6808
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006809 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006810 public int getCarrierPrivilegeStatus(int subId) {
6811 final Phone phone = getPhone(subId);
6812 if (phone == null) {
6813 loge("getCarrierPrivilegeStatus: Invalid subId");
6814 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6815 }
6816 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006817 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006818 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006819 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6820 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006821
6822 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6823 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006824 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006825 }
Junda Liu29340342014-07-10 15:23:27 -07006826
6827 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006828 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006829 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 final Phone phone = getPhone(subId);
6831 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006832 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006833 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6834 }
6835 UiccProfile profile =
6836 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6837 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006838 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6840 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006841 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006842 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006843 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 }
6845
6846 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006847 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006848 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006849 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006850 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006851 }
6852
6853 int phoneId = SubscriptionManager.getPhoneId(subId);
6854 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006855 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006856 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006857 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6858 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006859 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6860 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6861 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006862 }
6863
6864 @Override
6865 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006866 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006867 if (TextUtils.isEmpty(pkgName))
6868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006869 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6870 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6871 UiccCard card = UiccController.getInstance().getUiccCard(i);
6872 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006873 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006874 continue;
6875 }
6876
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006877 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6878 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6879 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006880 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6881 break;
6882 }
6883 }
6884
6885 return result;
Junda Liu29340342014-07-10 15:23:27 -07006886 }
Derek Tan89e89d42014-07-08 17:00:10 -07006887
6888 @Override
Junda Liue64de782015-04-16 17:19:16 -07006889 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006890 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006891 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6892 loge("phoneId " + phoneId + " is not valid.");
6893 return null;
6894 }
6895 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006896 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006897 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006898 return null ;
6899 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006900 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006901 }
6902
Amith Yamasani6e118872016-02-19 12:53:51 -08006903 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006904 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006905 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006906 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006907 List<String> privilegedPackages = new ArrayList<>();
6908 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006909 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6910 // has UICC in that slot.
6911 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006912 if (card.hasCarrierPrivilegeRules()) {
6913 if (packages == null) {
6914 // Only check packages in user 0 for now
6915 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006916 PackageManager.MATCH_DISABLED_COMPONENTS
6917 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006918 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006919 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006920 }
6921 for (int p = packages.size() - 1; p >= 0; p--) {
6922 PackageInfo pkgInfo = packages.get(p);
6923 if (pkgInfo != null && pkgInfo.packageName != null
6924 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006925 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006926 privilegedPackages.add(pkgInfo.packageName);
6927 }
6928 }
6929 }
6930 }
6931 return privilegedPackages;
6932 }
6933
chen xuf7e9fe82019-05-09 19:31:02 -07006934 @Override
6935 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006936 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6937
6938 final long identity = Binder.clearCallingIdentity();
6939
chen xuf7e9fe82019-05-09 19:31:02 -07006940 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006941 try {
6942 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6943 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6944 }
6945 } finally {
6946 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006947 }
6948 return privilegedPackages;
6949 }
6950
Wink Savilleb564aae2014-10-23 10:18:09 -07006951 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006952 final Phone phone = getPhone(subId);
6953 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006954 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006955 return null;
6956 }
6957 String iccId = card.getIccId();
6958 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006959 return null;
6960 }
6961 return iccId;
6962 }
6963
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006964 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006965 public void setCallComposerStatus(int subId, int status) {
6966 enforceModifyPermission();
6967
6968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 Phone phone = getPhone(subId);
6971 if (phone != null) {
6972 Phone defaultPhone = phone.getImsPhone();
6973 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6974 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6975 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006976 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6977 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006978 }
6979 }
Shuo Qian284ae752020-12-22 19:10:14 -08006980 } catch (ImsException e) {
6981 throw new ServiceSpecificException(e.getCode());
6982 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006983 Binder.restoreCallingIdentity(identity);
6984 }
6985 }
6986
6987 @Override
6988 public int getCallComposerStatus(int subId) {
6989 enforceReadPrivilegedPermission("getCallComposerStatus");
6990
6991 final long identity = Binder.clearCallingIdentity();
6992 try {
6993 Phone phone = getPhone(subId);
6994 if (phone != null) {
6995 Phone defaultPhone = phone.getImsPhone();
6996 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6997 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6998 return imsPhone.getCallComposerStatus();
6999 }
7000 }
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
7003 }
7004 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7005 }
7006
7007 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007008 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7009 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007010 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007011 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 final String iccId = getIccId(subId);
7016 final Phone phone = getPhone(subId);
7017 if (phone == null) {
7018 return false;
7019 }
7020 final String subscriberId = phone.getSubscriberId();
7021
7022 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007023 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 + subscriberId + " to " + number);
7025 }
7026
7027 if (TextUtils.isEmpty(iccId)) {
7028 return false;
7029 }
7030
7031 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7032
7033 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7034 if (alphaTag == null) {
7035 editor.remove(alphaTagPrefKey);
7036 } else {
7037 editor.putString(alphaTagPrefKey, alphaTag);
7038 }
7039
7040 // Record both the line number and IMSI for this ICCID, since we need to
7041 // track all merged IMSIs based on line number
7042 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7043 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7044 if (number == null) {
7045 editor.remove(numberPrefKey);
7046 editor.remove(subscriberPrefKey);
7047 } else {
7048 editor.putString(numberPrefKey, number);
7049 editor.putString(subscriberPrefKey, subscriberId);
7050 }
7051
7052 editor.commit();
7053 return true;
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007056 }
Derek Tan7226c842014-07-02 17:42:23 -07007057 }
7058
7059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007060 public String getLine1NumberForDisplay(int subId, String callingPackage,
7061 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007062 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007065 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007066 return null;
7067 }
Derek Tan97ebb422014-09-05 16:55:38 -07007068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 String iccId = getIccId(subId);
7072 if (iccId != null) {
7073 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7074 if (DBG_MERGE) {
7075 log("getLine1NumberForDisplay returning "
7076 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7077 }
7078 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7081 return null;
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007084 }
Derek Tan7226c842014-07-02 17:42:23 -07007085 }
7086
7087 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007088 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7089 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007091 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007092 return null;
7093 }
Derek Tan97ebb422014-09-05 16:55:38 -07007094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 String iccId = getIccId(subId);
7098 if (iccId != null) {
7099 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7100 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7101 }
7102 return null;
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007105 }
Derek Tan7226c842014-07-02 17:42:23 -07007106 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007107
7108 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007109 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7110 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007111 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7112 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007114 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007115 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007116 return null;
7117 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007118
Jordan Liub49b04b2019-05-06 14:45:15 -07007119 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7120 // the process, where TelephonyManager was instantiated.
7121 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007122 final long identity = Binder.clearCallingIdentity();
7123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 final TelephonyManager tele = TelephonyManager.from(context);
7126 final SubscriptionManager sub = SubscriptionManager.from(context);
7127
7128 // Figure out what subscribers are currently active
7129 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130
Jordan Liub49b04b2019-05-06 14:45:15 -07007131 // Only consider subs which match the current subId
7132 // This logic can be simplified. See b/131189269 for progress.
7133 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007134 activeSubscriberIds.add(tele.getSubscriberId(subId));
7135 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136
7137 // First pass, find a number override for an active subscriber
7138 String mergeNumber = null;
7139 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7140 for (String key : prefs.keySet()) {
7141 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7142 final String subscriberId = (String) prefs.get(key);
7143 if (activeSubscriberIds.contains(subscriberId)) {
7144 final String iccId = key.substring(
7145 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7146 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7147 mergeNumber = (String) prefs.get(numberKey);
7148 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007149 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 + " for active subscriber " + subscriberId);
7151 }
7152 if (!TextUtils.isEmpty(mergeNumber)) {
7153 break;
7154 }
7155 }
7156 }
7157 }
7158
7159 // Shortcut when no active merged subscribers
7160 if (TextUtils.isEmpty(mergeNumber)) {
7161 return null;
7162 }
7163
7164 // Second pass, find all subscribers under that line override
7165 final ArraySet<String> result = new ArraySet<>();
7166 for (String key : prefs.keySet()) {
7167 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7168 final String number = (String) prefs.get(key);
7169 if (mergeNumber.equals(number)) {
7170 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7171 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7172 final String subscriberId = (String) prefs.get(subscriberKey);
7173 if (!TextUtils.isEmpty(subscriberId)) {
7174 result.add(subscriberId);
7175 }
7176 }
7177 }
7178 }
7179
7180 final String[] resultArray = result.toArray(new String[result.size()]);
7181 Arrays.sort(resultArray);
7182 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007183 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7185 }
7186 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007187 } finally {
7188 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007189 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007190 }
7191
7192 @Override
zoey chen38003472019-12-13 17:16:31 +08007193 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7194 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 final TelephonyManager telephonyManager = mApp.getSystemService(
7199 TelephonyManager.class);
7200 String subscriberId = telephonyManager.getSubscriberId(subId);
7201 if (subscriberId == null) {
7202 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007203 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007204 + subId);
7205 }
7206 return null;
7207 }
7208
7209 final SubscriptionInfo info = SubscriptionController.getInstance()
7210 .getSubscriptionInfo(subId);
7211 final ParcelUuid groupUuid = info.getGroupUuid();
7212 // If it doesn't belong to any group, return just subscriberId of itself.
7213 if (groupUuid == null) {
7214 return new String[]{subscriberId};
7215 }
7216
7217 // Get all subscriberIds from the group.
7218 final List<String> mergedSubscriberIds = new ArrayList<>();
7219 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007220 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007221 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007222 for (SubscriptionInfo subInfo : groupInfos) {
7223 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7224 if (subscriberId != null) {
7225 mergedSubscriberIds.add(subscriberId);
7226 }
7227 }
7228
7229 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232
7233 }
7234 }
7235
7236 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007237 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007238 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007239 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240
7241 final long identity = Binder.clearCallingIdentity();
7242 try {
7243 final Phone phone = getPhone(subId);
7244 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007248 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007249
7250 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007251 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007252 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7253 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007254 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7255 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 final Phone phone = getPhone(subId);
7260 if (phone == null) {
7261 return false;
7262 }
7263 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7264 cdmaNonRoamingList);
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007267 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007268 }
7269
7270 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007271 @Deprecated
7272 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7273 enforceModifyPermission();
7274
7275 int returnValue = 0;
7276 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007277 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007278 if(result.exception == null) {
7279 if (result.result != null) {
7280 byte[] responseData = (byte[])(result.result);
7281 if(responseData.length > oemResp.length) {
7282 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7283 responseData.length + "bytes. Buffer Size is " +
7284 oemResp.length + "bytes.");
7285 }
7286 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7287 returnValue = responseData.length;
7288 }
7289 } else {
7290 CommandException ex = (CommandException) result.exception;
7291 returnValue = ex.getCommandError().ordinal();
7292 if(returnValue > 0) returnValue *= -1;
7293 }
7294 } catch (RuntimeException e) {
7295 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7296 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7297 if(returnValue > 0) returnValue *= -1;
7298 }
7299
7300 return returnValue;
7301 }
7302
7303 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007304 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007305 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007306 try {
7307 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007308 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007309 mApp, phone.getSubId(), "getRadioAccessFamily");
7310 } catch (SecurityException e) {
7311 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7312 throw e;
7313 }
chen xub97461a2018-10-26 14:17:57 -07007314 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007315 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007316 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 final long identity = Binder.clearCallingIdentity();
7319 try {
chen xub97461a2018-10-26 14:17:57 -07007320 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007321 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007322 mApp, phone.getSubId(), "getRadioAccessFamily");
7323 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
chen xub97461a2018-10-26 14:17:57 -07007327 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007328 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007329
7330 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007331 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007332 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007333 try {
7334 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7335 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007336 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007337 }
7338 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007339 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007340 }
7341 RoleManager rm = mApp.getSystemService(RoleManager.class);
7342 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7343 if (!dialerRoleHolders.contains(callingPackage)) {
7344 throw new SecurityException("App must be the dialer role holder to"
7345 + " upload a call composer pic");
7346 }
7347
7348 Executors.newSingleThreadExecutor().execute(() -> {
7349 ByteArrayOutputStream output = new ByteArrayOutputStream(
7350 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7351 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7352 boolean readUntilEnd = false;
7353 int totalBytesRead = 0;
7354 byte[] buffer = new byte[16 * 1024];
7355 while (true) {
7356 int numRead;
7357 try {
7358 numRead = input.read(buffer);
7359 } catch (IOException e) {
7360 try {
7361 fd.checkError();
7362 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7363 null);
7364 } catch (IOException e1) {
7365 // This means that the other side closed explicitly with an error. If this
7366 // happens, log and ignore.
7367 loge("Remote end of call composer picture pipe closed: " + e1);
7368 }
7369 break;
7370 }
7371 if (numRead == -1) {
7372 readUntilEnd = true;
7373 break;
7374 }
7375 totalBytesRead += numRead;
7376 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7377 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7378 try {
7379 input.close();
7380 } catch (IOException e) {
7381 // ignore
7382 }
7383 break;
7384 }
7385 output.write(buffer, 0, numRead);
7386 }
7387 // Generally, the remote end will close the file descriptors. The only case where we
7388 // close is above, where the picture size is too big.
7389
7390 try {
7391 fd.checkError();
7392 } catch (IOException e) {
7393 loge("Remote end for call composer closed with an error: " + e);
7394 return;
7395 }
7396
Hall Liuaa4211e2021-01-20 15:43:39 -08007397 if (!readUntilEnd) {
7398 loge("Did not finish reading entire image; aborting");
7399 return;
7400 }
Hall Liu82694d52020-12-11 18:22:04 -08007401
Hall Liuaa4211e2021-01-20 15:43:39 -08007402 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7403 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7404 new CallComposerPictureTransfer.Factory() {},
7405 imageData,
7406 (result) -> {
7407 if (result.first != null) {
7408 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7409 Bundle outputResult = new Bundle();
7410 outputResult.putParcelable(
7411 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7412 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7413 outputResult);
7414 } else {
7415 callback.send(result.second, null);
7416 }
7417 }
7418 );
Hall Liu82694d52020-12-11 18:22:04 -08007419 });
7420 }
7421
7422 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007423 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007424 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 ImsManager.getInstance(defaultPhone.getContext(),
7430 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007434 }
7435
7436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7440 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007441 return false;
7442 }
Svet Ganovb320e182015-04-16 12:30:10 -07007443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 // Check the user preference and the system-level IMS setting. Even if the user has
7447 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7448 // In the long run, we may instead need to check if there exists a connection service
7449 // which can support video calling.
7450 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007451 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 return imsManager.isVtEnabledByPlatform()
7453 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7454 && imsManager.isVtEnabledByUser();
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007458 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007459
Andrew Leea1239f22015-03-02 17:44:07 -08007460 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007461 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7462 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 mApp, subId, callingPackage, callingFeatureId,
7465 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 return false;
7467 }
7468
7469 final long identity = Binder.clearCallingIdentity();
7470 try {
7471 CarrierConfigManager configManager =
7472 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007473 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
Andrew Leea1239f22015-03-02 17:44:07 -08007478 }
7479
7480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 return false;
7485 }
7486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 CarrierConfigManager configManager =
7490 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007491 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
Andrew Leea1239f22015-03-02 17:44:07 -08007496 }
7497
Andrew Lee9431b832015-03-09 18:46:45 -07007498 @Override
7499 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007500 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007501 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007502 }
7503
7504 @Override
7505 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 final long identity = Binder.clearCallingIdentity();
7507 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007508 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Lee9431b832015-03-09 18:46:45 -07007512 }
7513
Hall Liuf6668912018-10-31 17:05:23 -07007514 /**
7515 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7516 * support for the feature and device firmware support.
7517 *
7518 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7519 */
7520 @Override
7521 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007523 final Phone phone = getPhone(subscriptionId);
7524 if (phone == null) {
7525 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7526 return false;
7527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007529 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7531 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 return isCarrierSupported && isDeviceSupported;
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
Hall Liu98187582018-01-22 19:15:32 -08007537 }
7538
Hall Liuf6668912018-10-31 17:05:23 -07007539 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007540 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7541 * RTT setting, will return true if the device and carrier both support RTT.
7542 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007543 */
7544 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007547 boolean isRttSupported = isRttSupported(subscriptionId);
7548 boolean isUserRttSettingOn = Settings.Secure.getInt(
7549 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7550 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7551 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7552 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007556 }
7557
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007558 @Deprecated
7559 @Override
7560 public String getDeviceId(String callingPackage) {
7561 return getDeviceIdWithFeature(callingPackage, null);
7562 }
7563
Sanket Padawe7310cc72015-01-14 09:53:20 -08007564 /**
7565 * Returns the unique device ID of phone, for example, the IMEI for
7566 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7567 *
7568 * <p>Requires Permission:
7569 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7570 */
7571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007572 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007573 try {
7574 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7575 } catch (SecurityException se) {
7576 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7577 throw new SecurityException("Package " + callingPackage + " does not belong to "
7578 + Binder.getCallingUid());
7579 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007580 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007581 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007582 return null;
7583 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007584 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007585 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007586 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007587 return null;
7588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589
7590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 return phone.getDeviceId();
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007596 }
7597
Ping Sunc67b7c22016-03-02 19:16:45 +08007598 /**
7599 * {@hide}
7600 * Returns the IMS Registration Status on a particular subid
7601 *
7602 * @param subId
7603 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007604 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007605 Phone phone = getPhone(subId);
7606 if (phone != null) {
7607 return phone.isImsRegistered();
7608 } else {
7609 return false;
7610 }
7611 }
7612
Santos Cordon7a1885b2015-02-03 11:15:19 -08007613 @Override
7614 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 final long identity = Binder.clearCallingIdentity();
7616 try {
7617 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
7620 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007621 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007622
Tyler Gunnf70ed162019-04-03 15:28:53 -07007623 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007624 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007625 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007627 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007628 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7629 }
7630 final long identity = Binder.clearCallingIdentity();
7631 try {
7632 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7633 } finally {
7634 Binder.restoreCallingIdentity(identity);
7635 }
7636 }
7637
7638 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007639 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007640 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007641 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007642 mApp,
7643 subscriptionId,
7644 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = getPhone(subscriptionId);
7648 if (phone == null) {
7649 return null;
7650 }
7651 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
7655 }
7656
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007657 /**
7658 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007659 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007660 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 Phone phone = getPhone(subId);
7664 if (phone != null) {
7665 return phone.isWifiCallingEnabled();
7666 } else {
7667 return false;
7668 }
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007672 }
7673
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007674 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007675 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007676 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = getPhone(subId);
7681 if (phone != null) {
7682 return phone.isVideoEnabled();
7683 } else {
7684 return false;
7685 }
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007688 }
7689 }
7690
7691 /**
7692 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7693 * defined in {@link ImsRegistrationImplBase}.
7694 */
7695 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 Phone phone = getPhone(subId);
7699 if (phone != null) {
7700 return phone.getImsRegistrationTech();
7701 } else {
7702 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7703 }
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007706 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007707 }
7708
Stuart Scott8eef64f2015-04-08 15:13:54 -07007709 @Override
7710 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007711 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007712 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7713 return;
7714 }
Kai Shif70f46f2021-03-03 13:59:46 -08007715 Phone defaultPhone = getDefaultPhone();
7716 if (defaultPhone != null) {
7717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7718 mApp, getDefaultPhone().getSubId(), "factoryReset");
7719 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007720 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721
Svet Ganovcc087f82015-05-12 20:35:54 -07007722 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007723 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7724 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007725 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007726 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007727 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007728 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007729 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007730 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007731 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007732 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007733 // There has been issues when Sms raw table somehow stores orphan
7734 // fragments. They lead to garbled message when new fragments come
7735 // in and combined with those stale ones. In case this happens again,
7736 // user can reset all network settings which will clean up this table.
7737 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007738 // Clean up IMS settings as well here.
7739 int slotId = getSlotIndex(subId);
7740 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7741 ImsManager.getInstance(mApp, slotId).factoryReset();
7742 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007743
Kai Shif70f46f2021-03-03 13:59:46 -08007744 if (defaultPhone == null) {
7745 return;
7746 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007747 // Erase modem config if erase modem on network setting is enabled.
7748 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7749 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7750 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007751 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007752 }
Kai Shif70f46f2021-03-03 13:59:46 -08007753
7754 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007755 } finally {
7756 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007757 }
7758 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007759
SongFerngWangfd89b102021-05-27 22:44:54 +08007760 @VisibleForTesting
7761 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7762 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7763 return;
7764 }
7765 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7766 RILConstants.PREFERRED_NETWORK_MODE);
7767 SubscriptionManager.setSubscriptionProperty(subId,
7768 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7769 "user=" + defaultNetworkType);
7770 phone.loadAllowedNetworksFromSubscriptionDatabase();
7771 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7772 defaultNetworkType, null);
7773 }
7774
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007775 private void cleanUpSmsRawTable(Context context) {
7776 ContentResolver resolver = context.getContentResolver();
7777 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7778 resolver.delete(uri, null, null);
7779 }
7780
Narayan Kamath1c496c22015-04-16 14:40:19 +01007781 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007782 public String getSimLocaleForSubscriber(int subId) {
7783 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7784 final Phone phone = getPhone(subId);
7785 if (phone == null) {
7786 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007787 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 final long identity = Binder.clearCallingIdentity();
7790 try {
chen xu5d3637b2019-01-21 23:31:38 -08007791 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007792 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007793 if (info == null) {
7794 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7795 return null;
7796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 // Try and fetch the locale from the carrier properties or from the SIM language
7798 // preferences (EF-PL and EF-LI)...
7799 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007801 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7802 if (localeFromDefaultSim != null) {
7803 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7804 if (DBG) log("Using locale from subId: " + subId + " locale: "
7805 + localeFromDefaultSim);
7806 return localeFromDefaultSim.toLanguageTag();
7807 } else {
7808 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 }
7810 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 // The SIM language preferences only store a language (e.g. fr = French), not an
7813 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7814 // the SIM and carrier preferences does not include a country we add the country
7815 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007816 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007818 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 return mccLocale.toLanguageTag();
7820 }
7821
7822 if (DBG) log("No locale found - returning null");
7823 return null;
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007827 }
7828
7829 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007830 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007831 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007832 }
7833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 /**
7835 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7836 */
7837 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007838 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007839 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007840 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007841
Chenjie Yu1ba97252018-01-11 18:16:20 -08007842 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007843 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007844
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007845 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007846 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7847 * representing the state of the modem.
7848 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007849 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7850 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007851 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007852 */
7853 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007854 public void requestModemActivityInfo(ResultReceiver result) {
7855 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007856 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857
7858 final long identity = Binder.clearCallingIdentity();
7859 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007860 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007863 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007864 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007865
Siddharth Rayb8114062018-06-17 15:02:38 -07007866 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7867 // less than total activity duration.
7868 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7869 if (info == null) {
7870 return false;
7871 }
7872 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007873 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7874 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7875
Siddharth Rayb8114062018-06-17 15:02:38 -07007876 return (info.isValid()
7877 && (info.getSleepTimeMillis() <= activityDurationMs)
7878 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007879 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007880 && (totalTxTimeMs <= activityDurationMs));
7881 }
7882
Jack Yu85bd38a2015-11-09 11:34:32 -08007883 /**
7884 * {@hide}
7885 * Returns the service state information on specified subscription.
7886 */
7887 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007888 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7889 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007891 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007892 return null;
7893 }
7894
Hall Liuf19c44f2018-11-27 14:38:17 -08007895 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7896 LocationAccessPolicy.checkLocationPermission(mApp,
7897 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7898 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007899 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007900 .setCallingPid(Binder.getCallingPid())
7901 .setCallingUid(Binder.getCallingUid())
7902 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007903 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007904 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007905 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7906 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007907 .build());
7908
7909 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7910 LocationAccessPolicy.checkLocationPermission(mApp,
7911 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7912 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007913 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007914 .setCallingPid(Binder.getCallingPid())
7915 .setCallingUid(Binder.getCallingUid())
7916 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007917 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007918 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007919 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7920 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007921 .build());
7922 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7923 boolean hasFinePermission =
7924 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7925 boolean hasCoarsePermission =
7926 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7927
Jack Yu479f40e2020-10-27 21:29:25 -07007928 final Phone phone = getPhone(subId);
7929 if (phone == null) {
7930 return null;
7931 }
7932
Jordan Liu0f2bc442020-11-18 16:47:37 -08007933 final long identity = Binder.clearCallingIdentity();
7934
Jack Yu479f40e2020-10-27 21:29:25 -07007935 boolean isCallingPackageDataService = phone.getDataServicePackages()
7936 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007938 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7939 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7940 Rlog.d(LOG_TAG,
7941 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7942 return null;
7943 }
7944
Hall Liuf19c44f2018-11-27 14:38:17 -08007945 ServiceState ss = phone.getServiceState();
7946
7947 // Scrub out the location info in ServiceState depending on what level of access
7948 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007949 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007950 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7951 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 } finally {
7953 Binder.restoreCallingIdentity(identity);
7954 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007955 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007956
7957 /**
7958 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7959 *
7960 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7961 * voicemail ringtone.
7962 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7963 * PhoneAccount.
7964 */
7965 @Override
7966 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 final long identity = Binder.clearCallingIdentity();
7968 try {
7969 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7970 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007971 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7975 } finally {
7976 Binder.restoreCallingIdentity(identity);
7977 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007978 }
7979
7980 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007981 * Sets the per-account voicemail ringtone.
7982 *
7983 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7984 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7985 *
7986 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7987 * voicemail ringtone.
7988 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7989 * PhoneAccount.
7990 */
7991 @Override
7992 public void setVoicemailRingtoneUri(String callingPackage,
7993 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007994 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007996 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7997 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7999 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8000 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008002
8003 final long identity = Binder.clearCallingIdentity();
8004 try {
8005 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8006 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008007 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 }
8009 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008012 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008013 }
8014
8015 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008016 * Returns whether vibration is set for voicemail notification in Phone settings.
8017 *
8018 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8019 * voicemail vibration setting.
8020 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8021 */
8022 @Override
8023 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8027 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008028 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8032 } finally {
8033 Binder.restoreCallingIdentity(identity);
8034 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008035 }
8036
Youhan Wange64578a2016-05-02 15:32:42 -07008037 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008038 * Sets the per-account voicemail vibration.
8039 *
8040 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8041 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8042 *
8043 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8044 * voicemail vibration setting.
8045 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8046 * specific PhoneAccount.
8047 */
8048 @Override
8049 public void setVoicemailVibrationEnabled(String callingPackage,
8050 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008051 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008052 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008053 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8054 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8056 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8057 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 }
8059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 final long identity = Binder.clearCallingIdentity();
8061 try {
8062 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8063 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008064 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 }
8066 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8067 } finally {
8068 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008069 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008070 }
8071
8072 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008073 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8074 *
8075 * @throws SecurityException if the caller does not have the required permission
8076 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008077 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008078 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008079 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008080 }
8081
8082 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008083 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8084 * permission.
8085 *
8086 * @throws SecurityException if the caller does not have the required permission
8087 */
8088 private void enforceSendSmsPermission() {
8089 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8090 }
8091
8092 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008093 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008094 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008095 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008096 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008097 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 if (componentName == null) {
8103 throw new SecurityException(
8104 "Caller not current active visual voicemail package[null]");
8105 }
8106 String vvmPackage = componentName.getPackageName();
8107 if (!callingPackage.equals(vvmPackage)) {
8108 throw new SecurityException("Caller not current active visual voicemail package["
8109 + vvmPackage + "]");
8110 }
8111 } finally {
8112 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008113 }
8114 }
8115
8116 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008117 * Return the application ID for the app type.
8118 *
8119 * @param subId the subscription ID that this request applies to.
8120 * @param appType the uicc app type.
8121 * @return Application ID for specificied app type, or null if no uicc.
8122 */
8123 @Override
8124 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008125 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127
8128 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008129 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 if (phone == null) {
8131 return null;
8132 }
8133 String aid = null;
8134 try {
8135 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8136 .getApplicationByType(appType).getAid();
8137 } catch (Exception e) {
8138 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8139 }
8140 return aid;
8141 } finally {
8142 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008143 }
Youhan Wange64578a2016-05-02 15:32:42 -07008144 }
8145
Youhan Wang4001d252016-05-11 10:29:41 -07008146 /**
8147 * Return the Electronic Serial Number.
8148 *
8149 * @param subId the subscription ID that this request applies to.
8150 * @return ESN or null if error.
8151 */
8152 @Override
8153 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008154 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008155 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008158 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 if (phone == null) {
8160 return null;
8161 }
8162 String esn = null;
8163 try {
8164 esn = phone.getEsn();
8165 } catch (Exception e) {
8166 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8167 }
8168 return esn;
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008171 }
Youhan Wang4001d252016-05-11 10:29:41 -07008172 }
8173
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008174 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008175 * Return the Preferred Roaming List Version.
8176 *
8177 * @param subId the subscription ID that this request applies to.
8178 * @return PRLVersion or null if error.
8179 */
8180 @Override
8181 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008182 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008183 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184
8185 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008186 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 if (phone == null) {
8188 return null;
8189 }
8190 String cdmaPrlVersion = null;
8191 try {
8192 cdmaPrlVersion = phone.getCdmaPrlVersion();
8193 } catch (Exception e) {
8194 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8195 }
8196 return cdmaPrlVersion;
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008199 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008200 }
8201
8202 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008203 * Get snapshot of Telephony histograms
8204 * @return List of Telephony histograms
8205 * @hide
8206 */
8207 @Override
8208 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8210 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 return RIL.getTelephonyRILTimingHistograms();
8215 } finally {
8216 Binder.restoreCallingIdentity(identity);
8217 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008218 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008219
8220 /**
8221 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008222 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8223 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224 * Require system privileges. In the future we may add this to carrier APIs.
8225 *
Michele Berionne482f8202018-11-27 18:57:59 -08008226 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008227 */
8228 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008229 @TelephonyManager.SetCarrierRestrictionResult
8230 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008231 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008232 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008233
Michele Berionne482f8202018-11-27 18:57:59 -08008234 if (carrierRestrictionRules == null) {
8235 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008236 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 final long identity = Binder.clearCallingIdentity();
8239 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008240 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008241 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 } finally {
8243 Binder.restoreCallingIdentity(identity);
8244 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 }
8246
8247 /**
8248 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008249 * Get the allowed carrier list and the excluded carrier list, including the priority between
8250 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008251 * Require system privileges. In the future we may add this to carrier APIs.
8252 *
Michele Berionne482f8202018-11-27 18:57:59 -08008253 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008254 */
8255 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008256 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008257 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008258 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259
8260 final long identity = Binder.clearCallingIdentity();
8261 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008262 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8263 if (response instanceof CarrierRestrictionRules) {
8264 return (CarrierRestrictionRules) response;
8265 }
8266 // Response is an Exception of some kind,
8267 // which is signalled to the user as a NULL retval
8268 return null;
8269 } catch (Exception e) {
8270 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8271 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008275 }
8276
fionaxu59545b42016-05-25 15:53:37 -07008277 /**
fionaxu59545b42016-05-25 15:53:37 -07008278 * Action set from carrier signalling broadcast receivers to enable/disable radio
8279 * @param subId the subscription ID that this action applies to.
8280 * @param enabled control enable or disable radio.
8281 * {@hide}
8282 */
8283 @Override
8284 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8285 enforceModifyPermission();
8286 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287
8288 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008289 if (phone == null) {
8290 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8291 return;
8292 }
8293 try {
8294 phone.carrierActionSetRadioEnabled(enabled);
8295 } catch (Exception e) {
8296 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 } finally {
8298 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008299 }
8300 }
8301
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008302 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008303 * Enable or disable Voice over NR (VoNR)
8304 * @param subId the subscription ID that this action applies to.
8305 * @param enabled enable or disable VoNR.
8306 * @return operation result.
8307 */
8308 @Override
8309 public int setVoNrEnabled(int subId, boolean enabled) {
8310 enforceModifyPermission();
8311 final Phone phone = getPhone(subId);
8312
8313 final long identity = Binder.clearCallingIdentity();
8314 if (phone == null) {
8315 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8316 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8317 }
8318
8319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8320 try {
8321 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8322 workSource);
8323 if (DBG) log("setVoNrEnabled result: " + result);
8324 return result;
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
8330 /**
8331 * Is voice over NR enabled
8332 * @return true if VoNR is enabled else false
8333 */
8334 @Override
8335 public boolean isVoNrEnabled(int subId) {
8336 enforceReadPrivilegedPermission("isVoNrEnabled");
8337 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8341 null, subId, workSource);
8342 if (DBG) log("isVoNrEnabled: " + isEnabled);
8343 return isEnabled;
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
8347 }
8348
8349 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008350 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8351 * network status based on which carrier apps could apply actions accordingly,
8352 * enable/disable default url handler for example.
8353 *
8354 * @param subId the subscription ID that this action applies to.
8355 * @param report control start/stop reporting the default network status.
8356 * {@hide}
8357 */
8358 @Override
8359 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8360 enforceModifyPermission();
8361 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362
8363 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008364 if (phone == null) {
8365 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8366 return;
8367 }
8368 try {
8369 phone.carrierActionReportDefaultNetworkStatus(report);
8370 } catch (Exception e) {
8371 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 } finally {
8373 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008374 }
8375 }
8376
8377 /**
fionaxud9622282017-07-17 17:51:30 -07008378 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8379 * @param subId the subscription ID that this action applies to.
8380 * {@hide}
8381 */
8382 @Override
8383 public void carrierActionResetAll(int subId) {
8384 enforceModifyPermission();
8385 final Phone phone = getPhone(subId);
8386 if (phone == null) {
8387 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8388 return;
8389 }
8390 try {
8391 phone.carrierActionResetAll();
8392 } catch (Exception e) {
8393 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8394 }
8395 }
8396
8397 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008398 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8399 * bug report is being generated.
8400 */
8401 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008402 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8404 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008405 writer.println("Permission Denial: can't dump Phone from pid="
8406 + Binder.getCallingPid()
8407 + ", uid=" + Binder.getCallingUid()
8408 + "without permission "
8409 + android.Manifest.permission.DUMP);
8410 return;
8411 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008412 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008413 }
Jack Yueb89b242016-06-22 13:27:47 -07008414
Brad Ebingerdac2f002018-04-03 15:17:52 -07008415 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008416 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8417 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8418 @NonNull String[] args) {
8419 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8420 this, in.getFileDescriptor(), out.getFileDescriptor(),
8421 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008422 }
8423
Jack Yueb89b242016-06-22 13:27:47 -07008424 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008425 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008426 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008427 * @param reason the reason the data enable change is taking place
8428 * @param enabled True if enabling the data, otherwise disabling.
8429 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008430 */
8431 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008432 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008433 boolean enabled) {
8434 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8435 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8436 try {
8437 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008438 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 } catch (SecurityException se) {
8440 enforceModifyPermission();
8441 }
8442 } else {
8443 enforceModifyPermission();
8444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone phone = getPhone(subId);
8449 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008450 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8451 phone.carrierActionSetMeteredApnsEnabled(enabled);
8452 } else {
8453 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455 }
8456 } finally {
8457 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008458 }
8459 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008460
8461 /**
8462 * Get Client request stats
8463 * @return List of Client Request Stats
8464 * @hide
8465 */
8466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8468 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471 return null;
8472 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008473 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 if (phone != null) {
8478 return phone.getClientRequestStats();
8479 }
8480
8481 return null;
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
8484 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485 }
8486
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008487 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008488 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008489 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008490 }
Jack Yueb4124c2017-02-16 15:32:43 -08008491
8492 /**
Grace Chen70990072017-03-24 17:21:30 -07008493 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008494 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008495 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008496 * @param state State of SIM (power down, power up, pass through)
8497 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8498 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8499 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008500 *
8501 **/
8502 @Override
Grace Chen70990072017-03-24 17:21:30 -07008503 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008504 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008505 Phone phone = PhoneFactory.getPhone(slotIndex);
8506
vagdeviaf9a5b92018-08-15 16:01:53 -07008507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008512 phone.setSimPowerState(state, null, workSource);
8513 }
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
8519 /**
8520 * Set SIM card power state.
8521 *
8522 * @param slotIndex SIM slot id.
8523 * @param state State of SIM (power down, power up, pass through)
8524 * @param callback callback to trigger after success or failure
8525 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8526 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8527 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8528 *
8529 **/
8530 @Override
8531 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8532 IIntegerConsumer callback) {
8533 enforceModifyPermission();
8534 Phone phone = PhoneFactory.getPhone(slotIndex);
8535
8536 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 if (phone != null) {
8541 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8542 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 }
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008546 }
8547 }
Shuo Qiandd210312017-04-12 22:11:33 +00008548
Tyler Gunn65d45c22017-06-05 11:22:26 -07008549 private boolean isUssdApiAllowed(int subId) {
8550 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008551 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008552 if (configManager == null) {
8553 return false;
8554 }
8555 PersistableBundle pb = configManager.getConfigForSubId(subId);
8556 if (pb == null) {
8557 return false;
8558 }
8559 return pb.getBoolean(
8560 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8561 }
8562
Shuo Qiandd210312017-04-12 22:11:33 +00008563 /**
8564 * Check if phone is in emergency callback mode
8565 * @return true if phone is in emergency callback mode
8566 * @param subId sub id
8567 */
goneil9c5f4872017-12-05 14:07:56 -08008568 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008569 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008570 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008571 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 if (phone != null) {
8576 return phone.isInEcm();
8577 } else {
8578 return false;
8579 }
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008582 }
8583 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008584
8585 /**
8586 * Get the current signal strength information for the given subscription.
8587 * Because this information is not updated when the device is in a low power state
8588 * it should not be relied-upon to be current.
8589 * @param subId Subscription index
8590 * @return the most recent cached signal strength info from the modem
8591 */
8592 @Override
8593 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 Phone p = getPhone(subId);
8597 if (p == null) {
8598 return null;
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601 return p.getSignalStrength();
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008605 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008606
Pengquan Meng77b7f132018-08-22 14:49:57 -07008607 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008608 * Get the current modem radio state for the given slot.
8609 * @param slotIndex slot index.
8610 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008611 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008612 * @return the current radio power state from the modem
8613 */
8614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008616 Phone phone = PhoneFactory.getPhone(slotIndex);
8617 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8619 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008620 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8621 }
8622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 return phone.getRadioPowerState();
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8631 }
8632
8633 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008634 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8635 *
8636 * <p>Requires one of the following permissions:
8637 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8638 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8639 * privileges.
8640 *
8641 * @param subId subscription id
8642 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8643 * {@code false}.
8644 */
8645 @Override
8646 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008647 try {
8648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8649 null);
8650 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008651 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008652 mApp, subId, "isDataRoamingEnabled");
8653 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008654
Pengquan Menga1bb6272018-09-06 09:59:22 -07008655 boolean isEnabled = false;
8656 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008657 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 Phone phone = getPhone(subId);
8659 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008662 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008663 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008664 }
8665
8666
8667 /**
8668 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8669 *
8670 * <p> Requires permission:
8671 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8672 * privileges.
8673 *
8674 * @param subId subscription id
8675 * @param isEnabled {@code true} means enable, {@code false} means disable.
8676 */
8677 @Override
8678 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8680 mApp, subId, "setDataRoamingEnabled");
8681
Pengquan Menga1bb6272018-09-06 09:59:22 -07008682 final long identity = Binder.clearCallingIdentity();
8683 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008684 Phone phone = getPhone(subId);
8685 if (phone != null) {
8686 phone.setDataRoamingEnabled(isEnabled);
8687 }
8688 } finally {
8689 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008690 }
8691 }
8692
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008693 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008694 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008695 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008696 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008697 mApp, subId, "isManualNetworkSelectionAllowed");
8698
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008699 boolean isAllowed = true;
8700 final long identity = Binder.clearCallingIdentity();
8701 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008702 Phone phone = getPhone(subId);
8703 if (phone != null) {
8704 isAllowed = phone.isCspPlmnEnabled();
8705 }
8706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 return isAllowed;
8710 }
8711
8712 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008713 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008714 // Verify that tha callingPackage belongs to the calling UID
8715 mApp.getSystemService(AppOpsManager.class)
8716 .checkPackage(Binder.getCallingUid(), callingPackage);
8717
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008719 try {
8720 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008721 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008722 } catch (SecurityException e) {
8723 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8724 // has carrier privileges on an active UICC
8725 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8726 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008728 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008729 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008730
8731 final long identity = Binder.clearCallingIdentity();
8732 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008733 UiccController uiccController = UiccController.getInstance();
8734 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008735 if (hasReadPermission) {
8736 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008737 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008738
8739 // Remove private info if the caller doesn't have access
8740 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8741 for (UiccCardInfo cardInfo : cardInfos) {
8742 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8743 // is available
8744 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8745 if (card == null || card.getUiccProfile() == null) {
8746 // assume no access if the card or profile is unavailable
8747 filteredInfos.add(cardInfo.getUnprivileged());
8748 continue;
8749 }
8750 UiccProfile profile = card.getUiccProfile();
8751 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8752 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8753 filteredInfos.add(cardInfo);
8754 } else {
8755 filteredInfos.add(cardInfo.getUnprivileged());
8756 }
8757 }
8758 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
8764 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008765 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008766 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8771 if (slots == null) {
8772 Rlog.i(LOG_TAG, "slots is null.");
8773 return null;
8774 }
8775
8776 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8777 for (int i = 0; i < slots.length; i++) {
8778 UiccSlot slot = slots[i];
8779 if (slot == null) {
8780 continue;
8781 }
8782
Jordan Liu7be7e652019-05-06 18:55:02 +00008783 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008784 UiccCard card = slot.getUiccCard();
8785 if (card != null) {
8786 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008787 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008788 cardId = slot.getEid();
8789 if (TextUtils.isEmpty(cardId)) {
8790 cardId = slot.getIccId();
8791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 }
8793
Jordan Liu857451f2019-05-09 16:35:35 -07008794 if (cardId != null) {
8795 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8796 // if cardId is an EID, it's all digits so this is fine
8797 cardId = IccUtils.stripTrailingFs(cardId);
8798 }
8799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008800 int cardState = 0;
8801 switch (slot.getCardState()) {
8802 case CARDSTATE_ABSENT:
8803 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8804 break;
8805 case CARDSTATE_PRESENT:
8806 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8807 break;
8808 case CARDSTATE_ERROR:
8809 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8810 break;
8811 case CARDSTATE_RESTRICTED:
8812 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8813 break;
8814 default:
8815 break;
8816
8817 }
8818
8819 infos[i] = new UiccSlotInfo(
8820 slot.isActive(),
8821 slot.isEuicc(),
8822 cardId,
8823 cardState,
8824 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008825 slot.isExtendedApduSupported(),
8826 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008827 }
8828 return infos;
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008831 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008832 }
8833
8834 @Override
8835 public boolean switchSlots(int[] physicalSlots) {
8836 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008837
8838 final long identity = Binder.clearCallingIdentity();
8839 try {
8840 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8841 } finally {
8842 Binder.restoreCallingIdentity(identity);
8843 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008844 }
Jack Yu4c988042018-02-27 15:30:01 -08008845
8846 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008847 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008848 final long identity = Binder.clearCallingIdentity();
8849 try {
8850 return UiccController.getInstance().getCardIdForDefaultEuicc();
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 }
8855
Pengquan Meng85728fb2018-03-12 16:31:21 -07008856 /**
goneil47ffb6e2018-04-06 15:40:58 -07008857 * A test API to reload the UICC profile.
8858 *
8859 * <p>Requires that the calling app has permission
8860 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8861 * @hide
8862 */
8863 @Override
8864 public void refreshUiccProfile(int subId) {
8865 enforceModifyPermission();
8866
8867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 Phone phone = getPhone(subId);
8870 if (phone == null) {
8871 return;
8872 }
8873 UiccCard uiccCard = phone.getUiccCard();
8874 if (uiccCard == null) {
8875 return;
8876 }
8877 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8878 if (uiccProfile == null) {
8879 return;
8880 }
8881 uiccProfile.refresh();
8882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
8885 }
8886
8887 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008888 * Returns false if the mobile data is disabled by default, otherwise return true.
8889 */
8890 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008891 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008892 }
8893
8894 /**
8895 * Returns true if the data roaming is enabled by default, i.e the system property
8896 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8897 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8898 */
8899 private boolean getDefaultDataRoamingEnabled(int subId) {
8900 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008901 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008902 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008903 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8904 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8905 return isDataRoamingEnabled;
8906 }
8907
8908 /**
8909 * Returns the default network type for the given {@code subId}, if the default network type is
8910 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8911 */
8912 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008913 List<Integer> list = TelephonyProperties.default_network();
8914 int phoneId = mSubscriptionController.getPhoneId(subId);
8915 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8916 return list.get(phoneId);
8917 }
8918 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008919 }
fionaxua13278b2018-03-21 00:08:13 -07008920
8921 @Override
8922 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008923 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008924 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925
8926 final long identity = Binder.clearCallingIdentity();
8927 try {
8928 final Phone phone = getPhone(subId);
8929 if (phone == null) {
8930 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8931 return;
8932 }
chen xueaba88a2019-03-15 13:15:10 -07008933 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8934 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008935 if (carrierPrivilegeRules == null) {
8936 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8937 } else {
8938 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008940 } finally {
8941 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008942 }
fionaxua13278b2018-03-21 00:08:13 -07008943 }
8944
8945 @Override
8946 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008947 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008948
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 final Phone phone = getPhone(subId);
8952 if (phone == null) {
8953 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8954 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8955 }
8956 return phone.getCarrierIdListVersion();
8957 } finally {
8958 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008959 }
fionaxua13278b2018-03-21 00:08:13 -07008960 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008961
8962 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008963 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8964 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008966 mApp, subId, callingPackage, callingFeatureId,
8967 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008968 return -1;
8969 }
8970
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008978
8979 @Override
8980 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008981 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008982 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008983 mApp, subId, "getCdmaRoamingMode");
8984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
8990 }
8991 }
8992
8993 @Override
8994 public boolean setCdmaRoamingMode(int subId, int mode) {
8995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8996 mApp, subId, "setCdmaRoamingMode");
8997
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
9006 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009007 public int getCdmaSubscriptionMode(int subId) {
9008 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009009 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009010 mApp, subId, "getCdmaSubscriptionMode");
9011
9012 final long identity = Binder.clearCallingIdentity();
9013 try {
9014 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9015 } finally {
9016 Binder.restoreCallingIdentity(identity);
9017 }
9018 }
9019
9020 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009021 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9023 mApp, subId, "setCdmaSubscriptionMode");
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009032
sqianc5eccab2018-10-19 18:46:41 -07009033 @Override
sqian8c685422019-02-22 15:55:18 -08009034 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009035 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009037 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9038 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009039 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9040 }
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
sqian854d44b2018-12-12 16:48:18 -08009043 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9044 for (Phone phone: PhoneFactory.getPhones()) {
9045 if (phone.getEmergencyNumberTracker() != null
9046 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9047 emergencyNumberListInternal.put(
9048 phone.getSubId(),
9049 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9050 }
sqian11b7a0e2018-12-05 18:48:28 -08009051 }
sqian854d44b2018-12-12 16:48:18 -08009052 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
sqianc5eccab2018-10-19 18:46:41 -07009056 }
9057
9058 @Override
sqian8c685422019-02-22 15:55:18 -08009059 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009060 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009061 if (!exactMatch) {
9062 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009063 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009064 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009065 }
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
sqian854d44b2018-12-12 16:48:18 -08009068 for (Phone phone: PhoneFactory.getPhones()) {
9069 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009070 && phone.getEmergencyNumberTracker()
9071 .isEmergencyNumber(number, exactMatch)) {
9072 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009073 }
sqian11b7a0e2018-12-05 18:48:28 -08009074 }
9075 return false;
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
sqianf4ca7ed2019-01-15 18:32:07 -08009081 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009082 * Start emergency callback mode for GsmCdmaPhone for testing.
9083 */
9084 @Override
9085 public void startEmergencyCallbackMode() {
9086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9087 "startEmergencyCallbackMode");
9088 enforceModifyPermission();
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
9091 for (Phone phone : PhoneFactory.getPhones()) {
9092 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9093 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9094 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9095 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9096 gsmCdmaPhone.obtainMessage(
9097 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9098 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9099 }
9100 }
9101 } finally {
9102 Binder.restoreCallingIdentity(identity);
9103 }
9104 }
9105
9106 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009107 * Update emergency number list for test mode.
9108 */
9109 @Override
9110 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9111 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9112 "updateEmergencyNumberListTestMode");
9113
9114 final long identity = Binder.clearCallingIdentity();
9115 try {
9116 for (Phone phone: PhoneFactory.getPhones()) {
9117 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9118 if (tracker != null) {
9119 tracker.executeEmergencyNumberTestModeCommand(action, num);
9120 }
9121 }
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
9124 }
9125 }
9126
9127 /**
9128 * Get the full emergency number list for test mode.
9129 */
9130 @Override
9131 public List<String> getEmergencyNumberListTestMode() {
9132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9133 "getEmergencyNumberListTestMode");
9134
9135 final long identity = Binder.clearCallingIdentity();
9136 try {
9137 Set<String> emergencyNumbers = new HashSet<>();
9138 for (Phone phone: PhoneFactory.getPhones()) {
9139 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9140 if (tracker != null) {
9141 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9142 emergencyNumbers.add(num.getNumber());
9143 }
9144 }
9145 }
9146 return new ArrayList<>(emergencyNumbers);
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 }
9151
chen xud6b45bd2018-10-30 22:27:10 -07009152 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009153 public int getEmergencyNumberDbVersion(int subId) {
9154 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 final Phone phone = getPhone(subId);
9159 if (phone == null) {
9160 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9161 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9162 }
9163 return phone.getEmergencyNumberDbVersion();
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
9167 }
9168
9169 @Override
9170 public void notifyOtaEmergencyNumberDbInstalled() {
9171 enforceModifyPermission();
9172
9173 final long identity = Binder.clearCallingIdentity();
9174 try {
9175 for (Phone phone: PhoneFactory.getPhones()) {
9176 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9177 if (tracker != null) {
9178 tracker.updateOtaEmergencyNumberDatabase();
9179 }
9180 }
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 }
9185
9186 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009187 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009188 enforceActiveEmergencySessionPermission();
9189
9190 final long identity = Binder.clearCallingIdentity();
9191 try {
9192 for (Phone phone: PhoneFactory.getPhones()) {
9193 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9194 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009195 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9196 }
9197 }
9198 } finally {
9199 Binder.restoreCallingIdentity(identity);
9200 }
9201 }
9202
9203 @Override
9204 public void resetOtaEmergencyNumberDbFilePath() {
9205 enforceActiveEmergencySessionPermission();
9206
9207 final long identity = Binder.clearCallingIdentity();
9208 try {
9209 for (Phone phone: PhoneFactory.getPhones()) {
9210 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9211 if (tracker != null) {
9212 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009213 }
9214 }
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
9217 }
9218 }
9219
9220 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009221 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9222 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9223 Phone phone = getPhone(subId);
9224 if (phone == null) {
9225 return null;
9226 }
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 UiccProfile profile = UiccController.getInstance()
9230 .getUiccProfileForPhone(phone.getPhoneId());
9231 if (profile != null) {
9232 return profile.getCertsFromCarrierPrivilegeAccessRules();
9233 }
9234 } finally {
9235 Binder.restoreCallingIdentity(identity);
9236 }
9237 return null;
9238 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009239
9240 /**
9241 * Enable or disable a modem stack.
9242 */
9243 @Override
9244 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9245 enforceModifyPermission();
9246
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 Phone phone = PhoneFactory.getPhone(slotIndex);
9250 if (phone == null) {
9251 return false;
9252 } else {
9253 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9254 }
9255 } finally {
9256 Binder.restoreCallingIdentity(identity);
9257 }
9258 }
Michelecea4cf22018-12-21 15:00:11 -08009259
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009260 /**
9261 * Whether a modem stack is enabled or not.
9262 */
9263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009264 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9265 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009266 Phone phone = PhoneFactory.getPhone(slotIndex);
9267 if (phone == null) return false;
9268
9269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009270 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9271 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009272 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9273 }
9274
9275 final long identity = Binder.clearCallingIdentity();
9276 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009277 try {
9278 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9279 } catch (NoSuchElementException ex) {
9280 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9281 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009282 } finally {
9283 Binder.restoreCallingIdentity(identity);
9284 }
9285 }
9286
Michelecea4cf22018-12-21 15:00:11 -08009287 @Override
Michele0ea7d782019-03-19 14:58:42 -07009288 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009289 enforceModifyPermission();
9290
9291 final long identity = Binder.clearCallingIdentity();
9292 try {
9293 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009294 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009295 .commit();
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
9300
9301 @Override
Michele0ea7d782019-03-19 14:58:42 -07009302 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009303 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009305 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9306 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009307 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009308 }
Michelecea4cf22018-12-21 15:00:11 -08009309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
Michele0ea7d782019-03-19 14:58:42 -07009312 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
9316 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009317
Michele0ea7d782019-03-19 14:58:42 -07009318 @TelephonyManager.IsMultiSimSupportedResult
9319 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009320 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9321 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9322 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009323 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9324 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009325 }
9326 // Check if the hardware supports multisim functionality. If usage of multisim is not
9327 // supported by the modem, indicate that it is restricted.
9328 PhoneCapability staticCapability =
9329 mPhoneConfigurationManager.getStaticPhoneCapability();
9330 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009331 loge("isMultiSimSupportedInternal: no static configuration available");
9332 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009333 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009334 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009335 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9336 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009337 }
9338 // Check if support of multiple SIMs is restricted by carrier
9339 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009340 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009341 }
9342
Michele0ea7d782019-03-19 14:58:42 -07009343 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009344 }
9345
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009346 /**
9347 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009348 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9349 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9350 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009351 * @param numOfSims number of active sims we want to switch to
9352 */
9353 @Override
9354 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009355 if (numOfSims == 1) {
9356 enforceModifyPermission();
9357 } else {
9358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9359 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9360 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009361 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009362
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009363 try {
Michele30b57b22019-03-01 12:01:14 -08009364 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009365 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009366 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9367 return;
9368 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009369 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9370 } finally {
9371 Binder.restoreCallingIdentity(identity);
9372 }
9373 }
9374
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009375 @Override
9376 public boolean isApplicationOnUicc(int subId, int appType) {
9377 enforceReadPrivilegedPermission("isApplicationOnUicc");
9378 Phone phone = getPhone(subId);
9379 if (phone == null) {
9380 return false;
9381 }
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
9384 UiccCard uiccCard = phone.getUiccCard();
9385 if (uiccCard == null) {
9386 return false;
9387 }
9388 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9389 if (uiccProfile == null) {
9390 return false;
9391 }
9392 if (TelephonyManager.APPTYPE_SIM <= appType
9393 && appType <= TelephonyManager.APPTYPE_ISIM) {
9394 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9395 }
9396 return false;
9397 } finally {
9398 Binder.restoreCallingIdentity(identity);
9399 }
9400 }
9401
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009402 /**
chen xub4baa772019-04-03 10:23:41 -07009403 * Get whether making changes to modem configurations will trigger reboot.
9404 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009405 */
9406 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009407 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9408 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009410 mApp, subId, callingPackage, callingFeatureId,
9411 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009412 return false;
9413 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009414 final long identity = Binder.clearCallingIdentity();
9415 try {
9416 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
Nathan Harold29f5f052019-02-15 13:41:57 -08009422 private void updateModemStateMetrics() {
9423 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9424 // TODO: check the state for each modem if the api is ready.
9425 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9426 }
9427
Pengquan Meng3889a572019-01-23 11:16:29 -08009428 @Override
9429 public int[] getSlotsMapping() {
9430 enforceReadPrivilegedPermission("getSlotsMapping");
9431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
9434 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9435 // All logical slots should have a mapping to a physical slot.
9436 int[] logicalSlotsMapping = new int[phoneCount];
9437 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9438 for (int i = 0; i < slotInfos.length; i++) {
9439 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9440 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9441 }
9442 }
9443 return logicalSlotsMapping;
9444 } finally {
9445 Binder.restoreCallingIdentity(identity);
9446 }
9447 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009448
9449 /**
9450 * Get the IRadio HAL Version
9451 */
9452 @Override
9453 public int getRadioHalVersion() {
9454 Phone phone = getDefaultPhone();
9455 if (phone == null) return -1;
9456 HalVersion hv = phone.getHalVersion();
9457 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9458 return hv.major * 100 + hv.minor;
9459 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009460
9461 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009462 * Get the current calling package name.
9463 * @return the current calling package name
9464 */
9465 @Override
9466 public String getCurrentPackageName() {
9467 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9468 }
9469
9470 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009471 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9472 * corresponding network requests on a subId.
9473 *
9474 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009475 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009476 * 2) APN is un-metered for this subscription, or
9477 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009478 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009479 *
9480 * @return whether data is allowed for a apn type.
9481 *
9482 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009483 */
9484 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009485 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009486 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9487 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009488
9489 // Now that all security checks passes, perform the operation as ourselves.
9490 final long identity = Binder.clearCallingIdentity();
9491 try {
9492 Phone phone = getPhone(subId);
9493 if (phone == null) return false;
9494
Jack Yu41407ee2019-05-13 16:54:09 -07009495 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009496 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9497 } finally {
9498 Binder.restoreCallingIdentity(identity);
9499 }
9500 }
9501
9502 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009503 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009504 enforceReadPrivilegedPermission("isApnMetered");
9505
9506 // Now that all security checks passes, perform the operation as ourselves.
9507 final long identity = Binder.clearCallingIdentity();
9508 try {
9509 Phone phone = getPhone(subId);
9510 if (phone == null) return true; // By default return true.
9511
Jack Yu41407ee2019-05-13 16:54:09 -07009512 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009513 } finally {
9514 Binder.restoreCallingIdentity(identity);
9515 }
9516 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009517
9518 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009519 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9520 int subscriptionId, IBooleanConsumer resultCallback) {
9521 enforceModifyPermission();
9522 long token = Binder.clearCallingIdentity();
9523 try {
9524 Phone phone = getPhone(subscriptionId);
9525 if (phone == null) {
9526 try {
9527 if (resultCallback != null) {
9528 resultCallback.accept(false);
9529 }
9530 } catch (RemoteException e) {
9531 // ignore
9532 }
9533 return;
9534 }
9535 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9536 Pair.create(specifiers, (x) -> {
9537 try {
9538 if (resultCallback != null) {
9539 resultCallback.accept(x);
9540 }
9541 } catch (RemoteException e) {
9542 // ignore
9543 }
9544 });
9545 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9546 } finally {
9547 Binder.restoreCallingIdentity(token);
9548 }
9549 }
9550
9551 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009552 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009555 mApp, subId, "getSystemSelectionChannels");
9556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9557 final long identity = Binder.clearCallingIdentity();
9558 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009559 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9560 if (result instanceof IllegalStateException) {
9561 throw (IllegalStateException) result;
9562 }
9563 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009564 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9565 return specifiers;
9566 } finally {
9567 Binder.restoreCallingIdentity(identity);
9568 }
9569 }
9570
9571 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009572 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009573 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009574 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9575 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9576 if (iccRecords == null) {
9577 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9578 return false;
9579 }
9580 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9581 }
9582
9583 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009584 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9585 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009586 if (callingPackage == null) {
9587 callingPackage = getCurrentPackageName();
9588 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009589 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9590 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009591 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9592 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009593 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9594 }
9595 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9596 Intent intent = new Intent();
9597 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9598 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9599 // Bring up choose default SMS subscription dialog right now
9600 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9601 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9602 mApp.startActivity(intent);
9603 }
chen xud5ca2d52019-05-28 15:20:57 -07009604
9605 @Override
9606 public String getMmsUAProfUrl(int subId) {
9607 //TODO investigate if this API should require proper permission check in R b/133791609
9608 final long identity = Binder.clearCallingIdentity();
9609 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009610 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9611 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9612 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9613 return carrierUAProfUrl;
9614 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009615 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9616 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
9621
9622 @Override
9623 public String getMmsUserAgent(int subId) {
9624 //TODO investigate if this API should require proper permission check in R b/133791609
9625 final long identity = Binder.clearCallingIdentity();
9626 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009627 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9628 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9629 if (!TextUtils.isEmpty(carrierUserAgent)) {
9630 return carrierUserAgent;
9631 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009632 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9633 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009634 } finally {
9635 Binder.restoreCallingIdentity(identity);
9636 }
9637 }
Jack Yub07d4972019-05-28 16:12:25 -07009638
9639 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009640 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9641 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009642
Jack Yub07d4972019-05-28 16:12:25 -07009643 final long identity = Binder.clearCallingIdentity();
9644 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009645 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009646 if (phone == null) return false;
9647
Hall Liua62f5da2020-09-25 10:42:19 -07009648 switch (policy) {
9649 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9650 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9651 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9652 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9653 default:
9654 throw new IllegalArgumentException(policy + " is not a valid policy");
9655 }
Jack Yub07d4972019-05-28 16:12:25 -07009656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
9660
9661 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009662 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009663 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009664 enforceModifyPermission();
9665
changbettyd5c246e2019-12-24 15:40:37 +08009666 final long identity = Binder.clearCallingIdentity();
9667 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009668 Phone phone = getPhone(subscriptionId);
9669 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009670
Hall Liua62f5da2020-09-25 10:42:19 -07009671 switch (policy) {
9672 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9673 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9674 break;
9675 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9676 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9677 break;
9678 default:
9679 throw new IllegalArgumentException(policy + " is not a valid policy");
9680 }
changbettyd5c246e2019-12-24 15:40:37 +08009681 } finally {
9682 Binder.restoreCallingIdentity(identity);
9683 }
9684 }
9685
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009686 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009687 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009688 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9689 * otherwise.
9690 */
9691 @Override
9692 public void setCepEnabled(boolean isCepEnabled) {
9693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9694
9695 final long identity = Binder.clearCallingIdentity();
9696 try {
9697 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9698 for (Phone phone : PhoneFactory.getPhones()) {
9699 Phone defaultPhone = phone.getImsPhone();
9700 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9701 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9702 ImsPhoneCallTracker imsPhoneCallTracker =
9703 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9704 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9705 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9706 + imsPhone.getMsisdn());
9707 }
9708 }
9709 } finally {
9710 Binder.restoreCallingIdentity(identity);
9711 }
9712 }
allenwtsu46dcc572020-01-08 18:24:03 +08009713
9714 /**
9715 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9716 *
9717 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9718 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9719 * before being read.
9720 */
9721 @Override
9722 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9723 isCompressed) {
9724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9725 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9727 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9728 }
9729 if (!isImsAvailableOnDevice()) {
9730 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9731 "IMS not available on device.");
9732 }
9733
9734 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009735 try {
Hui Wang761a6682020-10-31 05:12:53 +00009736 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9737 } finally {
9738 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009739 }
9740 }
zoey chene02881a2019-12-30 16:11:23 +08009741
9742 @Override
9743 public boolean isIccLockEnabled(int subId) {
9744 enforceReadPrivilegedPermission("isIccLockEnabled");
9745
9746 // Now that all security checks passes, perform the operation as ourselves.
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 Phone phone = getPhone(subId);
9750 if (phone != null && phone.getIccCard() != null) {
9751 return phone.getIccCard().getIccLockEnabled();
9752 } else {
9753 return false;
9754 }
9755 } finally {
9756 Binder.restoreCallingIdentity(identity);
9757 }
9758 }
9759
9760 /**
9761 * Set the ICC pin lock enabled or disabled.
9762 *
9763 * @return an integer representing the status of IccLock enabled or disabled in the following
9764 * three cases:
9765 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9766 * successfully.
9767 * - Positive number and zero for remaining password attempts.
9768 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9769 *
9770 */
9771 @Override
9772 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9773 enforceModifyPermission();
9774
9775 Phone phone = getPhone(subId);
9776 if (phone == null) {
9777 return 0;
9778 }
9779 // Now that all security checks passes, perform the operation as ourselves.
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9783 new Pair<Boolean, String>(enabled, password), phone, null);
9784 return attemptsRemaining;
9785
9786 } catch (Exception e) {
9787 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 return 0;
9792 }
9793
9794 /**
9795 * Change the ICC password used in ICC pin lock.
9796 *
9797 * @return an integer representing the status of IccLock changed in the following three cases:
9798 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9799 * - Positive number and zero for remaining password attempts.
9800 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9801 *
9802 */
9803 @Override
9804 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9805 enforceModifyPermission();
9806
9807 Phone phone = getPhone(subId);
9808 if (phone == null) {
9809 return 0;
9810 }
9811 // Now that all security checks passes, perform the operation as ourselves.
9812 final long identity = Binder.clearCallingIdentity();
9813 try {
9814 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9815 new Pair<String, String>(oldPassword, newPassword), phone, null);
9816 return attemptsRemaining;
9817
9818 } catch (Exception e) {
9819 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 return 0;
9824 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009825
9826 /**
9827 * Request for receiving user activity notification
9828 */
9829 @Override
9830 public void requestUserActivityNotification() {
9831 if (!mNotifyUserActivity.get()
9832 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9833 mNotifyUserActivity.set(true);
9834 }
9835 }
9836
9837 /**
9838 * Called when userActivity is signalled in the power manager.
9839 * This is safe to call from any thread, with any window manager locks held or not.
9840 */
9841 @Override
9842 public void userActivity() {
9843 // ***************************************
9844 // * Inherited from PhoneWindowManager *
9845 // ***************************************
9846 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9847 // WITH ITS LOCKS HELD.
9848 //
9849 // This code must be VERY careful about the locks
9850 // it acquires.
9851 // In fact, the current code acquires way too many,
9852 // and probably has lurking deadlocks.
9853
9854 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9855 throw new SecurityException("Only the OS may call notifyUserActivity()");
9856 }
9857
9858 if (mNotifyUserActivity.getAndSet(false)) {
9859 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9860 USER_ACTIVITY_NOTIFICATION_DELAY);
9861 }
9862 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009863
9864 @Override
9865 public boolean canConnectTo5GInDsdsMode() {
9866 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9867 }
Jack Yud10cdd42020-09-28 20:28:01 -07009868
9869 @Override
9870 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9871 String callingFeatureId) {
9872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9873 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9874 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9875 }
9876
9877 Phone phone = getPhone(subId);
9878 if (phone == null) {
9879 throw new RuntimeException("phone is not available");
9880 }
9881 // Now that all security checks passes, perform the operation as ourselves.
9882 final long identity = Binder.clearCallingIdentity();
9883 try {
9884 return phone.getEquivalentHomePlmns();
9885 } finally {
9886 Binder.restoreCallingIdentity(identity);
9887 }
9888 }
Daniel Bright59e67312020-11-13 11:49:37 -08009889
9890 @Override
9891 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009892 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9893 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009894 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009895 if (radioInterfaceCapabilities == null) {
9896 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009897 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009898 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009899 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009900
Hui Wang641e81c2020-10-12 12:14:23 -07009901 @Override
9902 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9903 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009904 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9905 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9906 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9907 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9908 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009909 if (DBG) {
9910 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9911 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9912 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9913 }
9914
9915 if (!SubscriptionManager.isValidSubscriptionId(subId)
9916 || appType < TelephonyManager.APPTYPE_UNKNOWN
9917 || appType > TelephonyManager.APPTYPE_ISIM
9918 || nafUrl == null || securityProtocol == null || callback == null) {
9919 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9920 if (callback != null) {
9921 try {
9922 callback.onAuthenticationFailure(
9923 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9924 } catch (RemoteException exception) {
9925 log("Fail to notify onAuthenticationFailure due to " + exception);
9926 }
9927 return;
9928 }
9929 }
9930
9931 final long token = Binder.clearCallingIdentity();
9932 try {
9933 getGbaManager(subId).bootstrapAuthenticationRequest(
9934 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9935 forceBootStrapping, callback));
9936 } finally {
9937 Binder.restoreCallingIdentity(token);
9938 }
9939 }
9940
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009941 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009942 * Attempts to set the radio power state for all phones for thermal reason.
9943 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009944 * requested radio power state will actually be set. See {@link
9945 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9946 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009947 * @param enable {@code true} if trying to turn radio on.
9948 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9949 * false}.
9950 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009951 private boolean setRadioPowerForThermal(boolean enable) {
9952 boolean isPhoneAvailable = false;
9953 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9954 Phone phone = PhoneFactory.getPhone(i);
9955 if (phone != null) {
9956 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9957 isPhoneAvailable = true;
9958 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009959 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009960
9961 // return true if successfully informed the phone object about the thermal radio power
9962 // request.
9963 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009964 }
9965
9966 private int handleDataThrottlingRequest(int subId,
9967 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009968 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9969 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9970 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9971 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9972 throw new IllegalArgumentException("modem does not support data throttling");
9973 }
9974
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009975 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9976 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009977 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009978 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9979 }
9980
9981 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9982
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009983 if (isDataThrottlingSupported) {
9984 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009985 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009986 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9987 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9988 } else if (thermalMitigationResult
9989 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009990 log("Modem likely does not support data throttling on secondary carrier. Data " +
9991 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9992 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009993 }
9994 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009995 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009996
9997 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009998 }
9999
Jack Nudelman644b91a2021-03-12 14:09:48 -080010000 private static List<String> getThermalMitigationAllowlist(Context context) {
10001 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10002 for (String pckg : context.getResources()
10003 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10004 sThermalMitigationAllowlistedPackages.add(pckg);
10005 }
10006 }
10007
10008 return sThermalMitigationAllowlistedPackages;
10009 }
10010
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010011 private boolean isAnyPhoneInEmergencyState() {
10012 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10013 if (tm.isInEmergencyCall()) {
10014 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10015 return true;
10016 }
10017 for (Phone phone : PhoneFactory.getPhones()) {
10018 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10019 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10020 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10021 + phone.isInEcm());
10022 return true;
10023 }
10024 }
10025
10026 return false;
10027 }
10028
Jack Nudelman644b91a2021-03-12 14:09:48 -080010029 /**
10030 * Used by shell commands to add an authorized package name for thermal mitigation.
10031 * @param packageName name of package to be allowlisted
10032 * @param context
10033 */
10034 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10035 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10036 sThermalMitigationAllowlistedPackages.add(packageName);
10037 }
10038
10039 /**
10040 * Used by shell commands to remove an authorized package name for thermal mitigation.
10041 * @param packageName name of package to remove from allowlist
10042 * @param context
10043 */
10044 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10045 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10046 sThermalMitigationAllowlistedPackages.remove(packageName);
10047 }
10048
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010049 /**
10050 * Thermal mitigation request to control functionalities at modem.
10051 *
10052 * @param subId the id of the subscription.
10053 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010054 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055 *
10056 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10057 */
10058 @Override
10059 @ThermalMitigationResult
10060 public int sendThermalMitigationRequest(
10061 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010062 ThermalMitigationRequest thermalMitigationRequest,
10063 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010064 enforceModifyPermission();
10065
Jack Nudelman644b91a2021-03-12 14:09:48 -080010066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10067 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10068 .contains(callingPackage)) {
10069 throw new SecurityException("Calling package must be configured in the device config. "
10070 + "calling package: " + callingPackage);
10071 }
10072
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10074 final long identity = Binder.clearCallingIdentity();
10075
10076 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10077 try {
10078 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10079 switch (thermalMitigationAction) {
10080 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10081 thermalMitigationResult =
10082 handleDataThrottlingRequest(subId,
10083 thermalMitigationRequest.getDataThrottlingRequest());
10084 break;
10085 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10086 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10087 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10088 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10089 }
10090
10091 // Ensure that radio is on. If not able to power on due to phone being
10092 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010093 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010094 thermalMitigationResult =
10095 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10096 break;
10097 }
10098
10099 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10100 false);
10101 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10102 break;
10103 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10104 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10105 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10106 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10107 }
10108
10109 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10110 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010111 Phone phone = getPhone(subId);
10112 if (phone == null) {
10113 thermalMitigationResult =
10114 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10115 break;
10116 }
10117
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010118 TelephonyConnectionService service =
10119 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010120 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010121 Log.e(LOG_TAG, "An emergency call is pending");
10122 thermalMitigationResult =
10123 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10124 break;
10125 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010126 thermalMitigationResult =
10127 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10128 break;
10129 }
10130 } else {
10131 thermalMitigationResult =
10132 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10133 break;
10134 }
10135
10136 // Turn radio off. If not able to power off due to phone being unavailable,
10137 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010138 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010139 thermalMitigationResult =
10140 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10141 break;
10142 }
10143 thermalMitigationResult =
10144 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10145 break;
10146 default:
10147 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10148 + "not exist. Requested action: " + thermalMitigationAction);
10149 }
10150 } catch (IllegalArgumentException e) {
10151 throw e;
10152 } catch (Exception e) {
10153 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10154 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10155 } finally {
10156 Binder.restoreCallingIdentity(identity);
10157 }
10158
10159 if (DBG) {
10160 log("thermalMitigationRequest returning with thermalMitigationResult: "
10161 + thermalMitigationResult);
10162 }
10163
10164 return thermalMitigationResult;
10165 }
Hui Wang641e81c2020-10-12 12:14:23 -070010166
10167 /**
10168 * Set the GbaService Package Name that Telephony will bind to.
10169 *
10170 * @param subId The sim that the GbaService is associated with.
10171 * @param packageName The name of the package to be replaced with.
10172 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10173 */
10174 @Override
10175 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10176 enforceModifyPermission();
10177
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 return getGbaManager(subId).overrideServicePackage(packageName);
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 /**
10187 * Return the package name of the currently bound GbaService.
10188 *
10189 * @param subId The sim that the GbaService is associated with.
10190 * @return the package name of the GbaService configuration, null if GBA is not supported.
10191 */
10192 @Override
10193 public String getBoundGbaService(int subId) {
10194 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10195
10196 final long identity = Binder.clearCallingIdentity();
10197 try {
10198 return getGbaManager(subId).getServicePackage();
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
10201 }
10202 }
10203
10204 /**
10205 * Set the release time for telephony to unbind GbaService.
10206 *
10207 * @param subId The sim that the GbaService is associated with.
10208 * @param interval The release time to unbind GbaService by millisecond.
10209 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10210 */
10211 @Override
10212 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10213 enforceModifyPermission();
10214
10215 final long identity = Binder.clearCallingIdentity();
10216 try {
10217 return getGbaManager(subId).overrideReleaseTime(interval);
10218 } finally {
10219 Binder.restoreCallingIdentity(identity);
10220 }
10221 }
10222
10223 /**
10224 * Return the release time for telephony to unbind GbaService.
10225 *
10226 * @param subId The sim that the GbaService is associated with.
10227 * @return The release time to unbind GbaService by millisecond.
10228 */
10229 @Override
10230 public int getGbaReleaseTime(int subId) {
10231 enforceReadPrivilegedPermission("getGbaReleaseTime");
10232
10233 final long identity = Binder.clearCallingIdentity();
10234 try {
10235 return getGbaManager(subId).getReleaseTime();
10236 } finally {
10237 Binder.restoreCallingIdentity(identity);
10238 }
10239 }
10240
10241 private GbaManager getGbaManager(int subId) {
10242 GbaManager instance = GbaManager.getInstance(subId);
10243 if (instance == null) {
10244 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10245 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10246 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10247 }
10248 return instance;
10249 }
Hui Wang761a6682020-10-31 05:12:53 +000010250
10251 /**
10252 * indicate whether the device and the carrier can support
10253 * RCS VoLTE single registration.
10254 */
10255 @Override
10256 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010257 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10258 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10259 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10260 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010261
10262 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10263 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10264 }
10265
10266 final long identity = Binder.clearCallingIdentity();
10267 try {
10268 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10269 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010270 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10271 if (isCapable != null) {
10272 return isCapable;
10273 }
Hui Wang761a6682020-10-31 05:12:53 +000010274 }
Hui Wang67af90e2021-06-04 16:57:15 -070010275 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10276 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
10281
10282 /**
10283 * Register RCS provisioning callback.
10284 */
10285 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010286 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010287 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010288 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010289 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010290 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10291 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010292
10293 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10294 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10295 }
10296 if (!isImsAvailableOnDevice()) {
10297 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10298 "IMS not available on device.");
10299 }
10300
10301 final long identity = Binder.clearCallingIdentity();
10302 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010303 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010304 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010305 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10306 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010307 }
Hui Wang761a6682020-10-31 05:12:53 +000010308 } finally {
10309 Binder.restoreCallingIdentity(identity);
10310 }
10311 }
10312
10313 /**
10314 * Unregister RCS provisioning callback.
10315 */
10316 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010317 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010318 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010319 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010320 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010321 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10322 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010323
10324 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10325 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10326 }
10327 if (!isImsAvailableOnDevice()) {
10328 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10329 "IMS not available on device.");
10330 }
10331
10332 final long identity = Binder.clearCallingIdentity();
10333 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010334 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010335 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
10340
10341 /**
10342 * trigger RCS reconfiguration.
10343 */
10344 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010345 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10346 "triggerRcsReconfiguration",
10347 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010348
10349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10351 }
10352 if (!isImsAvailableOnDevice()) {
10353 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10354 "IMS not available on device.");
10355 }
10356
10357 final long identity = Binder.clearCallingIdentity();
10358 try {
10359 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
10365 /**
10366 * Provide the client configuration parameters of the RCS application.
10367 */
10368 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010369 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10370 "setRcsClientConfiguration",
10371 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010372
10373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10374 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10375 }
10376 if (!isImsAvailableOnDevice()) {
10377 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10378 "IMS not available on device.");
10379 }
10380
10381 final long identity = Binder.clearCallingIdentity();
10382
10383 try {
10384 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10385 if (configBinder == null) {
10386 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010387 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10388 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010389 } else {
10390 configBinder.setRcsClientConfiguration(rcc);
10391 }
10392 } catch (RemoteException e) {
10393 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010394 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10395 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010396 } finally {
10397 Binder.restoreCallingIdentity(identity);
10398 }
10399 }
10400
10401 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010402 * Enables or disables the test mode for RCS VoLTE single registration.
10403 */
10404 @Override
10405 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10406 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10407 "setRcsSingleRegistrationTestModeEnabled");
10408
10409 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10410 }
10411
10412 /**
10413 * Gets the test mode for RCS VoLTE single registration.
10414 */
10415 @Override
10416 public boolean getRcsSingleRegistrationTestModeEnabled() {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "getRcsSingleRegistrationTestModeEnabled");
10419
10420 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10421 }
10422
10423 /**
Hui Wang761a6682020-10-31 05:12:53 +000010424 * Overrides the config of RCS VoLTE single registration enabled for the device.
10425 */
10426 @Override
10427 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "setDeviceSingleRegistrationEnabledOverride");
10430 enforceModifyPermission();
10431
10432 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10433 : Boolean.parseBoolean(enabledStr);
10434 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010435 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010436 }
10437
10438 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010439 * Sends a device to device communication message. Only usable via shell.
10440 * @param message message to send.
10441 * @param value message value.
10442 */
10443 @Override
10444 public void sendDeviceToDeviceMessage(int message, int value) {
10445 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010446 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010447 enforceModifyPermission();
10448
10449 final long identity = Binder.clearCallingIdentity();
10450 try {
10451 TelephonyConnectionService service =
10452 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10453 if (service == null) {
10454 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10455 return;
10456 }
10457 service.sendTestDeviceToDeviceMessage(message, value);
10458 } finally {
10459 Binder.restoreCallingIdentity(identity);
10460 }
10461 }
10462
Tyler Gunnbabbda02021-02-10 11:05:02 -080010463 /**
10464 * Sets the specified device to device transport active.
10465 * @param transport The transport to set active.
10466 */
10467 @Override
10468 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10469 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10470 "setActiveDeviceToDeviceTransport");
10471 enforceModifyPermission();
10472
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 TelephonyConnectionService service =
10476 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10477 if (service == null) {
10478 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10479 return;
10480 }
10481 service.setActiveDeviceToDeviceTransport(transport);
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
Tyler Gunn92479152021-01-20 16:30:10 -080010486
Tyler Gunnd4575212021-05-03 14:46:49 -070010487 @Override
10488 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "setDeviceToDeviceForceEnabled");
10491
10492 final long identity = Binder.clearCallingIdentity();
10493 try {
10494 Arrays.stream(PhoneFactory.getPhones()).forEach(
10495 p -> {
10496 Phone thePhone = p.getImsPhone();
10497 if (thePhone != null && thePhone instanceof ImsPhone) {
10498 ImsPhone imsPhone = (ImsPhone) thePhone;
10499 CallTracker tracker = imsPhone.getCallTracker();
10500 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10501 ImsPhoneCallTracker imsPhoneCallTracker =
10502 (ImsPhoneCallTracker) tracker;
10503 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10504 }
10505 }
10506 }
10507 );
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
Tyler Gunn92479152021-01-20 16:30:10 -080010513 /**
Hui Wang761a6682020-10-31 05:12:53 +000010514 * Gets the config of RCS VoLTE single registration enabled for the device.
10515 */
10516 @Override
10517 public boolean getDeviceSingleRegistrationEnabled() {
10518 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10519 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10520 }
10521
10522 /**
10523 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10524 */
10525 @Override
10526 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10527 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10528 "setCarrierSingleRegistrationEnabledOverride");
10529 enforceModifyPermission();
10530
10531 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10532 : Boolean.parseBoolean(enabledStr);
10533 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10534 subId, enabled);
10535 }
10536
10537 /**
10538 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10539 */
10540 @Override
10541 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10542 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10543 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10544 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010545
10546 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010547 * Overrides the ims feature validation result
10548 */
10549 @Override
10550 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10552 "setImsFeatureValidationOverride");
10553
10554 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10555 : Boolean.parseBoolean(enabledStr);
10556 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10557 subId, enabled);
10558 }
10559
10560 /**
10561 * Gets the ims feature validation override value
10562 */
10563 @Override
10564 public boolean getImsFeatureValidationOverride(int subId) {
10565 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10566 "getImsFeatureValidationOverride");
10567 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10568 }
10569
10570 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010571 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10572 * their mobile plan.
10573 */
10574 @Override
10575 public String getMobileProvisioningUrl() {
10576 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10577 final long identity = Binder.clearCallingIdentity();
10578 try {
10579 return getDefaultPhone().getMobileProvisioningUrl();
10580 } finally {
10581 Binder.restoreCallingIdentity(identity);
10582 }
10583 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010584
James.cf Linbcdf8b32021-01-14 16:44:13 +080010585 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010586 * Get the EAB contact from the EAB database.
10587 */
10588 @Override
10589 public String getContactFromEab(String contact) {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10591 enforceModifyPermission();
10592 final long identity = Binder.clearCallingIdentity();
10593 try {
10594 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 /**
Calvin Pana1434322021-07-01 19:27:01 +080010601 * Get the EAB capability from the EAB database.
10602 */
10603 @Override
10604 public String getCapabilityFromEab(String contact) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10606 enforceModifyPermission();
10607 final long identity = Binder.clearCallingIdentity();
10608 try {
10609 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
10615 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010616 * Remove the EAB contacts from the EAB database.
10617 */
10618 @Override
10619 public int removeContactFromEab(int subId, String contacts) {
10620 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10621 enforceModifyPermission();
10622 final long identity = Binder.clearCallingIdentity();
10623 try {
10624 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
10629
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010630 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010631 public boolean getDeviceUceEnabled() {
10632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return mApp.getDeviceUceEnabled();
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
10641 @Override
10642 public void setDeviceUceEnabled(boolean isEnabled) {
10643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 mApp.setDeviceUceEnabled(isEnabled);
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
Brad Ebinger14d467f2021-02-12 06:18:28 +000010652 /**
10653 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10654 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10655 */
10656 // Used for SHELL command only right now.
10657 @Override
10658 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10659 List<String> featureTags) {
10660 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10661 "addUceRegistrationOverrideShell");
10662 final long identity = Binder.clearCallingIdentity();
10663 try {
10664 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10665 new ArraySet<>(featureTags));
10666 } catch (ImsException e) {
10667 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10668 } finally {
10669 Binder.restoreCallingIdentity(identity);
10670 }
10671 }
10672
10673 /**
10674 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10675 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10676 */
10677 // Used for SHELL command only right now.
10678 @Override
10679 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10680 List<String> featureTags) {
10681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10682 "removeUceRegistrationOverrideShell");
10683 final long identity = Binder.clearCallingIdentity();
10684 try {
10685 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10686 new ArraySet<>(featureTags));
10687 } catch (ImsException e) {
10688 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10689 } finally {
10690 Binder.restoreCallingIdentity(identity);
10691 }
10692 }
10693
10694 /**
10695 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10696 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10697 */
10698 // Used for SHELL command only right now.
10699 @Override
10700 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10701 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10702 "clearUceRegistrationOverrideShell");
10703 final long identity = Binder.clearCallingIdentity();
10704 try {
10705 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10706 } catch (ImsException e) {
10707 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 /**
10714 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10715 */
10716 // Used for SHELL command only right now.
10717 @Override
10718 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10719 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10720 "getLatestRcsContactUceCapabilityShell");
10721 final long identity = Binder.clearCallingIdentity();
10722 try {
10723 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10724 } catch (ImsException e) {
10725 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10726 } finally {
10727 Binder.restoreCallingIdentity(identity);
10728 }
10729 }
10730
10731 /**
10732 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10733 * device does not have an active PUBLISH.
10734 */
10735 // Used for SHELL command only right now.
10736 @Override
10737 public String getLastUcePidfXmlShell(int subId) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10739 final long identity = Binder.clearCallingIdentity();
10740 try {
10741 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10742 } catch (ImsException e) {
10743 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
10748
James.cf Line8713a42021-04-29 16:04:26 +080010749 /**
10750 * Remove UCE requests cannot be sent to the network status.
10751 */
10752 // Used for SHELL command only right now.
10753 @Override
10754 public boolean removeUceRequestDisallowedStatus(int subId) {
10755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10756 final long identity = Binder.clearCallingIdentity();
10757 try {
10758 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10759 } catch (ImsException e) {
10760 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10761 } finally {
10762 Binder.restoreCallingIdentity(identity);
10763 }
10764 }
10765
James.cf Lin0fc71b02021-05-25 01:37:38 +080010766 /**
10767 * Remove UCE requests cannot be sent to the network status.
10768 */
10769 // Used for SHELL command only.
10770 @Override
10771 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10773 final long identity = Binder.clearCallingIdentity();
10774 try {
10775 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10776 } catch (ImsException e) {
10777 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010782
James.cf Lin4b784aa2021-01-31 03:25:15 +080010783 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010784 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10785 String callingPackage) {
10786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10787 mApp, subId, "setSignalStrengthUpdateRequest");
10788
10789 final int callingUid = Binder.getCallingUid();
10790 // Verify that tha callingPackage belongs to the calling UID
10791 mApp.getSystemService(AppOpsManager.class)
10792 .checkPackage(callingUid, callingPackage);
10793
10794 validateSignalStrengthUpdateRequest(request, callingUid);
10795
10796 final long identity = Binder.clearCallingIdentity();
10797 try {
10798 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10799 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10800
10801 if (result instanceof IllegalStateException) {
10802 throw (IllegalStateException) result;
10803 }
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
10808
10809 @Override
10810 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10811 String callingPackage) {
10812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10813 mApp, subId, "clearSignalStrengthUpdateRequest");
10814
10815 final int callingUid = Binder.getCallingUid();
10816 // Verify that tha callingPackage belongs to the calling UID
10817 mApp.getSystemService(AppOpsManager.class)
10818 .checkPackage(callingUid, callingPackage);
10819
10820 final long identity = Binder.clearCallingIdentity();
10821 try {
10822 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10823 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10824
10825 if (result instanceof IllegalStateException) {
10826 throw (IllegalStateException) result;
10827 }
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
10833 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10834 int callingUid) {
10835 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10836 // phone/system process do not have further restriction on request
10837 return;
10838 }
10839
10840 // Applications has restrictions on how to use the request:
10841 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10842 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10843 // This is not system caller which has been checked above
10844 throw new IllegalArgumentException(
10845 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10846 }
10847
10848 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10849 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10850 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10851 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10852 || info.isEnabled()) {
10853 throw new IllegalArgumentException(
10854 "Only system can set hide fields in SignalThresholdInfo");
10855 }
10856
10857 // Thresholds length for each RAN need in range. This has been validated in
10858 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10859 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10860 final int[] thresholds = info.getThresholds();
10861 Objects.requireNonNull(thresholds);
10862 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10863 || thresholds.length
10864 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10865 throw new IllegalArgumentException(
10866 "thresholds length is out of range: " + thresholds.length);
10867 }
10868 }
10869 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010870
10871 /**
10872 * Gets the current phone capability.
10873 *
10874 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10875 * @return the PhoneCapability which describes the data connection capability of modem.
10876 * It's used to evaluate possible phone config change, for example from single
10877 * SIM device to multi-SIM device.
10878 */
10879 @Override
10880 public PhoneCapability getPhoneCapability() {
10881 enforceReadPrivilegedPermission("getPhoneCapability");
10882 final long identity = Binder.clearCallingIdentity();
10883 try {
10884 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10885 } finally {
10886 Binder.restoreCallingIdentity(identity);
10887 }
10888 }
Michele Berionne5e411512020-11-13 02:36:59 +000010889
10890 /**
10891 * Prepare TelephonyManager for an unattended reboot. The reboot is
10892 * required to be done shortly after the API is invoked.
10893 */
10894 @Override
10895 @TelephonyManager.PrepareUnattendedRebootResult
10896 public int prepareForUnattendedReboot() {
10897 enforceRebootPermission();
10898
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
10901 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10902 } finally {
10903 Binder.restoreCallingIdentity(identity);
10904 }
10905 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010906
10907 /**
10908 * Request to get the current slicing configuration including URSP rules and
10909 * NSSAIs (configured, allowed and rejected).
10910 *
10911 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10912 */
10913 @Override
10914 public void getSlicingConfig(ResultReceiver callback) {
10915 enforceReadPrivilegedPermission("getSlicingConfig");
10916
10917 final long identity = Binder.clearCallingIdentity();
10918 try {
10919 Phone phone = getDefaultPhone();
10920 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010925}