blob: e59d91a009d4256466af14a04936d0ec8d18123f [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800345 // Parameters of select command.
346 private static final int SELECT_COMMAND = 0xA4;
347 private static final int SELECT_P1 = 0x04;
348 private static final int SELECT_P2 = 0;
349 private static final int SELECT_P3 = 0x10;
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /** The singleton instance. */
352 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800353 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800357 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700358 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700360 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800362 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700364 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800365 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 /** User Activity */
368 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
370
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700371 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
372
Derek Tan97ebb422014-09-05 16:55:38 -0700373 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
374 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800375 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800376 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700377
Michelecea4cf22018-12-21 15:00:11 -0800378 // String to store multi SIM allowed
379 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
380
Derek Tan740e1672017-06-27 14:56:27 -0700381 // The AID of ISD-R.
382 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
383
yinxub1bed742017-04-17 11:45:04 -0700384 private NetworkScanRequestTracker mNetworkScanRequestTracker;
385
David Kelly5e06a7f2018-03-12 14:10:59 +0000386 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
387 private static final int MANUFACTURER_CODE_LENGTH = 8;
388
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800390 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391
Derek Tan89e89d42014-07-08 17:00:10 -0700392 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700393 * Experiment flag to enable erase modem config on reset network, default value is false
394 */
395 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
396 "reset_network_erase_modem_config_enabled";
397
Rambo Wang0f050d82021-02-12 11:43:36 -0800398 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
399
Naina Nallurid63128d2019-09-17 14:10:30 -0700400 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class IccAPDUArgument {
404 public int channel, cla, command, p1, p2, p3;
405 public String data;
406
407 public IccAPDUArgument(int channel, int cla, int command,
408 int p1, int p2, int p3, String data) {
409 this.channel = channel;
410 this.cla = cla;
411 this.command = command;
412 this.p1 = p1;
413 this.p2 = p2;
414 this.p3 = p3;
415 this.data = data;
416 }
417 }
418
419 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700420 * A request object to use for transmitting data to an ICC.
421 */
422 private static final class ManualNetworkSelectionArgument {
423 public OperatorInfo operatorInfo;
424 public boolean persistSelection;
425
426 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
427 this.operatorInfo = operatorInfo;
428 this.persistSelection = persistSelection;
429 }
430 }
431
432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
434 * request after sending. The main thread will notify the request when it is complete.
435 */
436 private static final class MainThreadRequest {
437 /** The argument to use for the request */
438 public Object argument;
439 /** The result of the request that is run on the main thread */
440 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 // The subscriber id that this request applies to. Defaults to
442 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
443 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 // In cases where subId is unavailable, the caller needs to specify the phone.
446 public Phone phone;
447
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 public WorkSource workSource;
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 public MainThreadRequest(Object argument) {
451 this.argument = argument;
452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453
Nathan Harold92bed182018-10-12 18:16:49 -0700454 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
455 this.argument = argument;
456 if (phone != null) {
457 this.phone = phone;
458 }
459 this.workSource = workSource;
460 }
461
vagdeviaf9a5b92018-08-15 16:01:53 -0700462 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800463 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 if (subId != null) {
465 this.subId = subId;
466 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 }
470
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800471 private static final class IncomingThirdPartyCallArgs {
472 public final ComponentName component;
473 public final String callId;
474 public final String callerDisplayName;
475
476 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
477 String callerDisplayName) {
478 this.component = component;
479 this.callId = callId;
480 this.callerDisplayName = callerDisplayName;
481 }
482 }
483
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 /**
485 * A handler that processes messages on the main thread in the phone process. Since many
486 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
487 * inbound binder threads to the main thread in the phone process. The Binder thread
488 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
489 * on, which will be notified when the operation completes and will contain the result of the
490 * request.
491 *
492 * <p>If a MainThreadRequest object is provided in the msg.obj field,
493 * note that request.result must be set to something non-null for the calling thread to
494 * unblock.
495 */
496 private final class MainThreadHandler extends Handler {
497 @Override
498 public void handleMessage(Message msg) {
499 MainThreadRequest request;
500 Message onCompleted;
501 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800504 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
506 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 case CMD_HANDLE_USSD_REQUEST: {
508 request = (MainThreadRequest) msg.obj;
509 final Phone phone = getPhoneFromRequest(request);
510 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
511 String ussdRequest = ussdObject.first;
512 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 if (!isUssdApiAllowed(request.subId)) {
515 // Carrier does not support use of this API, return failure.
516 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
517 UssdResponse response = new UssdResponse(ussdRequest, null);
518 Bundle returnData = new Bundle();
519 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
520 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 request.result = true;
523 notifyRequester(request);
524 return;
525 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 try {
528 request.result = phone != null
529 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
530 } catch (CallStateException cse) {
531 request.result = false;
532 }
533 // Wake up the requesting thread
534 notifyRequester(request);
535 break;
pkanwar32d516d2016-10-14 19:37:38 -0700536 }
537
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700540 final Phone phone = getPhoneFromRequest(request);
541 request.result = phone != null ?
542 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
543 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccTransmitApduLogicalChannel: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
559 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 iccArgument.channel, iccArgument.cla, iccArgument.command,
562 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800576 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800578 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
580 loge("iccTransmitApduLogicalChannel: Unknown exception");
581 }
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
588 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (uiccCard == null) {
591 loge("iccTransmitApduBasicChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
596 request);
597 uiccCard.iccTransmitApduBasicChannel(
598 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
599 iccArgument.p3, iccArgument.data, onCompleted);
600 }
601 break;
602
603 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("iccTransmitApduBasicChannel: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("iccTransmitApduBasicChannel: CommandException: " +
614 ar.exception);
615 } else {
616 loge("iccTransmitApduBasicChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 break;
621
622 case CMD_EXCHANGE_SIM_IO:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 if (uiccCard == null) {
627 loge("iccExchangeSimIO: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
632 request);
633 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
634 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
635 iccArgument.data, onCompleted);
636 }
637 break;
638
639 case EVENT_EXCHANGE_SIM_IO_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
645 request.result = new IccIoResult(0x6f, 0, (byte[])null);
646 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 break;
649
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 case CMD_SEND_ENVELOPE:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("sendEnvelopeWithStatus: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
659 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
660 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
663 case EVENT_SEND_ENVELOPE_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700669 request.result = new IccIoResult(0x6F, 0, (byte[])null);
670 if (ar.result == null) {
671 loge("sendEnvelopeWithStatus: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("sendEnvelopeWithStatus: CommandException: " +
674 ar.exception);
675 } else {
676 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
677 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800680 break;
681
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 case CMD_OPEN_CHANNEL:
683 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800684 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800685 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800688 request.result = new IccOpenLogicalChannelResponse(-1,
689 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800693 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
694 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
698 case EVENT_OPEN_CHANNEL_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 int[] result = (int[]) ar.result;
704 int channelId = result[0];
705 byte[] selectResponse = null;
706 if (result.length > 1) {
707 selectResponse = new byte[result.length - 1];
708 for (int i = 1; i < result.length; ++i) {
709 selectResponse[i - 1] = (byte) result[i];
710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 if (ar.result == null) {
716 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.exception != null) {
719 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
720 }
721
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700722 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700723 if (ar.exception instanceof CommandException) {
724 CommandException.Error error =
725 ((CommandException) (ar.exception)).getCommandError();
726 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700728 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700729 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 }
731 }
732 openChannelResp = new IccOpenLogicalChannelResponse(
733 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700735 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case CMD_CLOSE_CHANNEL:
740 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800741 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 if (uiccCard == null) {
743 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900744 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
748 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 break;
751
752 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800753 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
754 break;
755
756 case CMD_NV_READ_ITEM:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800766 if (ar.exception == null && ar.result != null) {
767 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800769 request.result = "";
770 if (ar.result == null) {
771 loge("nvReadItem: Empty response");
772 } else if (ar.exception instanceof CommandException) {
773 loge("nvReadItem: CommandException: " +
774 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800776 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 }
778 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 break;
781
Jake Hambye994d462014-02-03 13:10:13 -0800782 case CMD_NV_WRITE_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
785 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700787 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_ITEM_DONE:
791 handleNullReturnEvent(msg, "nvWriteItem");
792 break;
793
794 case CMD_NV_WRITE_CDMA_PRL:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
800 case EVENT_NV_WRITE_CDMA_PRL_DONE:
801 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
802 break;
803
chen xu6dac5ab2018-10-26 17:39:23 -0700804 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800805 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700806 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800807 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case EVENT_RESET_MODEM_CONFIG_DONE:
811 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
Sooraj Sasindran37444802020-08-11 10:40:43 -0700814 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
817 request);
818 Phone phone = getPhoneFromRequest(request);
819 if (phone != null) {
820 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
821 } else {
822 loge("isNRDualConnectivityEnabled: No phone object");
823 request.result = false;
824 notifyRequester(request);
825 }
826 break;
827 }
828
829 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 // request.result must be set to something non-null
836 // for the calling thread to unblock
837 if (request.result != null) {
838 request.result = ar.result;
839 } else {
840 request.result = false;
841 }
842 if (ar.result == null) {
843 loge("isNRDualConnectivityEnabled: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("isNRDualConnectivityEnabled: CommandException: "
846 + ar.exception);
847 } else {
848 loge("isNRDualConnectivityEnabled: Unknown exception");
849 }
850 }
851 notifyRequester(request);
852 break;
853
854 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
857 Phone phone = getPhoneFromRequest(request);
858 if (phone != null) {
859 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
860 request.workSource);
861 } else {
862 loge("enableNrDualConnectivity: No phone object");
863 request.result =
864 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 notifyRequester(request);
866 }
867 break;
868 }
869
870 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null) {
874 request.result =
875 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
876 } else {
877 request.result =
878 TelephonyManager
879 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000887 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
888 request.result =
889 TelephonyManager
890 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700891 }
892 loge("enableNrDualConnectivity" + ": CommandException: "
893 + ar.exception);
894 } else {
895 loge("enableNrDualConnectivity" + ": Unknown exception");
896 }
897 }
898 notifyRequester(request);
899 break;
900 }
901
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
905 request);
906 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result; // Integer
914 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530915 // request.result must be set to something non-null
916 // for the calling thread to unblock
917 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: CommandException: "
922 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 break;
929
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800932 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
933 request);
934 Pair<Integer, Long> reasonWithNetworkTypes =
935 (Pair<Integer, Long>) request.argument;
936 getPhoneFromRequest(request).setAllowedNetworkTypes(
937 reasonWithNetworkTypes.first,
938 reasonWithNetworkTypes.second,
939 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
SongFerngWang3ef3e072020-12-21 16:41:52 +0800942 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
943 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800944 break;
945
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
947 request = (MainThreadRequest)msg.obj;
948 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800949 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000950 break;
951
952 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
953 ar = (AsyncResult)msg.obj;
954 request = (MainThreadRequest)ar.userObj;
955 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000957 break;
958
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800959 case CMD_SET_VOICEMAIL_NUMBER:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
962 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800963 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
964 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800965 break;
966
967 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
968 handleNullReturnEvent(msg, "setVoicemailNumber");
969 break;
970
Stuart Scott54788802015-03-30 13:18:01 -0700971 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
974 request);
975 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
976 break;
977
978 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
979 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
980 break;
981
Shishir Agrawal302c8692015-06-19 13:49:39 -0700982 case CMD_PERFORM_NETWORK_SCAN:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
985 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
986 break;
987
Hall Liu27d24262020-09-18 19:04:59 -0700988 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700991 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
992 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument;
994 int callForwardingReason = args.first;
995 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800996 break;
Hall Liu27d24262020-09-18 19:04:59 -0700997 }
998 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001001 TelephonyManager.CallForwardingInfoCallback callback =
1002 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1003 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001005 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1007 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1008 // Service Class is a bit mask per 3gpp 27.007. Search for
1009 // any service for voice call.
1010 if ((callForwardInfo.serviceClass
1011 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001012 callForwardingInfo = new CallForwardingInfo(
1013 callForwardInfo.status
1014 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001015 callForwardInfo.reason,
1016 callForwardInfo.number,
1017 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001018 break;
1019 }
1020 }
1021 // Didn't find a call forward info for voice call.
1022 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001023 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1024 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 }
Hall Liu27d24262020-09-18 19:04:59 -07001026 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001027 } else {
1028 if (ar.result == null) {
1029 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1030 }
1031 if (ar.exception != null) {
1032 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1033 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001034 int errorCode = TelephonyManager
1035 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager
1041 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001042 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001043 errorCode = TelephonyManager
1044 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001045 }
1046 }
Hall Liu27d24262020-09-18 19:04:59 -07001047 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049 break;
Hall Liu27d24262020-09-18 19:04:59 -07001050 }
Shuo Qian4a594052020-01-23 11:59:30 -08001051
Hall Liu27d24262020-09-18 19:04:59 -07001052 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001053 request = (MainThreadRequest) msg.obj;
1054 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001055 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001056 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001057 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1058 request.argument).first;
1059 request.phone.setCallForwardingOption(
1060 callForwardingInfoToSet.isEnabled()
1061 ? CommandsInterface.CF_ACTION_ENABLE
1062 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001063 callForwardingInfoToSet.getReason(),
1064 callForwardingInfoToSet.getNumber(),
1065 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1066 break;
Hall Liu27d24262020-09-18 19:04:59 -07001067 }
Shuo Qian4a594052020-01-23 11:59:30 -08001068
Hall Liu27d24262020-09-18 19:04:59 -07001069 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001072 Consumer<Integer> callback =
1073 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1074 request.argument).second;
1075 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001077 int errorCode = TelephonyManager.CallForwardingInfoCallback
1078 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001079 if (ar.exception instanceof CommandException) {
1080 CommandException.Error error =
1081 ((CommandException) (ar.exception)).getCommandError();
1082 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001083 errorCode = TelephonyManager.CallForwardingInfoCallback
1084 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001086 errorCode = TelephonyManager.CallForwardingInfoCallback
1087 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001088 }
1089 }
1090 callback.accept(errorCode);
1091 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001092 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094 break;
Hall Liu27d24262020-09-18 19:04:59 -07001095 }
Shuo Qian4a594052020-01-23 11:59:30 -08001096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1100 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1101 break;
Hall Liu27d24262020-09-18 19:04:59 -07001102 }
Shuo Qian4a594052020-01-23 11:59:30 -08001103
Hall Liu27d24262020-09-18 19:04:59 -07001104 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001108 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1109 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 // Service Class is a bit mask per 3gpp 27.007.
1112 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001113 if (callForwardResults.length > 1
1114 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001115 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001116 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001117 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1118 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001119 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001120 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 }
1122 } else {
1123 if (ar.result == null) {
1124 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1125 }
1126 if (ar.exception != null) {
1127 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1128 }
1129 if (ar.exception instanceof CommandException) {
1130 CommandException.Error error =
1131 ((CommandException) (ar.exception)).getCommandError();
1132 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1133 callForwardingStatus =
1134 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1135 }
1136 }
1137 }
Hall Liu27d24262020-09-18 19:04:59 -07001138 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001139 break;
Hall Liu27d24262020-09-18 19:04:59 -07001140 }
Shuo Qian4a594052020-01-23 11:59:30 -08001141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1146 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001147 break;
Hall Liu27d24262020-09-18 19:04:59 -07001148 }
Shuo Qian4a594052020-01-23 11:59:30 -08001149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001153 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1154 Consumer<Integer> callback =
1155 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1156 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001158 if (ar.exception instanceof CommandException) {
1159 CommandException.Error error =
1160 ((CommandException) (ar.exception)).getCommandError();
1161 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1163 } else {
1164 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1165 }
1166 } else {
1167 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1168 }
1169 } else {
1170 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1171 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 }
Shuo Qian4a594052020-01-23 11:59:30 -08001173 break;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001175 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
1178 CellNetworkScanResult cellScanResult;
1179 if (ar.exception == null && ar.result != null) {
1180 cellScanResult = new CellNetworkScanResult(
1181 CellNetworkScanResult.STATUS_SUCCESS,
1182 (List<OperatorInfo>) ar.result);
1183 } else {
1184 if (ar.result == null) {
1185 loge("getCellNetworkScanResults: Empty response");
1186 }
1187 if (ar.exception != null) {
1188 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1189 }
1190 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1191 if (ar.exception instanceof CommandException) {
1192 CommandException.Error error =
1193 ((CommandException) (ar.exception)).getCommandError();
1194 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1195 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1196 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1197 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1198 }
1199 }
1200 cellScanResult = new CellNetworkScanResult(errorCode, null);
1201 }
1202 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001203 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 break;
1205
1206 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1207 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001208 ManualNetworkSelectionArgument selArg =
1209 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1211 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001212 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1213 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001214 break;
1215
1216 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null) {
1220 request.result = true;
1221 } else {
1222 request.result = false;
1223 loge("setNetworkSelectionModeManual " + ar.exception);
1224 }
1225 notifyRequester(request);
1226 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001227 break;
1228
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 case CMD_GET_MODEM_ACTIVITY_INFO:
1230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001232 if (defaultPhone != null) {
1233 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001234 } else {
1235 ResultReceiver result = (ResultReceiver) request.argument;
1236 Bundle bundle = new Bundle();
1237 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001238 new ModemActivityInfo(0, 0, 0,
1239 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001240 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001241 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 break;
1243
Hall Liud0f208c2020-10-14 16:54:44 -07001244 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 ar = (AsyncResult) msg.obj;
1246 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 ResultReceiver result = (ResultReceiver) request.argument;
1248
Hall Liud0f208c2020-10-14 16:54:44 -07001249 ModemActivityInfo ret = null;
1250 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001251 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001252 // Update the last modem activity info and the result of the request.
1253 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1254 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001255 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001256 int[] txTimeMs = info.getTransmitTimeMillis();
1257 int[] lastModemTxTimeMs = mLastModemActivityInfo
1258 .getTransmitTimeMillis();
1259 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1260 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1261 }
Hall Liu49656c02020-10-09 19:00:11 -07001262 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001263 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1264 + mLastModemActivityInfo.getSleepTimeMillis());
1265 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1266 + mLastModemActivityInfo.getIdleTimeMillis());
1267 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1268 mLastModemActivityInfo.setReceiveTimeMillis(
1269 info.getReceiveTimeMillis()
1270 + mLastModemActivityInfo.getReceiveTimeMillis());
1271 }
Hall Liu49656c02020-10-09 19:00:11 -07001272 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001273 mLastModemActivityInfo.getSleepTimeMillis(),
1274 mLastModemActivityInfo.getIdleTimeMillis(),
1275 mLastModemActivityInfo.getTransmitTimeMillis(),
1276 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else {
1278 if (ar.result == null) {
1279 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 } else if (ar.exception instanceof CommandException) {
1283 loge("queryModemActivityInfo: CommandException: " +
1284 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001285 error = TelephonyManager.ModemActivityInfoException
1286 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001287 } else {
1288 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001289 error = TelephonyManager.ModemActivityInfoException
1290 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001291 }
1292 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001293 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001294 if (ret != null) {
1295 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1296 } else {
1297 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1298 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001299 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001300 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001301 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001302 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001303
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 case CMD_SET_ALLOWED_CARRIERS:
1305 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001306 CarrierRestrictionRules argument =
1307 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001309 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 break;
1311
1312 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null && ar.result != null) {
1316 request.result = ar.result;
1317 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001318 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1319 if (ar.exception instanceof CommandException) {
1320 loge("setAllowedCarriers: CommandException: " + ar.exception);
1321 CommandException.Error error =
1322 ((CommandException) (ar.exception)).getCommandError();
1323 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1324 request.result =
1325 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1326 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 } else {
1328 loge("setAllowedCarriers: Unknown exception");
1329 }
1330 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001332 break;
1333
1334 case CMD_GET_ALLOWED_CARRIERS:
1335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001337 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001338 break;
1339
1340 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 if (ar.exception == null && ar.result != null) {
1344 request.result = ar.result;
1345 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001346 request.result = new IllegalStateException(
1347 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001348 if (ar.result == null) {
1349 loge("getAllowedCarriers: Empty response");
1350 } else if (ar.exception instanceof CommandException) {
1351 loge("getAllowedCarriers: CommandException: " +
1352 ar.exception);
1353 } else {
1354 loge("getAllowedCarriers: Unknown exception");
1355 }
1356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001358 break;
1359
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 if (ar.exception == null && ar.result != null) {
1364 request.result = ar.result;
1365 } else {
1366 request.result = new IllegalArgumentException(
1367 "Failed to retrieve Forbidden Plmns");
1368 if (ar.result == null) {
1369 loge("getForbiddenPlmns: Empty response");
1370 } else {
1371 loge("getForbiddenPlmns: Unknown exception");
1372 }
1373 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001375 break;
1376
1377 case CMD_GET_FORBIDDEN_PLMNS:
1378 request = (MainThreadRequest) msg.obj;
1379 uiccCard = getUiccCardFromRequest(request);
1380 if (uiccCard == null) {
1381 loge("getForbiddenPlmns() UiccCard is null");
1382 request.result = new IllegalArgumentException(
1383 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001384 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001385 break;
1386 }
1387 Integer appType = (Integer) request.argument;
1388 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1389 if (uiccApp == null) {
1390 loge("getForbiddenPlmns() no app with specified type -- "
1391 + appType);
1392 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001394 break;
1395 } else {
1396 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1397 + " specified type -- " + appType);
1398 }
1399 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1400 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1401 onCompleted);
1402 break;
1403
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001404 case CMD_SWITCH_SLOTS:
1405 request = (MainThreadRequest) msg.obj;
1406 int[] physicalSlots = (int[]) request.argument;
1407 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1408 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1409 break;
1410
1411 case EVENT_SWITCH_SLOTS_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001415 notifyRequester(request);
1416 break;
1417 case CMD_GET_NETWORK_SELECTION_MODE:
1418 request = (MainThreadRequest) msg.obj;
1419 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1420 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1421 break;
1422
1423 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception != null) {
1427 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1428 } else {
1429 int mode = ((int[]) ar.result)[0];
1430 if (mode == 0) {
1431 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1432 } else {
1433 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1434 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001435 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 notifyRequester(request);
1437 break;
1438 case CMD_GET_CDMA_ROAMING_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1441 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1442 break;
1443 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception != null) {
1447 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1448 } else {
1449 request.result = ((int[]) ar.result)[0];
1450 }
1451 notifyRequester(request);
1452 break;
1453 case CMD_SET_CDMA_ROAMING_MODE:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1456 int mode = (int) request.argument;
1457 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1458 break;
1459 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 request.result = ar.exception == null;
1463 notifyRequester(request);
1464 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001465 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1468 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1469 break;
1470 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception != null) {
1474 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1475 } else {
1476 request.result = ((int[]) ar.result)[0];
1477 }
1478 notifyRequester(request);
1479 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1481 request = (MainThreadRequest) msg.obj;
1482 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1483 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001484 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1485 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001486 break;
1487 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
1490 request.result = ar.exception == null;
1491 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001492 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 case CMD_GET_ALL_CELL_INFO:
1494 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001496 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 case EVENT_GET_ALL_CELL_INFO_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001501 // If a timeout occurs, the response will be null
1502 request.result = (ar.exception == null && ar.result != null)
1503 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001508 case CMD_REQUEST_CELL_INFO_UPDATE:
1509 request = (MainThreadRequest) msg.obj;
1510 request.phone.requestCellInfoUpdate(request.workSource,
1511 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1512 break;
1513 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1514 ar = (AsyncResult) msg.obj;
1515 request = (MainThreadRequest) ar.userObj;
1516 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1517 try {
1518 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001520 cb.onError(
1521 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1522 ar.exception.getClass().getName(),
1523 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001524 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001525 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001526 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001527 } else {
1528 // use the result as returned
1529 cb.onCellInfo((List<CellInfo>) ar.result);
1530 }
1531 } catch (RemoteException re) {
1532 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1533 }
1534 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001535 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 request = (MainThreadRequest) msg.obj;
1537 WorkSource ws = (WorkSource) request.argument;
1538 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001539 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001541 }
1542 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null) {
1546 request.result = ar.result;
1547 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001548 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001549 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001550 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001551 }
1552
1553 synchronized (request) {
1554 request.notifyAll();
1555 }
1556 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001557 }
chen xu6dac5ab2018-10-26 17:39:23 -07001558 case CMD_MODEM_REBOOT:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001561 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001562 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001563 case EVENT_CMD_MODEM_REBOOT_DONE:
1564 handleNullReturnEvent(msg, "rebootModem");
1565 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 case CMD_REQUEST_ENABLE_MODEM:
1567 request = (MainThreadRequest) msg.obj;
1568 boolean enable = (boolean) request.argument;
1569 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001570 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001571 PhoneConfigurationManager.getInstance()
1572 .enablePhone(request.phone, enable, onCompleted);
1573 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001574 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001579 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001580 if ((boolean) request.result) {
1581 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1582 updateModemStateMetrics();
1583 } else {
1584 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1585 + ar.exception);
1586 }
1587 notifyRequester(request);
1588 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001589 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001590 case CMD_GET_MODEM_STATUS:
1591 request = (MainThreadRequest) msg.obj;
1592 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1593 PhoneConfigurationManager.getInstance()
1594 .getPhoneStatusFromModem(request.phone, onCompleted);
1595 break;
1596 case EVENT_GET_MODEM_STATUS_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 int id = request.phone.getPhoneId();
1600 if (ar.exception == null && ar.result != null) {
1601 request.result = ar.result;
1602 //update the cache as modem status has changed
1603 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1604 (boolean) request.result);
1605 } else {
1606 // Return true if modem status cannot be retrieved. For most cases,
1607 // modem status is on. And for older version modems, GET_MODEM_STATUS
1608 // and disable modem are not supported. Modem is always on.
1609 // TODO: this should be fixed in R to support a third
1610 // status UNKNOWN b/131631629
1611 request.result = true;
1612 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1613 + ar.exception);
1614 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001615 notifyRequester(request);
1616 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001617 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1618 request = (MainThreadRequest) msg.obj;
1619 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1620 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1621 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1622 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1623 break;
1624 }
1625 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1629 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1630 args.second.accept(ar.exception == null);
1631 notifyRequester(request);
1632 break;
1633 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001634 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1637 Phone phone = getPhoneFromRequest(request);
1638 if (phone != null) {
1639 phone.getSystemSelectionChannels(onCompleted);
1640 } else {
1641 loge("getSystemSelectionChannels: No phone object");
1642 request.result = new ArrayList<RadioAccessSpecifier>();
1643 notifyRequester(request);
1644 }
1645 break;
1646 }
1647 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 if (ar.exception == null && ar.result != null) {
1651 request.result = ar.result;
1652 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001653 request.result = new IllegalStateException(
1654 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001655 if (ar.result == null) {
1656 loge("getSystemSelectionChannels: Empty response");
1657 } else {
1658 loge("getSystemSelectionChannels: Unknown exception");
1659 }
1660 }
1661 notifyRequester(request);
1662 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001663 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 if (ar.exception == null && ar.result != null) {
1667 request.result = ar.result;
1668 } else {
1669 request.result = -1;
1670 loge("Failed to set Forbidden Plmns");
1671 if (ar.result == null) {
1672 loge("setForbidenPlmns: Empty response");
1673 } else if (ar.exception != null) {
1674 loge("setForbiddenPlmns: Exception: " + ar.exception);
1675 request.result = -1;
1676 } else {
1677 loge("setForbiddenPlmns: Unknown exception");
1678 }
1679 }
1680 notifyRequester(request);
1681 break;
1682 case CMD_SET_FORBIDDEN_PLMNS:
1683 request = (MainThreadRequest) msg.obj;
1684 uiccCard = getUiccCardFromRequest(request);
1685 if (uiccCard == null) {
1686 loge("setForbiddenPlmns: UiccCard is null");
1687 request.result = -1;
1688 notifyRequester(request);
1689 break;
1690 }
1691 Pair<Integer, List<String>> setFplmnsArgs =
1692 (Pair<Integer, List<String>>) request.argument;
1693 appType = setFplmnsArgs.first;
1694 List<String> fplmns = setFplmnsArgs.second;
1695 uiccApp = uiccCard.getApplicationByType(appType);
1696 if (uiccApp == null) {
1697 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1698 request.result = -1;
1699 loge("Failed to get UICC App");
1700 notifyRequester(request);
1701 } else {
1702 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1703 ((SIMRecords) uiccApp.getIccRecords())
1704 .setForbiddenPlmns(onCompleted, fplmns);
1705 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001706 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001707 case CMD_ERASE_MODEM_CONFIG:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1710 defaultPhone.eraseModemConfig(onCompleted);
1711 break;
1712 case EVENT_ERASE_MODEM_CONFIG_DONE:
1713 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001714 break;
zoey chene02881a2019-12-30 16:11:23 +08001715
Kai Shif70f46f2021-03-03 13:59:46 -08001716 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1717 request = (MainThreadRequest) msg.obj;
1718 request.result = defaultPhone.eraseDataInSharedPreferences();
1719 notifyRequester(request);
1720 break;
1721
zoey chene02881a2019-12-30 16:11:23 +08001722 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1725 Pair<String, String> changed = (Pair<String, String>) request.argument;
1726 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1727 changed.first, changed.second, onCompleted);
1728 break;
1729 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception == null) {
1733 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 // If the operation is successful, update the PIN storage
1735 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1736 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001737 UiccController.getInstance().getPinStorage()
1738 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001739 } else {
1740 request.result = msg.arg1;
1741 }
1742 notifyRequester(request);
1743 break;
1744
Michele Berionne5e411512020-11-13 02:36:59 +00001745 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1748 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1749 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1750 enabled.first, enabled.second, onCompleted);
1751 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001752 }
zoey chene02881a2019-12-30 16:11:23 +08001753 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null) {
1757 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001758 // If the operation is successful, update the PIN storage
1759 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1760 int phoneId = getPhoneFromRequest(request).getPhoneId();
1761 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001762 UiccController.getInstance().getPinStorage()
1763 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001764 } else {
1765 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1766 }
zoey chene02881a2019-12-30 16:11:23 +08001767 } else {
1768 request.result = msg.arg1;
1769 }
Michele Berionne5e411512020-11-13 02:36:59 +00001770
1771
zoey chene02881a2019-12-30 16:11:23 +08001772 notifyRequester(request);
1773 break;
1774
Peter Wangdafb9ac2020-01-15 14:13:38 -08001775 case MSG_NOTIFY_USER_ACTIVITY:
1776 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001777 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001778 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1779 getDefaultPhone().getContext().sendBroadcastAsUser(
1780 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1781 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001782
1783 case CMD_SET_DATA_THROTTLING: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1786 DataThrottlingRequest dataThrottlingRequest =
1787 (DataThrottlingRequest) request.argument;
1788 Phone phone = getPhoneFromRequest(request);
1789 if (phone != null) {
1790 phone.setDataThrottling(onCompleted,
1791 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1792 dataThrottlingRequest.getCompletionDurationMillis());
1793 } else {
1794 loge("setDataThrottling: No phone object");
1795 request.result =
1796 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1797 notifyRequester(request);
1798 }
1799
1800 break;
1801 }
1802 case EVENT_SET_DATA_THROTTLING_DONE:
1803 ar = (AsyncResult) msg.obj;
1804 request = (MainThreadRequest) ar.userObj;
1805
1806 if (ar.exception == null) {
1807 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1808 } else if (ar.exception instanceof CommandException) {
1809 loge("setDataThrottling: CommandException: " + ar.exception);
1810 CommandException.Error error =
1811 ((CommandException) (ar.exception)).getCommandError();
1812
1813 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1814 request.result = TelephonyManager
1815 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1816 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1817 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001818 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1819 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001820 } else {
1821 request.result =
1822 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1823 }
1824 } else {
1825 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1826 }
1827 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1828 notifyRequester(request);
1829 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001830
1831 case CMD_SET_SIM_POWER: {
1832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1834 request = (MainThreadRequest) msg.obj;
1835 int stateToSet =
1836 ((Pair<Integer, IIntegerConsumer>)
1837 request.argument).first;
1838 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1839 break;
1840 }
1841 case EVENT_SET_SIM_POWER_DONE: {
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 IIntegerConsumer callback =
1845 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1846 if (ar.exception != null) {
1847 loge("setSimPower exception: " + ar.exception);
1848 int errorCode = TelephonyManager.CallForwardingInfoCallback
1849 .RESULT_ERROR_UNKNOWN;
1850 if (ar.exception instanceof CommandException) {
1851 CommandException.Error error =
1852 ((CommandException) (ar.exception)).getCommandError();
1853 if (error == CommandException.Error.SIM_ERR) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1855 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1857 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1858 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1859 } else {
1860 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1861 }
1862 }
1863 try {
1864 callback.accept(errorCode);
1865 } catch (RemoteException e) {
1866 // Ignore if the remote process is no longer available to call back.
1867 Log.w(LOG_TAG, "setSimPower: callback not available.");
1868 }
1869 } else {
1870 try {
1871 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1872 } catch (RemoteException e) {
1873 // Ignore if the remote process is no longer available to call back.
1874 Log.w(LOG_TAG, "setSimPower: callback not available.");
1875 }
1876 }
1877 break;
1878 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001879 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1880 request = (MainThreadRequest) msg.obj;
1881
1882 final Phone phone = getPhoneFromRequest(request);
1883 if (phone == null || phone.getServiceStateTracker() == null) {
1884 request.result = new IllegalStateException("Phone or SST is null");
1885 notifyRequester(request);
1886 break;
1887 }
1888
1889 Pair<Integer, SignalStrengthUpdateRequest> pair =
1890 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1891 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1892 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001893 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001894 request.subId, pair.first /*callingUid*/,
1895 pair.second /*request*/, onCompleted);
1896 break;
1897 }
1898 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 // request.result will be the exception of ar if present, true otherwise.
1902 // Be cautious not to leave result null which will wait() forever
1903 request.result = ar.exception != null ? ar.exception : true;
1904 notifyRequester(request);
1905 break;
1906 }
1907 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1908 request = (MainThreadRequest) msg.obj;
1909
1910 Phone phone = getPhoneFromRequest(request);
1911 if (phone == null || phone.getServiceStateTracker() == null) {
1912 request.result = new IllegalStateException("Phone or SST is null");
1913 notifyRequester(request);
1914 break;
1915 }
1916
1917 Pair<Integer, SignalStrengthUpdateRequest> pair =
1918 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1919 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1920 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001921 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001922 request.subId, pair.first /*callingUid*/,
1923 pair.second /*request*/, onCompleted);
1924 break;
1925 }
1926 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 request.result = ar.exception != null ? ar.exception : true;
1930 notifyRequester(request);
1931 break;
1932 }
Jordan Liu109698e2020-11-24 14:50:34 -08001933
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001934 case CMD_GET_SLICING_CONFIG: {
1935 request = (MainThreadRequest) msg.obj;
1936 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1937 request.phone.getSlicingConfig(onCompleted);
1938 break;
1939 }
1940 case EVENT_GET_SLICING_CONFIG_DONE: {
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 ResultReceiver result = (ResultReceiver) request.argument;
1944
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001945 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001946 Bundle bundle = new Bundle();
1947 int resultCode = 0;
1948 if (ar.exception != null) {
1949 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1950 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001951 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001952 } else if (ar.result == null) {
1953 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001954 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001955 } else {
1956 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001957 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1958 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001959 }
1960
1961 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001962 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001963 }
1964 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1965 result.send(resultCode, bundle);
1966 notifyRequester(request);
1967 break;
1968 }
1969
Michele Berionne5e411512020-11-13 02:36:59 +00001970 case CMD_PREPARE_UNATTENDED_REBOOT:
1971 request = (MainThreadRequest) msg.obj;
1972 request.result =
1973 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1974 notifyRequester(request);
1975 break;
1976
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 default:
1978 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1979 break;
1980 }
1981 }
Jake Hambye994d462014-02-03 13:10:13 -08001982
Pengquan Menga1bb6272018-09-06 09:59:22 -07001983 private void notifyRequester(MainThreadRequest request) {
1984 synchronized (request) {
1985 request.notifyAll();
1986 }
1987 }
1988
Jake Hambye994d462014-02-03 13:10:13 -08001989 private void handleNullReturnEvent(Message msg, String command) {
1990 AsyncResult ar = (AsyncResult) msg.obj;
1991 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1992 if (ar.exception == null) {
1993 request.result = true;
1994 } else {
1995 request.result = false;
1996 if (ar.exception instanceof CommandException) {
1997 loge(command + ": CommandException: " + ar.exception);
1998 } else {
1999 loge(command + ": Unknown exception");
2000 }
2001 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002002 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 }
2005
2006 /**
2007 * Posts the specified command to be executed on the main thread,
2008 * waits for the request to complete, and returns the result.
2009 * @see #sendRequestAsync
2010 */
2011 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2013 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002014 }
2015
2016 /**
2017 * Posts the specified command to be executed on the main thread,
2018 * waits for the request to complete, and returns the result.
2019 * @see #sendRequestAsync
2020 */
2021 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2022 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002023 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002024 }
2025
2026 /**
2027 * Posts the specified command to be executed on the main thread,
2028 * waits for the request to complete, and returns the result.
2029 * @see #sendRequestAsync
2030 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002031 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002032 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2033 }
2034
2035 /**
2036 * Posts the specified command to be executed on the main thread,
2037 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2038 * if not timeout or null otherwise.
2039 * @see #sendRequestAsync
2040 */
2041 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2042 long timeoutInMs) {
2043 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002044 }
2045
2046 /**
2047 * Posts the specified command to be executed on the main thread,
2048 * waits for the request to complete, and returns the result.
2049 * @see #sendRequestAsync
2050 */
Nathan Harold92bed182018-10-12 18:16:49 -07002051 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002052 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002053 }
2054
2055 /**
2056 * Posts the specified command to be executed on the main thread,
2057 * waits for the request to complete, and returns the result.
2058 * @see #sendRequestAsync
2059 */
2060 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002061 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2062 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002063 }
2064
2065 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002066 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2067 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2068 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002069 * @see #sendRequestAsync
2070 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002071 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2072 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2074 throw new RuntimeException("This method will deadlock if called from the main thread.");
2075 }
2076
Nathan Harold92bed182018-10-12 18:16:49 -07002077 MainThreadRequest request = null;
2078 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2079 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2080 } else if (phone != null) {
2081 request = new MainThreadRequest(argument, phone, workSource);
2082 } else {
2083 request = new MainThreadRequest(argument, subId, workSource);
2084 }
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 Message msg = mMainThreadHandler.obtainMessage(command, request);
2087 msg.sendToTarget();
2088
Rambo Wang0f050d82021-02-12 11:43:36 -08002089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002091 if (timeoutInMs >= 0) {
2092 // Wait for at least timeoutInMs before returning null request result
2093 long now = SystemClock.elapsedRealtime();
2094 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002095 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002096 try {
2097 request.wait(deadline - now);
2098 } catch (InterruptedException e) {
2099 // Do nothing, go back and check if request is completed or timeout
2100 } finally {
2101 now = SystemClock.elapsedRealtime();
2102 }
2103 }
2104 } else {
2105 // Wait for the request to complete
2106 while (request.result == null) {
2107 try {
2108 request.wait();
2109 } catch (InterruptedException e) {
2110 // Do nothing, go back and wait until the request is complete
2111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113 }
2114 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002115 if (request.result == null) {
2116 Log.wtf(LOG_TAG,
2117 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 return request.result;
2120 }
2121
2122 /**
2123 * Asynchronous ("fire and forget") version of sendRequest():
2124 * Posts the specified command to be executed on the main thread, and
2125 * returns immediately.
2126 * @see #sendRequest
2127 */
2128 private void sendRequestAsync(int command) {
2129 mMainThreadHandler.sendEmptyMessage(command);
2130 }
2131
2132 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002135 */
2136 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002137 sendRequestAsync(command, argument, null, null);
2138 }
2139
2140 /**
2141 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2142 * @see {@link #sendRequest(int,Object)}
2143 */
2144 private void sendRequestAsync(
2145 int command, Object argument, Phone phone, WorkSource workSource) {
2146 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002147 Message msg = mMainThreadHandler.obtainMessage(command, request);
2148 msg.sendToTarget();
2149 }
2150
2151 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 * Initialize the singleton PhoneInterfaceManager instance.
2153 * This is only done once, at startup, from PhoneApp.onCreate().
2154 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 synchronized (PhoneInterfaceManager.class) {
2157 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002158 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 } else {
2160 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2161 }
2162 return sInstance;
2163 }
2164 }
2165
2166 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002167 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002170 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002171 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002173 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002175 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002176 mTelephonySharedPreferences =
2177 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002178 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002179 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002180 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002181 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 publish();
2184 }
2185
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002186 private Phone getDefaultPhone() {
2187 Phone thePhone = getPhone(getDefaultSubscription());
2188 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2189 }
2190
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 private void publish() {
2192 if (DBG) log("publish: " + this);
2193
Peter Wangc035ce42020-01-08 21:00:22 -08002194 TelephonyFrameworkInitializer
2195 .getTelephonyServiceManager()
2196 .getTelephonyServiceRegisterer()
2197 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
Stuart Scott584921c2015-01-15 17:10:34 -08002200 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002201 if (request.phone != null) {
2202 return request.phone;
2203 } else {
2204 return getPhoneFromSubId(request.subId);
2205 }
2206 }
2207
2208 private Phone getPhoneFromSubId(int subId) {
2209 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2210 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002211 }
2212
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002213 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2214 Phone phone = getPhoneFromRequest(request);
2215 return phone == null ? null :
2216 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2217 }
2218
Wink Saville36469e72014-06-11 15:17:00 -07002219 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002221 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223
Kai Shif70f46f2021-03-03 13:59:46 -08002224 private void sendEraseModemConfig(@NonNull Phone phone) {
2225 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2226 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2227 }
2228
2229 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2230 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2231 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002232 }
2233
Peter Wang44b186e2020-01-13 23:33:09 -08002234 private boolean isImsAvailableOnDevice() {
2235 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2236 if (pm == null) {
2237 // For some reason package manger is not available.. This will fail internally anyway,
2238 // so do not throw error and allow.
2239 return true;
2240 }
2241 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2242 }
2243
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002245 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002246 }
2247
Wink Savilleb564aae2014-10-23 10:18:09 -07002248 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 if (DBG) log("dial: " + number);
2250 // No permission check needed here: This is just a wrapper around the
2251 // ACTION_DIAL intent, which is available to any app since it puts up
2252 // the UI before it does anything.
2253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 String url = createTelUrl(number);
2257 if (url == null) {
2258 return;
2259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 // PENDING: should we just silently fail if phone is offhook or ringing?
2262 PhoneConstants.State state = mCM.getState(subId);
2263 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2264 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2265 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2266 mApp.startActivity(intent);
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271 }
2272
2273 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002274 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002275 }
2276
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 if (DBG) log("call: " + number);
2279
2280 // This is just a wrapper around the ACTION_CALL intent, but we still
2281 // need to do a permission check since we're calling startActivity()
2282 // from the context of the phone app.
2283 enforceCallPermission();
2284
Jordan Liu1617b712019-07-10 15:06:26 -07002285 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 != AppOpsManager.MODE_ALLOWED) {
2287 return;
2288 }
2289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 String url = createTelUrl(number);
2293 if (url == null) {
2294 return;
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 boolean isValid = false;
2298 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2299 if (slist != null) {
2300 for (SubscriptionInfo subInfoRecord : slist) {
2301 if (subInfoRecord.getSubscriptionId() == subId) {
2302 isValid = true;
2303 break;
2304 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002305 }
Wink Saville08874612014-08-31 19:19:58 -07002306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (!isValid) {
2308 return;
2309 }
Wink Saville08874612014-08-31 19:19:58 -07002310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2312 intent.putExtra(SUBSCRIPTION_KEY, subId);
2313 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2314 mApp.startActivity(intent);
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
Wink Savilleb564aae2014-10-23 10:18:09 -07002320 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002321 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2323 }
2324
Wink Savilleb564aae2014-10-23 10:18:09 -07002325 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002326 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002327 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2328 }
2329
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332
2333 final long identity = Binder.clearCallingIdentity();
2334 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002335 Phone phone = getPhone(subId);
2336 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 checkSimPin.start();
2338 return checkSimPin.unlockSim(null, pin);
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
2341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002349 Phone phone = getPhone(subId);
2350 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 checkSimPuk.start();
2352 return checkSimPuk.unlockSim(puk, pin);
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357
2358 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002359 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 * a synchronous one.
2361 */
2362 private static class UnlockSim extends Thread {
2363
2364 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002365 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
2367 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002368 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2369 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370
2371 // For replies from SimCard interface
2372 private Handler mHandler;
2373
2374 // For async handler to identify request type
2375 private static final int SUPPLY_PIN_COMPLETE = 100;
2376
Michele Berionne5e411512020-11-13 02:36:59 +00002377 UnlockSim(int phoneId, IccCard simCard) {
2378 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 mSimCard = simCard;
2380 }
2381
2382 @Override
2383 public void run() {
2384 Looper.prepare();
2385 synchronized (UnlockSim.this) {
2386 mHandler = new Handler() {
2387 @Override
2388 public void handleMessage(Message msg) {
2389 AsyncResult ar = (AsyncResult) msg.obj;
2390 switch (msg.what) {
2391 case SUPPLY_PIN_COMPLETE:
2392 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2393 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002394 mRetryCount = msg.arg1;
2395 if (ar.exception != null) {
2396 if (ar.exception instanceof CommandException &&
2397 ((CommandException)(ar.exception)).getCommandError()
2398 == CommandException.Error.PASSWORD_INCORRECT) {
2399 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002400 } //When UiccCardApp dispose,handle message and return exception
2401 else if (ar.exception instanceof CommandException &&
2402 ((CommandException) (ar.exception)).getCommandError()
2403 == CommandException.Error.ABORTED) {
2404 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002405 } else {
2406 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2407 }
2408 } else {
2409 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 mDone = true;
2412 UnlockSim.this.notifyAll();
2413 }
2414 break;
2415 }
2416 }
2417 };
2418 UnlockSim.this.notifyAll();
2419 }
2420 Looper.loop();
2421 }
2422
2423 /*
2424 * Use PIN or PUK to unlock SIM card
2425 *
2426 * If PUK is null, unlock SIM card with PIN
2427 *
2428 * If PUK is not null, unlock SIM card with PUK and set PIN code
2429 */
Wink Saville9de0f752013-10-22 19:04:03 -07002430 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431
2432 while (mHandler == null) {
2433 try {
2434 wait();
2435 } catch (InterruptedException e) {
2436 Thread.currentThread().interrupt();
2437 }
2438 }
2439 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2440
2441 if (puk == null) {
2442 mSimCard.supplyPin(pin, callback);
2443 } else {
2444 mSimCard.supplyPuk(puk, pin, callback);
2445 }
2446
2447 while (!mDone) {
2448 try {
2449 Log.d(LOG_TAG, "wait for done");
2450 wait();
2451 } catch (InterruptedException e) {
2452 // Restore the interrupted status
2453 Thread.currentThread().interrupt();
2454 }
2455 }
2456 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002457 int[] resultArray = new int[2];
2458 resultArray[0] = mResult;
2459 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002460
2461 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002462 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002463 }
2464
Wink Saville9de0f752013-10-22 19:04:03 -07002465 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467 }
2468
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002469 /**
2470 * This method has been removed due to privacy and stability concerns.
2471 */
2472 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002474 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2475 return;
Wink Saville36469e72014-06-11 15:17:00 -07002476 }
2477
Nathan Harold1f889d82020-06-04 17:05:26 -07002478 @Override
2479 public void updateServiceLocationWithPackageName(String callingPackage) {
2480 mApp.getSystemService(AppOpsManager.class)
2481 .checkPackage(Binder.getCallingUid(), callingPackage);
2482
Nathan Haroldf096d982020-11-18 17:18:06 -08002483 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002484 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2485 // Callers targeting S have no business invoking this method.
2486 return;
2487 }
2488
2489 LocationAccessPolicy.LocationPermissionResult locationResult =
2490 LocationAccessPolicy.checkLocationPermission(mApp,
2491 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2492 .setCallingPackage(callingPackage)
2493 .setCallingFeatureId(null)
2494 .setCallingPid(Binder.getCallingPid())
2495 .setCallingUid(Binder.getCallingUid())
2496 .setMethod("updateServiceLocation")
2497 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2498 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2499 .build());
2500 // Apps that lack location permission have no business calling this method;
2501 // however, because no permission was declared in the public API, denials must
2502 // all be "soft".
2503 switch (locationResult) {
2504 case DENIED_HARD: /* fall through */
2505 case DENIED_SOFT:
2506 return;
2507 }
2508
2509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 final long identity = Binder.clearCallingIdentity();
2511 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002512 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002514 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002521 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
2523 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002524 return isRadioOnWithFeature(callingPackage, null);
2525 }
2526
2527
2528 @Override
2529 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2530 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2531 callingFeatureId);
2532 }
2533
2534 @Deprecated
2535 @Override
2536 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2537 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
2539
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002541 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2542 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002544 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002545 return false;
2546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 return isRadioOnForSubscriber(subId);
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 }
2555
2556 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2562 } else {
2563 return false;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
2570 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002571 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
Wink Saville36469e72014-06-11 15:17:00 -07002573
Wink Savilleb564aae2014-10-23 10:18:09 -07002574 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
2588 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002589 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Wink Savilleb564aae2014-10-23 10:18:09 -07002592 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone == null) {
2599 return false;
2600 }
2601 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2602 toggleRadioOnOffForSubscriber(subId);
2603 }
2604 return true;
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
Wink Saville36469e72014-06-11 15:17:00 -07002609
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002610 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002611 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002612 /*
2613 * If any of the Radios are available, it will need to be
2614 * shutdown. So return true if any Radio is available.
2615 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2619 Phone phone = PhoneFactory.getPhone(i);
2620 if (phone != null && phone.isRadioAvailable()) return true;
2621 }
2622 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2623 return false;
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002626 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002627 }
2628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002630 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 enforceModifyPermission();
2632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2636 logv("Shutting down Phone " + i);
2637 shutdownRadioUsingPhoneId(i);
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002641 }
2642 }
2643
2644 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002645 Phone phone = PhoneFactory.getPhone(phoneId);
2646 if (phone != null && phone.isRadioAvailable()) {
2647 phone.shutdownRadio();
2648 }
2649 }
2650
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2657 if (defaultPhone != null) {
2658 defaultPhone.setRadioPower(turnOn);
2659 return true;
2660 } else {
2661 loge("There's no default phone.");
2662 return false;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002666 }
Wink Saville36469e72014-06-11 15:17:00 -07002667 }
2668
Wink Savilleb564aae2014-10-23 10:18:09 -07002669 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
2672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 if (phone != null) {
2676 phone.setRadioPower(turnOn);
2677 return true;
2678 } else {
2679 return false;
2680 }
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
Wink Saville36469e72014-06-11 15:17:00 -07002686 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002687 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 public boolean enableDataConnectivity() {
2689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 int subId = mSubscriptionController.getDefaultDataSubId();
2694 final Phone phone = getPhone(subId);
2695 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002696 phone.getDataEnabledSettings().setDataEnabled(
2697 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 return true;
2699 } else {
2700 return false;
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 }
2706
Wink Saville36469e72014-06-11 15:17:00 -07002707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 public boolean disableDataConnectivity() {
2710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 int subId = mSubscriptionController.getDefaultDataSubId();
2715 final Phone phone = getPhone(subId);
2716 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002717 phone.getDataEnabledSettings().setDataEnabled(
2718 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 return true;
2720 } else {
2721 return false;
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002729 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002734 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 } else {
2736 return false;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
pkanwarae03a6b2016-11-06 20:37:09 -08002747 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 enforceCallPermission();
2749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2753 return;
2754 }
2755 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2756 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
pkanwar32d516d2016-10-14 19:37:38 -07002760 };
2761
Wink Savilleb564aae2014-10-23 10:18:09 -07002762 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2768 return false;
2769 }
2770 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002776 /**
2777 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2778 * tag on getCallState Binder call.
2779 */
2780 @Deprecated
2781 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002783 if (CompatChanges.isChangeEnabled(
2784 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2785 Binder.getCallingUid())) {
2786 // Do not allow this API to be called on API version 31+, it should only be
2787 // called on old apps using this Binder call directly.
2788 throw new SecurityException("This method can only be used for applications "
2789 + "targeting API version 30 or less.");
2790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002793 Phone phone = getPhone(getDefaultSubscription());
2794 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2795 PhoneConstantConversions.convertCallState(phone.getState());
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
2799 }
2800
2801 @Override
2802 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2803 if (CompatChanges.isChangeEnabled(
2804 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2805 Binder.getCallingUid())) {
2806 // Check READ_PHONE_STATE for API version 31+
2807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2808 featureId, "getCallStateForSubscription")) {
2809 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2810 + "targeting API level 31+.");
2811 }
2812 }
2813 final long identity = Binder.clearCallingIdentity();
2814 try {
2815 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2817 PhoneConstantConversions.convertCallState(phone.getState());
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002824 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002825 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2826 }
2827
2828 @Override
2829 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 if (phone != null) {
2834 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2835 } else {
2836 return PhoneConstantConversions.convertDataState(
2837 PhoneConstants.DataState.DISCONNECTED);
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002845 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002846 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2847 }
2848
2849 @Override
2850 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002853 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 if (phone != null) {
2855 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2856 } else {
2857 return TelephonyManager.DATA_ACTIVITY_NONE;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002865 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002867 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002868
2869 LocationAccessPolicy.LocationPermissionResult locationResult =
2870 LocationAccessPolicy.checkLocationPermission(mApp,
2871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2872 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002873 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002874 .setCallingPid(Binder.getCallingPid())
2875 .setCallingUid(Binder.getCallingUid())
2876 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2879 .build());
2880 switch (locationResult) {
2881 case DENIED_HARD:
2882 throw new SecurityException("Not allowed to access cell location");
2883 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002884 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2885 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
2887
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002892 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002893 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
Svetoslav64fad262015-04-14 14:35:21 -07002897 }
2898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002900 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002901 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2902 // registered cell info, so return a NULL country instead.
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002905 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2906 // Get default phone in this case.
2907 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2908 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002909 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002911 if (phone == null) return "";
2912 ServiceStateTracker sst = phone.getServiceStateTracker();
2913 if (sst == null) return "";
2914 LocaleTracker lt = sst.getLocaleTracker();
2915 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002916 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002920 }
2921
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002922 /**
2923 * This method was removed due to potential issues caused by performing partial
2924 * updates of service state, and lack of a credible use case.
2925 *
2926 * This has the ability to break the telephony implementation by disabling notification of
2927 * changes in device connectivity. DO NOT USE THIS!
2928 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002929 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 public void enableLocationUpdates() {
2931 mApp.enforceCallingOrSelfPermission(
2932 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002935 /**
2936 * This method was removed due to potential issues caused by performing partial
2937 * updates of service state, and lack of a credible use case.
2938 *
2939 * This has the ability to break the telephony implementation by disabling notification of
2940 * changes in device connectivity. DO NOT USE THIS!
2941 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 @Override
2943 public void disableLocationUpdates() {
2944 mApp.enforceCallingOrSelfPermission(
2945 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947
2948 @Override
2949 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002950 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2951 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002952 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002953 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2954 throw new SecurityException(
2955 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2956 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002957
Jordan Liu1617b712019-07-10 15:06:26 -07002958 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002959 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2960 return null;
2961 }
Svetoslav64fad262015-04-14 14:35:21 -07002962
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002963 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002965 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002966 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967
Nathan Haroldf180aac2018-06-01 18:43:55 -07002968 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2969 for (CellInfo ci : info) {
2970 if (ci instanceof CellInfoGsm) {
2971 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2972 } else if (ci instanceof CellInfoWcdma) {
2973 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002976 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002979 private List<CellInfo> getCachedCellInfo() {
2980 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2981 for (Phone phone : PhoneFactory.getPhones()) {
2982 List<CellInfo> info = phone.getAllCellInfo();
2983 if (info != null) cellInfos.addAll(info);
2984 }
2985 return cellInfos;
2986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987
2988 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002989 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002991 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002992
2993 LocationAccessPolicy.LocationPermissionResult locationResult =
2994 LocationAccessPolicy.checkLocationPermission(mApp,
2995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setCallingPid(Binder.getCallingPid())
2999 .setCallingUid(Binder.getCallingUid())
3000 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3003 .build());
3004 switch (locationResult) {
3005 case DENIED_HARD:
3006 throw new SecurityException("Not allowed to access cell info");
3007 case DENIED_SOFT:
3008 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003009 }
3010
Nathan Haroldf096d982020-11-18 17:18:06 -08003011 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003012 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3013 return getCachedCellInfo();
3014 }
3015
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003016 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3021 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003022 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003023 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 if (info != null) cellInfos.addAll(info);
3025 }
3026 return cellInfos;
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030 }
3031
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003032 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003033 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3034 String callingFeatureId) {
3035 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3036 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003037 }
3038
3039 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3041 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 }
3045
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003046 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3047 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003049 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003050
3051 LocationAccessPolicy.LocationPermissionResult locationResult =
3052 LocationAccessPolicy.checkLocationPermission(mApp,
3053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3054 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003055 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003056 .setCallingPid(Binder.getCallingPid())
3057 .setCallingUid(Binder.getCallingUid())
3058 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3060 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003061 .build());
3062 switch (locationResult) {
3063 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003064 if (TelephonyPermissions
3065 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003066 // Safetynet logging for b/154934934
3067 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3068 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003069 throw new SecurityException("Not allowed to access cell info");
3070 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003071 if (TelephonyPermissions
3072 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003073 // Safetynet logging for b/154934934
3074 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3075 }
Nathan Harold5320c422019-05-09 10:26:08 -07003076 try {
3077 cb.onCellInfo(new ArrayList<CellInfo>());
3078 } catch (RemoteException re) {
3079 // Drop without consequences
3080 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003081 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003082 }
3083
Nathan Harolda939a962019-05-09 10:13:47 -07003084
3085 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003086 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3087
3088 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3089 }
3090
3091 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003093 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
3103
Shishir Agrawala9f32182016-04-12 12:00:16 -07003104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003105 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 Phone phone = PhoneFactory.getPhone(slotIndex);
3107 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 return null;
3109 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003110 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003111 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003112 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003113 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003114 return null;
3115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 return phone.getImei();
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003123 }
3124
3125 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003126 public String getTypeAllocationCodeForSlot(int slotIndex) {
3127 Phone phone = PhoneFactory.getPhone(slotIndex);
3128 String tac = null;
3129 if (phone != null) {
3130 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003131 try {
3132 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3133 } catch (IndexOutOfBoundsException e) {
3134 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3135 return null;
3136 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003137 }
3138 return tac;
3139 }
3140
3141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003143 Phone phone = PhoneFactory.getPhone(slotIndex);
3144 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003145 return null;
3146 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147
Jeff Davidson913390f2018-02-23 17:11:49 -08003148 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003149 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003150 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003151 return null;
3152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return phone.getMeid();
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Jack Yu2af8d712017-03-15 17:14:14 -07003160 }
3161
3162 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003163 public String getManufacturerCodeForSlot(int slotIndex) {
3164 Phone phone = PhoneFactory.getPhone(slotIndex);
3165 String manufacturerCode = null;
3166 if (phone != null) {
3167 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003168 try {
3169 manufacturerCode =
3170 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3171 } catch (IndexOutOfBoundsException e) {
3172 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3173 return null;
3174 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003175 }
3176 return manufacturerCode;
3177 }
3178
3179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3181 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003182 Phone phone = PhoneFactory.getPhone(slotIndex);
3183 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003184 return null;
3185 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003186 int subId = phone.getSubId();
3187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003188 mApp, subId, callingPackage, callingFeatureId,
3189 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003190 return null;
3191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 return phone.getDeviceSvn();
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003199 }
3200
fionaxu43304da2017-11-27 22:51:16 -08003201 @Override
3202 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 final Phone phone = getPhone(subId);
3206 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
fionaxu43304da2017-11-27 22:51:16 -08003210 }
3211
3212 @Override
3213 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = getPhone(subId);
3217 return phone == null ? null : phone.getCarrierName();
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
fionaxu43304da2017-11-27 22:51:16 -08003221 }
3222
calvinpanffe225e2018-11-01 19:43:06 +08003223 @Override
chen xu0026ca62019-03-06 15:28:50 -08003224 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = getPhone(subId);
3228 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003229 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
3233 }
3234
3235 @Override
chen xu0026ca62019-03-06 15:28:50 -08003236 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003240 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
chen xu651eec72018-11-11 19:03:44 -08003246 @Override
chen xu864e11c2018-12-06 22:10:03 -08003247 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3248 if (!isSubscriptionMccMnc) {
3249 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3250 }
chen xu651eec72018-11-11 19:03:44 -08003251 final Phone phone = PhoneFactory.getPhone(slotIndex);
3252 if (phone == null) {
3253 return TelephonyManager.UNKNOWN_CARRIER_ID;
3254 }
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 //
3264 // Internal helper methods.
3265 //
3266
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003267 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003268 * Make sure the caller is the calling package itself
3269 *
3270 * @throws SecurityException if the caller is not the calling package
3271 */
3272 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3273 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003274 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3275 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003276 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003277 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003278 } catch (PackageManager.NameNotFoundException e) {
3279 // packageUid is -1
3280 }
3281 if (packageUid != callingUid) {
3282 throw new SecurityException(message + ": Package " + callingPackage
3283 + " does not belong to " + callingUid);
3284 }
3285 }
3286
3287 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3289 *
3290 * @throws SecurityException if the caller does not have the required permission
3291 */
3292 private void enforceModifyPermission() {
3293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3294 }
3295
Shuo Qiancd19c462020-01-16 20:51:11 -08003296 /**
3297 * Make sure the caller is system.
3298 *
3299 * @throws SecurityException if the caller is not system.
3300 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003301 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003302 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3303 throw new SecurityException("Caller must be system");
3304 }
3305 }
3306
Shuo Qian3b6ee772019-11-13 17:43:31 -08003307 private void enforceActiveEmergencySessionPermission() {
3308 mApp.enforceCallingOrSelfPermission(
3309 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3310 }
3311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 /**
3313 * Make sure the caller has the CALL_PHONE permission.
3314 *
3315 * @throws SecurityException if the caller does not have the required permission
3316 */
3317 private void enforceCallPermission() {
3318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3319 }
3320
paulhu5a773602019-08-23 19:17:33 +08003321 private void enforceSettingsPermission() {
3322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003323 }
3324
Michele Berionne5e411512020-11-13 02:36:59 +00003325 private void enforceRebootPermission() {
3326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3327 }
3328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003329 private String createTelUrl(String number) {
3330 if (TextUtils.isEmpty(number)) {
3331 return null;
3332 }
3333
Jake Hambye994d462014-02-03 13:10:13 -08003334 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 }
3336
Ihab Awadf9e92732013-12-05 18:02:52 -08003337 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003338 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3339 }
3340
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003341 private static void logv(String msg) {
3342 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3343 }
3344
Ihab Awadf9e92732013-12-05 18:02:52 -08003345 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003346 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3347 }
3348
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003351 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003352 }
3353
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003355 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 final Phone phone = PhoneFactory.getPhone(slotIndex);
3359 if (phone == null) {
3360 return PhoneConstants.PHONE_TYPE_NONE;
3361 } else {
3362 return phone.getPhoneType();
3363 }
3364 } finally {
3365 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003367 }
3368
3369 /**
3370 * Returns the CDMA ERI icon index to display
3371 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003373 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3374 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3375 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003376 }
3377
Sanket Padawe356d7632015-06-22 14:03:32 -07003378 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003379 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3380 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003382 mApp, subId, callingPackage, callingFeatureId,
3383 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003384 return -1;
3385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 final Phone phone = getPhone(subId);
3390 if (phone != null) {
3391 return phone.getCdmaEriIconIndex();
3392 } else {
3393 return -1;
3394 }
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398 }
3399
3400 /**
3401 * Returns the CDMA ERI icon mode,
3402 * 0 - ON
3403 * 1 - FLASHING
3404 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003405 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003406 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3407 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3408 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003409 }
3410
Sanket Padawe356d7632015-06-22 14:03:32 -07003411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003412 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3413 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003415 mApp, subId, callingPackage, callingFeatureId,
3416 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003417 return -1;
3418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 final Phone phone = getPhone(subId);
3423 if (phone != null) {
3424 return phone.getCdmaEriIconMode();
3425 } else {
3426 return -1;
3427 }
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003431 }
3432
3433 /**
3434 * Returns the CDMA ERI text,
3435 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003437 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3438 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3439 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003440 }
3441
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003443 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3444 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003446 mApp, subId, callingPackage, callingFeatureId,
3447 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003448 return null;
3449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 final Phone phone = getPhone(subId);
3454 if (phone != null) {
3455 return phone.getCdmaEriText();
3456 } else {
3457 return null;
3458 }
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 }
3463
3464 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003465 * Returns the CDMA MDN.
3466 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003468 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3470 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471
3472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003475 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476 return phone.getLine1Number();
3477 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 return null;
3480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003483 }
3484 }
3485
3486 /**
3487 * Returns the CDMA MIN.
3488 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003490 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3492 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 final Phone phone = getPhone(subId);
3497 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3498 return phone.getCdmaMin();
3499 } else {
3500 return null;
3501 }
3502 } finally {
3503 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003504 }
3505 }
3506
Hall Liud892bec2018-11-30 14:51:45 -08003507 @Override
3508 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3509 INumberVerificationCallback callback, String callingPackage) {
3510 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3511 != PERMISSION_GRANTED) {
3512 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3513 }
3514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3515
3516 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3517 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003518 throw new SecurityException("Calling package must be configured in the device config: "
3519 + "calling package: " + callingPackage
3520 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003521 }
3522
3523 if (range == null) {
3524 throw new NullPointerException("Range must be non-null");
3525 }
3526
3527 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003528 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003529
3530 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3531 }
3532
Junda Liuca05d5d2014-08-14 22:36:34 -07003533 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003534 * Returns true if CDMA provisioning needs to run.
3535 */
3536 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 final long identity = Binder.clearCallingIdentity();
3538 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003539 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003546 * Sets the voice mail number of a given subId.
3547 */
3548 @Override
3549 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003550 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3551 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3556 new Pair<String, String>(alphaTag, number), new Integer(subId));
3557 return success;
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003561 }
3562
Ta-wei Yen87c49842016-05-13 21:19:52 -07003563 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003564 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003566 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3567 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003568 if (!TextUtils.equals(callingPackage, systemDialer)) {
3569 throw new SecurityException("caller must be system dialer");
3570 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3575 if (phoneAccountHandle == null) {
3576 return null;
3577 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003578 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 } finally {
3580 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003581 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003582 }
3583
3584 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003585 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3586 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 mApp, subId, callingPackage, callingFeatureId,
3590 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003591 return null;
3592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003594 final long identity = Binder.clearCallingIdentity();
3595 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003600 }
3601
3602 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003603 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3604 VisualVoicemailSmsFilterSettings settings) {
3605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003614 }
3615
3616 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003617 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003627 }
3628
3629 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003630 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3631 String callingPackage, int subId) {
3632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003641 }
3642
3643 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003644 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003654 }
3655
3656 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003657 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3658 String callingAttributionTag, int subId, String number, int port, String text,
3659 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003661 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003662 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003663 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003664 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3665 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003666 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003667
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003668 /**
fionaxu0152e512016-11-14 13:36:14 -08003669 * Sets the voice activation state of a given subId.
3670 */
3671 @Override
3672 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3674 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = getPhone(subId);
3679 if (phone != null) {
3680 phone.setVoiceActivationState(activationState);
3681 } else {
3682 loge("setVoiceActivationState fails with invalid subId: " + subId);
3683 }
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003686 }
3687 }
3688
3689 /**
3690 * Sets the data activation state of a given subId.
3691 */
3692 @Override
3693 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3695 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 final Phone phone = getPhone(subId);
3700 if (phone != null) {
3701 phone.setDataActivationState(activationState);
3702 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003703 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 }
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003707 }
3708 }
3709
3710 /**
3711 * Returns the voice activation state of a given subId.
3712 */
3713 @Override
3714 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716
fionaxu0152e512016-11-14 13:36:14 -08003717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 if (phone != null) {
3721 return phone.getVoiceActivationState();
3722 } else {
3723 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3724 }
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003727 }
3728 }
3729
3730 /**
3731 * Returns the data activation state of a given subId.
3732 */
3733 @Override
3734 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
fionaxu0152e512016-11-14 13:36:14 -08003737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 if (phone != null) {
3741 return phone.getDataActivationState();
3742 } else {
3743 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3744 }
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003747 }
3748 }
3749
3750 /**
Wink Saville36469e72014-06-11 15:17:00 -07003751 * Returns the unread count of voicemails for a subId
3752 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003754 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3755 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 mApp, subId, callingPackage, callingFeatureId,
3758 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003759 return 0;
3760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003761 final long identity = Binder.clearCallingIdentity();
3762 try {
3763 final Phone phone = getPhone(subId);
3764 if (phone != null) {
3765 return phone.getVoiceMessageCount();
3766 } else {
3767 return 0;
3768 }
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003772 }
3773
3774 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003775 * returns true, if the device is in a state where both voice and data
3776 * are supported simultaneously. This can change based on location or network condition.
3777 */
3778 @Override
3779 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 final Phone phone = getPhone(subId);
3783 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
3786 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003787 }
3788
3789 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003790 * Send the dialer code if called from the current default dialer or the caller has
3791 * carrier privilege.
3792 * @param inputCode The dialer code to send
3793 */
3794 @Override
3795 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003798 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3799 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003800 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003801 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003802 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003807 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 } finally {
3809 Binder.restoreCallingIdentity(identity);
3810 }
fionaxu235cc5e2017-03-06 22:25:57 -08003811 }
3812
Pengquan Menga1bb6272018-09-06 09:59:22 -07003813 @Override
3814 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003815 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003816 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003817 mApp, subId, "getNetworkSelectionMode");
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 if (!isActiveSubscription(subId)) {
3821 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3822 }
3823 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003826 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003827 }
3828
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003830 public boolean isInEmergencySmsMode() {
3831 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 for (Phone phone : PhoneFactory.getPhones()) {
3835 if (phone.isInEmergencySmsMode()) {
3836 return true;
3837 }
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
3841 }
3842 return false;
3843 }
3844
shilu366312e2019-12-17 09:28:10 -08003845 /**
3846 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3847 * @param subId The subscription to use to check the configuration.
3848 * @param c The callback that will be used to send the result.
3849 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003850 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003851 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3852 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003853 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003854 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003855
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003856 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3857 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3858 "IMS not available on device.");
3859 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 final long token = Binder.clearCallingIdentity();
3861 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003862 int slotId = getSlotIndexOrException(subId);
3863 verifyImsMmTelConfiguredOrThrow(slotId);
3864 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003865 } catch (ImsException e) {
3866 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 } finally {
3868 Binder.restoreCallingIdentity(token);
3869 }
3870 }
3871
shilu366312e2019-12-17 09:28:10 -08003872 /**
3873 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3874 * @param subId The subscription to use to check the configuration.
3875 * @param c The callback that will be used to send the result.
3876 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003878 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003879 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003880 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3883 }
Meng Wangafbc5852019-09-19 17:37:13 -07003884 final long token = Binder.clearCallingIdentity();
3885 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003886 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3887 .removeRegistrationCallbackForSubscription(c, subId);
3888 } catch (ImsException e) {
3889 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3890 + "is inactive, ignoring unregister.");
3891 // If the subscription is no longer active, just return, since the callback
3892 // will already have been removed internally.
3893 } finally {
3894 Binder.restoreCallingIdentity(token);
3895 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 }
3897
Brad Ebingera34a6c22019-10-22 17:36:18 -07003898 /**
3899 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3900 */
3901 @Override
3902 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3903 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3904 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3905 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3906 "IMS not available on device.");
3907 }
3908 final long token = Binder.clearCallingIdentity();
3909 try {
3910 Phone phone = getPhone(subId);
3911 if (phone == null) {
3912 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3913 + subId + "'");
3914 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3915 }
3916 phone.getImsRegistrationState(regState -> {
3917 try {
3918 consumer.accept((regState == null)
3919 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3920 } catch (RemoteException e) {
3921 // Ignore if the remote process is no longer available to call back.
3922 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3923 }
3924 });
3925 } finally {
3926 Binder.restoreCallingIdentity(token);
3927 }
3928 }
3929
3930 /**
3931 * Get the transport type for the IMS service registration state.
3932 */
3933 @Override
3934 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003935 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003936 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003937 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3939 "IMS not available on device.");
3940 }
3941 final long token = Binder.clearCallingIdentity();
3942 try {
3943 Phone phone = getPhone(subId);
3944 if (phone == null) {
3945 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3946 + subId + "'");
3947 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3948 }
3949 phone.getImsRegistrationTech(regTech -> {
3950 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3951 int regTechConverted = (regTech == null)
3952 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3953 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3954 regTechConverted);
3955 try {
3956 consumer.accept(regTechConverted);
3957 } catch (RemoteException e) {
3958 // Ignore if the remote process is no longer available to call back.
3959 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3960 }
3961 });
3962 } finally {
3963 Binder.restoreCallingIdentity(token);
3964 }
3965 }
3966
shilu366312e2019-12-17 09:28:10 -08003967 /**
3968 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3969 * @param subId The subscription to use to check the configuration.
3970 * @param c The callback that will be used to send the result.
3971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003973 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3974 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003975 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003976 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003977 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3978 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3979 "IMS not available on device.");
3980 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 final long token = Binder.clearCallingIdentity();
3982 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003983 int slotId = getSlotIndexOrException(subId);
3984 verifyImsMmTelConfiguredOrThrow(slotId);
3985 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003986 } catch (ImsException e) {
3987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 } finally {
3989 Binder.restoreCallingIdentity(token);
3990 }
3991 }
3992
shilu366312e2019-12-17 09:28:10 -08003993 /**
3994 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3995 * @param subId The subscription to use to check the configuration.
3996 * @param c The callback that will be used to send the result.
3997 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003999 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004000 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004001 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004002 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4003 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4004 }
Meng Wangafbc5852019-09-19 17:37:13 -07004005
4006 final long token = Binder.clearCallingIdentity();
4007 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004008 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004009 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004010 } catch (ImsException e) {
4011 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4012 + "is inactive, ignoring unregister.");
4013 // If the subscription is no longer active, just return, since the callback
4014 // will already have been removed internally.
4015 } finally {
4016 Binder.restoreCallingIdentity(token);
4017 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 }
4019
4020 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004021 public boolean isCapable(int subId, int capability, int regTech) {
4022 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 final long token = Binder.clearCallingIdentity();
4024 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004025 int slotId = getSlotIndexOrException(subId);
4026 verifyImsMmTelConfiguredOrThrow(slotId);
4027 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004028 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4030 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004031 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004032 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4033 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 } finally {
4035 Binder.restoreCallingIdentity(token);
4036 }
4037 }
4038
4039 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004040 public boolean isAvailable(int subId, int capability, int regTech) {
4041 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 final long token = Binder.clearCallingIdentity();
4043 try {
4044 Phone phone = getPhone(subId);
4045 if (phone == null) return false;
4046 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004047 } catch (com.android.ims.ImsException e) {
4048 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4049 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 } finally {
4051 Binder.restoreCallingIdentity(token);
4052 }
4053 }
4054
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004055 /**
4056 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4057 * subscription.
4058 * @param subId The subscription to use to check the configuration.
4059 * @param callback The callback that will be used to send the result.
4060 * @param capability The MmTelFeature capability that will be used to send the result.
4061 * @param transportType The transport type of the MmTelFeature capability.
4062 */
4063 @Override
4064 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4065 int transportType) {
4066 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4069 "IMS not available on device.");
4070 }
4071 final long token = Binder.clearCallingIdentity();
4072 try {
4073 int slotId = getSlotIndex(subId);
4074 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4075 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4076 + subId + "'");
4077 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4078 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004079 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004080 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4081 transportType, aBoolean -> {
4082 try {
4083 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4084 } catch (RemoteException e) {
4085 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4086 + "running. Ignore");
4087 }
4088 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004091 } finally {
4092 Binder.restoreCallingIdentity(token);
4093 }
4094 }
4095
shilu366312e2019-12-17 09:28:10 -08004096 /**
4097 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4098 * @param subId The subscription to use to check the configuration.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
4101 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004102 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004103 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004104
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 final long token = Binder.clearCallingIdentity();
4106 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004107 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004108 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004109 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004110 } catch (ImsException e) {
4111 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 } finally {
4113 Binder.restoreCallingIdentity(token);
4114 }
4115 }
4116
4117 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004118 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004120 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 final long identity = Binder.clearCallingIdentity();
4122 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004123 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004124 // This setting doesn't require an active ImsService connection, so do not verify. The
4125 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004126 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004127 } catch (ImsException e) {
4128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
shilu366312e2019-12-17 09:28:10 -08004134 /**
4135 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4136 * @param subId The subscription to use to check the configuration.
4137 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004139 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004140 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004141 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 final long identity = Binder.clearCallingIdentity();
4143 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004144 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004145 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004146 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004147 } catch (ImsException e) {
4148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
4152 }
4153
4154 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004155 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004157 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 final long identity = Binder.clearCallingIdentity();
4159 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004160 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004161 // This setting doesn't require an active ImsService connection, so do not verify. The
4162 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004163 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (ImsException e) {
4165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
shilu366312e2019-12-17 09:28:10 -08004171 /**
4172 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4173 * @param subId The subscription to use to check the configuration.
4174 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 @Override
4176 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004178 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 final long identity = Binder.clearCallingIdentity();
4180 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004182 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004183 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
4185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
4191 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004192 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004194 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long identity = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004197 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004198 // This setting doesn't require an active ImsService connection, so do not verify. The
4199 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004200 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
shilu366312e2019-12-17 09:28:10 -08004208 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004209 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4210 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4211 * @param subId The subscription to use to check the configuration.
4212 */
4213 @Override
4214 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004215 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004216 mApp, subId, "isCrossSimCallingEnabledByUser");
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004220 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
4224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
4229 /**
4230 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4231 * Requires MODIFY_PHONE_STATE permission.
4232 * @param subId The subscription to use to check the configuration.
4233 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4234 * false otherwise
4235 */
4236 @Override
4237 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4239 "setCrossSimCallingEnabled");
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004242 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004243 // This setting doesn't require an active ImsService connection, so do not verify. The
4244 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004245 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004246 } catch (ImsException e) {
4247 throw new ServiceSpecificException(e.getCode());
4248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
4251 }
4252
4253 /**
shilu366312e2019-12-17 09:28:10 -08004254 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4255 * @param subId The subscription to use to check the configuration.
4256 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004258
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004260 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004261 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004262 final long identity = Binder.clearCallingIdentity();
4263 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004264 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004265 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004267 } catch (ImsException e) {
4268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
4272 }
4273
4274 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004275 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004277 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 final long identity = Binder.clearCallingIdentity();
4279 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004280 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004281 // This setting doesn't require an active ImsService connection, so do not verify. The
4282 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 } catch (ImsException e) {
4285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
4291 @Override
4292 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4294 "setVoWiFiNonPersistent");
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
shilu366312e2019-12-17 09:28:10 -08004307 /**
4308 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4309 * @param subId The subscription to use to check the configuration.
4310 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 @Override
4312 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004313 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004314 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 final long identity = Binder.clearCallingIdentity();
4316 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004318 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
4325 }
4326
4327 @Override
4328 public void setVoWiFiModeSetting(int subId, int mode) {
4329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4330 "setVoWiFiModeSetting");
4331 final long identity = Binder.clearCallingIdentity();
4332 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004333 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004334 // This setting doesn't require an active ImsService connection, so do not verify. The
4335 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004337 } catch (ImsException e) {
4338 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
4342 }
4343
4344 @Override
4345 public int getVoWiFiRoamingModeSetting(int subId) {
4346 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4347 final long identity = Binder.clearCallingIdentity();
4348 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004350 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004352 } catch (ImsException e) {
4353 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
4357 }
4358
4359 @Override
4360 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4362 "setVoWiFiRoamingModeSetting");
4363 final long identity = Binder.clearCallingIdentity();
4364 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004365 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004366 // This setting doesn't require an active ImsService connection, so do not verify. The
4367 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004368 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004369 } catch (ImsException e) {
4370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374 }
4375
4376 @Override
4377 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4379 "setRttCapabilityEnabled");
4380 final long identity = Binder.clearCallingIdentity();
4381 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004383 // This setting doesn't require an active ImsService connection, so do not verify. The
4384 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004386 } catch (ImsException e) {
4387 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
shilu366312e2019-12-17 09:28:10 -08004393 /**
4394 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4395 * @param subId The subscription to use to check the configuration.
4396 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 @Override
4398 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004399 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004400 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 final long identity = Binder.clearCallingIdentity();
4402 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004403 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004404 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004406 } catch (ImsException e) {
4407 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004408 } finally {
4409 Binder.restoreCallingIdentity(identity);
4410 }
4411 }
4412
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004413 @Override
4414 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4415 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4416 final long identity = Binder.clearCallingIdentity();
4417 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004418 if (!isImsAvailableOnDevice()) {
4419 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4420 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004421 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 int slotId = getSlotIndexOrException(subId);
4423 verifyImsMmTelConfiguredOrThrow(slotId);
4424 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004425 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
4431 }
4432
4433 @Override
4434 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4435 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4436 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004437 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4438 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4439 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004440 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004442 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004443 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004444 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4445 + "is inactive, ignoring unregister.");
4446 // If the subscription is no longer active, just return, since the callback will already
4447 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
allenwtsu99c623b2020-01-03 18:24:23 +08004453
4454 private void checkModifyPhoneStatePermission(int subId, String message) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4456 message);
4457 }
4458
4459 private boolean isImsProvisioningRequired(int subId, int capability,
4460 boolean isMmtelCapability) {
4461 Phone phone = getPhone(subId);
4462 if (phone == null) {
4463 loge("phone instance null for subid " + subId);
4464 return false;
4465 }
4466 if (isMmtelCapability) {
4467 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4468 return false;
4469 }
4470 } else {
4471 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4472 return false;
4473 }
4474 }
4475 return true;
4476 }
4477
4478 @Override
4479 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4480 boolean isProvisioned) {
4481 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4482
4483 final long identity = Binder.clearCallingIdentity();
4484 try {
4485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4486 if (!isImsProvisioningRequired(subId, capability, false)) {
4487 return;
4488 }
4489
4490 // this capability requires provisioning, route to the correct API.
4491 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4492 switch (capability) {
4493 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4494 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4495 ims.setEabProvisioned(isProvisioned);
4496 break;
4497 default: {
4498 throw new IllegalArgumentException("Tried to set provisioning for "
4499 + "rcs capability '" + capability + "', which does not require "
4500 + "provisioning.");
4501 }
4502 }
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506
4507 }
4508
4509
4510 @Override
4511 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4512 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4516 if (!isImsProvisioningRequired(subId, capability, false)) {
4517 return true;
4518 }
4519
4520 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4521 switch (capability) {
4522 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4523 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4524 return ims.isEabProvisionedOnDevice();
4525
4526 default: {
4527 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4528 + "capability '" + capability + "', which does not require "
4529 + "provisioning.");
4530 }
4531 }
4532
4533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004538 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004539 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4540 boolean isProvisioned) {
4541 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004542 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4543 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4544 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004545 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4546 }
allenwtsu99c623b2020-01-03 18:24:23 +08004547 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004548 final long identity = Binder.clearCallingIdentity();
4549 try {
4550 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004551 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004552 return;
4553 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004554 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4555 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4556 loge("setImsProvisioningStatusForCapability: called for technology that does "
4557 + "not support provisioning - " + tech);
4558 return;
4559 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004560
4561 // this capability requires provisioning, route to the correct API.
4562 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4563 switch (capability) {
4564 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4565 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4566 ims.setVolteProvisioned(isProvisioned);
4567 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4568 ims.setWfcProvisioned(isProvisioned);
4569 }
4570 break;
4571 }
4572 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4573 // There is currently no difference in VT provisioning type.
4574 ims.setVtProvisioned(isProvisioned);
4575 break;
4576 }
4577 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4578 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4579 // change the capability of the feature instead if needed.
4580 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4581 == isProvisioned) {
4582 // No change in provisioning.
4583 return;
4584 }
4585 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4586 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004587 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004588 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004589 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4590 + ", Exception" + e.getMessage());
4591 }
4592 break;
4593 }
4594 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004595 throw new IllegalArgumentException("Tried to set provisioning for "
4596 + "MmTel capability '" + capability + "', which does not require "
4597 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 }
4599 }
4600
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
4603 }
4604 }
4605
4606 @Override
4607 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4608 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004609 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4610 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4611 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004612 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4613 }
4614 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004618 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 return true;
4620 }
4621
Brad Ebinger0d79c572021-04-17 15:20:49 -07004622 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4623 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4624 loge("getImsProvisioningStatusForCapability: called for technology that does "
4625 + "not support provisioning - " + tech);
4626 return true;
4627 }
4628
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004629 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4630 switch (capability) {
4631 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4632 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4633 return ims.isVolteProvisionedOnDevice();
4634 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4635 return ims.isWfcProvisionedOnDevice();
4636 }
4637 // This should never happen, since we are checking tech above to make sure it
4638 // is either LTE or IWLAN.
4639 throw new IllegalArgumentException("Invalid radio technology for voice "
4640 + "capability.");
4641 }
4642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4643 // There is currently no difference in VT provisioning type.
4644 return ims.isVtProvisionedOnDevice();
4645 }
4646 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4647 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4648 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4649 }
4650 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004651 throw new IllegalArgumentException(
4652 "Tried to get provisioning for MmTel capability '" + capability
4653 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 }
4655 }
4656
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
4659 }
4660 }
4661
4662 @Override
4663 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4664 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4665 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4666 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4667 }
4668 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4669 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4670 return (provisionedBits & capability) > 0;
4671 }
4672
4673 @Override
4674 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4675 boolean isProvisioned) {
4676 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4677 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4678 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4679 }
4680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4681 "setProvisioningStatusForCapability");
4682 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4683 // If the current provisioning status for capability already matches isProvisioned,
4684 // do nothing.
4685 if (((provisionedBits & capability) > 0) == isProvisioned) {
4686 return;
4687 }
4688 if (isProvisioned) {
4689 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4690 } else {
4691 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4692 }
4693 }
4694
4695 /**
4696 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4697 * technology. The bitfield should mirror the bitfield defined by
4698 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4699 */
4700 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4701 String key = getMmTelProvisioningKey(subId, tech);
4702 // Default is no capabilities are provisioned.
4703 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4704 }
4705
4706 /**
4707 * Sets the MmTel capability provisioning bitfield (defined by
4708 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4709 * technology specified.
4710 *
4711 * Note: This is a synchronous command and should not be called on UI thread.
4712 */
4713 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4714 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4715 String key = getMmTelProvisioningKey(subId, tech);
4716 editor.putInt(key, newField);
4717 editor.commit();
4718 }
4719
4720 private static String getMmTelProvisioningKey(int subId, int tech) {
4721 // resulting key is provision_ims_mmtel_{subId}_{tech}
4722 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4723 }
4724
4725 /**
4726 * Query CarrierConfig to see if the specified capability requires provisioning for the
4727 * carrier associated with the subscription id.
4728 */
4729 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4730 int capability) {
4731 CarrierConfigManager configManager = new CarrierConfigManager(context);
4732 PersistableBundle c = configManager.getConfigForSubId(subId);
4733 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004734 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4736 false);
4737 boolean requireVoiceVtProvisioning = c.getBoolean(
4738 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4739
4740 // First check to make sure that the capability requires provisioning.
4741 switch (capability) {
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4743 // intentional fallthrough
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4745 if (requireVoiceVtProvisioning) {
4746 // Voice and Video requires provisioning
4747 return true;
4748 }
4749 break;
4750 }
4751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4752 if (requireUtProvisioning) {
4753 // UT requires provisioning
4754 return true;
4755 }
4756 break;
4757 }
4758 }
4759 return false;
4760 }
4761
allenwtsu99c623b2020-01-03 18:24:23 +08004762 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4763 int capability) {
4764 CarrierConfigManager configManager = new CarrierConfigManager(context);
4765 PersistableBundle c = configManager.getConfigForSubId(subId);
4766
4767 boolean requireRcsProvisioning = c.getBoolean(
4768 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4769
4770 // First check to make sure that the capability requires provisioning.
4771 switch (capability) {
4772 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4773 // intentional fallthrough
4774 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4775 if (requireRcsProvisioning) {
4776 // OPTION or PRESENCE requires provisioning
4777 return true;
4778 }
4779 break;
4780 }
4781 }
4782 return false;
4783 }
4784
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004785 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004787 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4788 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4789 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004790 enforceReadPrivilegedPermission("getImsProvisioningInt");
4791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004794 int slotId = getSlotIndex(subId);
4795 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4796 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4797 + subId + "' for key:" + key);
4798 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4799 }
calvinpanb5a34062021-02-08 19:59:36 +08004800 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004801 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4803 + subId + "' for key:" + key);
4804 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
4808 }
4809
4810 @Override
4811 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4813 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4814 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 enforceReadPrivilegedPermission("getImsProvisioningString");
4816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004819 int slotId = getSlotIndex(subId);
4820 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4821 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4822 + subId + "' for key:" + key);
4823 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4824 }
calvinpanb5a34062021-02-08 19:59:36 +08004825 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004826 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004827 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4828 + subId + "' for key:" + key);
4829 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
4833 }
4834
4835 @Override
4836 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4838 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4839 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4841 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 int slotId = getSlotIndex(subId);
4846 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4847 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4848 + subId + "' for key:" + key);
4849 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4850 }
calvinpanb5a34062021-02-08 19:59:36 +08004851 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4852 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004854 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
4859 }
4860
4861 @Override
4862 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4864 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4865 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4867 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871 int slotId = getSlotIndex(subId);
4872 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4873 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4874 + subId + "' for key:" + key);
4875 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4876 }
calvinpanb5a34062021-02-08 19:59:36 +08004877 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4878 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004880 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
Brad Ebinger919631e2021-06-02 17:46:35 -07004887 /**
4888 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4889 * for the given slot ID or no ImsResolver instance has been created.
4890 * @param slotId The slot ID that the IMS service is created for.
4891 * @throws ImsException If there is no ImsService configured for this slot.
4892 */
4893 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4894 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4895 ImsFeature.FEATURE_MMTEL)) {
4896 throw new ImsException("This subscription does not support MMTEL over IMS",
4897 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4898 }
4899 }
4900
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004902 int slotId = SubscriptionManager.getSlotIndex(subId);
4903 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004904 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4905 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004906 }
4907 return slotId;
4908 }
4909
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004910 private int getSlotIndex(int subId) {
4911 int slotId = SubscriptionManager.getSlotIndex(subId);
4912 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4913 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4914 }
4915 return slotId;
4916 }
4917
Wink Saville36469e72014-06-11 15:17:00 -07004918 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004919 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004920 */
4921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4923 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004924 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004925 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004927 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004928 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004929 mApp, subId, callingPackage, callingFeatureId,
4930 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004931 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4932 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 final long identity = Binder.clearCallingIdentity();
4935 try {
4936 final Phone phone = getPhone(subId);
4937 if (phone != null) {
4938 return phone.getServiceState().getDataNetworkType();
4939 } else {
4940 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4941 }
4942 } finally {
4943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004945 }
4946
4947 /**
4948 * Returns the data network type
4949 */
4950 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004951 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004952 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4953 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004954 }
4955
4956 /**
4957 * Returns the data network type for a subId
4958 */
4959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004960 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4961 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004963 mApp, subId, callingPackage, callingFeatureId,
4964 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004965 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4966 }
4967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 final Phone phone = getPhone(subId);
4971 if (phone != null) {
4972 return phone.getServiceState().getDataNetworkType();
4973 } else {
4974 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4975 }
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004978 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004979 }
4980
4981 /**
Wink Saville36469e72014-06-11 15:17:00 -07004982 * Returns the Voice network type for a subId
4983 */
4984 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004985 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4986 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004988 mApp, subId, callingPackage, callingFeatureId,
4989 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004990 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4991 }
4992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 final long identity = Binder.clearCallingIdentity();
4994 try {
4995 final Phone phone = getPhone(subId);
4996 if (phone != null) {
4997 return phone.getServiceState().getVoiceNetworkType();
4998 } else {
4999 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5000 }
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005004 }
5005
5006 /**
5007 * @return true if a ICC card is present
5008 */
5009 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005010 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005011 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5012 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005013 }
5014
5015 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005016 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005017 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005018 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005019 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 final Phone phone = PhoneFactory.getPhone(slotIndex);
5023 if (phone != null) {
5024 return phone.getIccCard().hasIccCard();
5025 } else {
5026 return false;
5027 }
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005031 }
5032
5033 /**
5034 * Return if the current radio is LTE on CDMA. This
5035 * is a tri-state return value as for a period of time
5036 * the mode may be unknown.
5037 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005038 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005039 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005040 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005041 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005043 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5044 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5045 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005046 }
5047
Sanket Padawe356d7632015-06-22 14:03:32 -07005048 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005049 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5050 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005051 try {
5052 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5053 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005054 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5055 }
5056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 final Phone phone = getPhone(subId);
5060 if (phone == null) {
5061 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5062 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005063 return TelephonyProperties.lte_on_cdma_device()
5064 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 }
5066 } finally {
5067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005068 }
Wink Saville36469e72014-06-11 15:17:00 -07005069 }
5070
Wink Saville36469e72014-06-11 15:17:00 -07005071 /**
5072 * {@hide}
5073 * Returns Default subId, 0 in the case of single standby.
5074 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005075 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005076 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005077 }
5078
Shishir Agrawala9f32182016-04-12 12:00:16 -07005079 private int getSlotForDefaultSubscription() {
5080 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5081 }
5082
Wink Savilleb564aae2014-10-23 10:18:09 -07005083 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005084 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005085 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005086
Pengquan Menge92a50d2018-09-21 15:54:48 -07005087 private boolean isActiveSubscription(int subId) {
5088 return mSubscriptionController.isActiveSubId(subId);
5089 }
5090
Ihab Awadf2177b72013-11-25 13:33:23 -08005091 /**
5092 * @see android.telephony.TelephonyManager.WifiCallingChoices
5093 */
5094 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005097 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5099 getWhenToMakeWifiCallsDefaultPreference());
5100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005103 }
5104
5105 /**
5106 * @see android.telephony.TelephonyManager.WifiCallingChoices
5107 */
5108 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005112 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005117 }
5118
Sailesh Nepald1e68152013-12-12 19:08:02 -08005119 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005120 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005121 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005122 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005123
Jordan Liu4c733742019-02-28 12:03:40 -08005124 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5125 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5126 if (phoneId == -1) {
5127 throw new IllegalArgumentException("Given slot index: " + slotIndex
5128 + " does not correspond to an active phone");
5129 }
5130 return PhoneFactory.getPhone(phoneId);
5131 }
5132
Shishir Agrawal566b7612013-10-28 14:41:00 -07005133 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005134 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5135 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5137 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005139 if (DBG) {
5140 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5141 }
5142 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5143 p2);
5144 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005145
Jordan Liu4c733742019-02-28 12:03:40 -08005146
5147 @Override
5148 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5149 int slotIndex, String callingPackage, String aid, int p2) {
5150 enforceModifyPermission();
5151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5152 if (DBG) {
5153 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5154 }
5155 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5156 callingPackage, aid, p2);
5157 }
5158
5159 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5160 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 final long identity = Binder.clearCallingIdentity();
5162 try {
5163 if (TextUtils.equals(ISDR_AID, aid)) {
5164 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005165 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5166 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 if (bestComponent == null
5168 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5169 loge("The calling package is not allowed to access ISD-R.");
5170 throw new SecurityException(
5171 "The calling package is not allowed to access ISD-R.");
5172 }
Derek Tan740e1672017-06-27 14:56:27 -07005173 }
Derek Tan740e1672017-06-27 14:56:27 -07005174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005175 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005176 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5177 null /* workSource */);
5178 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 return response;
5180 } finally {
5181 Binder.restoreCallingIdentity(identity);
5182 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005183 }
5184
5185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005186 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5188 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005189 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5190 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192
Jordan Liu4c733742019-02-28 12:03:40 -08005193 @Override
5194 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5195 enforceModifyPermission();
5196 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5197 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5198 channel);
5199 }
5200
5201 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 if (channel < 0) {
5205 return false;
5206 }
Jordan Liu4c733742019-02-28 12:03:40 -08005207 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5208 null /* workSource */);
5209 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 return success;
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005213 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005214 }
5215
5216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005217 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005218 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005221 if (DBG) {
5222 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5223 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5224 + p3 + " data=" + data);
5225 }
5226 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5227 command, p1, p2, p3, data);
5228 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005229
Jordan Liu4c733742019-02-28 12:03:40 -08005230 @Override
5231 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5232 int command, int p1, int p2, int p3, String data) {
5233 enforceModifyPermission();
5234 if (DBG) {
5235 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5236 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5237 + p3 + " data=" + data);
5238 }
5239 return iccTransmitApduLogicalChannelWithPermission(
5240 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5241 data);
5242 }
5243
5244 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5245 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005248 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 return "";
5250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005253 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5254 null /* workSource */);
5255 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 // Append the returned status code to the end of the response payload.
5258 String s = Integer.toHexString(
5259 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5260 if (response.payload != null) {
5261 s = IccUtils.bytesToHexString(response.payload) + s;
5262 }
5263 return s;
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005266 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005267 }
Jake Hambye994d462014-02-03 13:10:13 -08005268
Evan Charltonc66da362014-05-16 14:06:40 -07005269 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005270 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5271 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5273 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005275 if (DBG) {
5276 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5277 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5278 }
5279 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5280 cla, command, p1, p2, p3, data);
5281 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005282
Jordan Liu4c733742019-02-28 12:03:40 -08005283 @Override
5284 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5285 int command, int p1, int p2, int p3, String data) {
5286 enforceModifyPermission();
5287 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5288 if (DBG) {
5289 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5290 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5291 + " data=" + data);
5292 }
5293
5294 return iccTransmitApduBasicChannelWithPermission(
5295 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5296 p2, p3, data);
5297 }
5298
5299 // open APDU basic channel assuming the caller has sufficient permissions
5300 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5301 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5305 && TextUtils.equals(ISDR_AID, data)) {
5306 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005307 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5308 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 if (bestComponent == null
5310 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5311 loge("The calling package is not allowed to select ISD-R.");
5312 throw new SecurityException(
5313 "The calling package is not allowed to select ISD-R.");
5314 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005315 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005318 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5319 null /* workSource */);
5320 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 // Append the returned status code to the end of the response payload.
5323 String s = Integer.toHexString(
5324 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5325 if (response.payload != null) {
5326 s = IccUtils.bytesToHexString(response.payload) + s;
5327 }
5328 return s;
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005331 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005332 }
5333
5334 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005335 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005336 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5338 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
5342 if (DBG) {
5343 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5344 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5345 }
5346
5347 IccIoResult response =
5348 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5349 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5350 subId);
5351
5352 if (DBG) {
5353 log("Exchange SIM_IO [R]" + response);
5354 }
5355
5356 byte[] result = null;
5357 int length = 2;
5358 if (response.payload != null) {
5359 length = 2 + response.payload.length;
5360 result = new byte[length];
5361 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5362 } else {
5363 result = new byte[length];
5364 }
5365
5366 result[length - 1] = (byte) response.sw2;
5367 result[length - 2] = (byte) response.sw1;
5368 return result;
5369 } finally {
5370 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005371 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005372 }
5373
Nathan Haroldb3014052017-01-25 15:57:32 -08005374 /**
5375 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5376 * on a particular subscription
5377 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005378 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5379 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005381 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005382 return null;
5383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384
5385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (appType != TelephonyManager.APPTYPE_USIM
5388 && appType != TelephonyManager.APPTYPE_SIM) {
5389 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5390 return null;
5391 }
5392 Object response = sendRequest(
5393 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5394 if (response instanceof String[]) {
5395 return (String[]) response;
5396 }
yincheng zhao2737e882019-09-06 17:06:54 -07005397 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005399 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005402 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005403 }
5404
yincheng zhao2737e882019-09-06 17:06:54 -07005405 /**
5406 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5407 * subscription.
5408 *
5409 * @param subId the id of the subscription.
5410 * @param appType the uicc app type, must be USIM or SIM.
5411 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5412 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005413 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005414 * @return number of fplmns that is successfully written to the SIM.
5415 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005416 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5417 String callingFeatureId) {
5418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5419 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005420 if (DBG) logv("no permissions for setForbiddenplmns");
5421 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5422 }
5423 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5424 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5425 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5426 }
5427 if (fplmns == null) {
5428 throw new IllegalArgumentException("Fplmn List provided is null");
5429 }
5430 for (String fplmn : fplmns) {
5431 if (!CellIdentity.isValidPlmn(fplmn)) {
5432 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5433 }
5434 }
5435 final long identity = Binder.clearCallingIdentity();
5436 try {
5437 Object response = sendRequest(
5438 CMD_SET_FORBIDDEN_PLMNS,
5439 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5440 subId);
5441 return (int) response;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
5445 }
5446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005448 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5450 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5455 if (response.payload == null) {
5456 return "";
5457 }
Evan Charltonc66da362014-05-16 14:06:40 -07005458
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 // Append the returned status code to the end of the response payload.
5460 String s = Integer.toHexString(
5461 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5462 s = IccUtils.bytesToHexString(response.payload) + s;
5463 return s;
5464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
Evan Charltonc66da362014-05-16 14:06:40 -07005467 }
5468
Jake Hambye994d462014-02-03 13:10:13 -08005469 /**
5470 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5471 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5472 *
5473 * @param itemID the ID of the item to read
5474 * @return the NV item as a String, or null on error.
5475 */
5476 @Override
5477 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005478 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5480 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005485 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5487 return value;
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Jake Hambye994d462014-02-03 13:10:13 -08005491 }
5492
5493 /**
5494 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5495 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5496 *
5497 * @param itemID the ID of the item to read
5498 * @param itemValue the value to write, as a String
5499 * @return true on success; false on any failure
5500 */
5501 @Override
5502 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5505 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
5509 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5510 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005511 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5513 return success;
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Jake Hambye994d462014-02-03 13:10:13 -08005517 }
5518
5519 /**
5520 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5521 * Used for device configuration by some CDMA operators.
5522 *
5523 * @param preferredRoamingList byte array containing the new PRL
5524 * @return true on success; false on any failure
5525 */
5526 @Override
5527 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530
5531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5534 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5535 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5536 return success;
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
5539 }
Jake Hambye994d462014-02-03 13:10:13 -08005540 }
5541
5542 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005543 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005544 * Used for device configuration by some CDMA operators.
5545 *
chen xu6dac5ab2018-10-26 17:39:23 -07005546 * @param slotIndex - device slot.
5547 *
Jake Hambye994d462014-02-03 13:10:13 -08005548 * @return true on success; false on any failure
5549 */
5550 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005551 public boolean resetModemConfig(int slotIndex) {
5552 Phone phone = PhoneFactory.getPhone(slotIndex);
5553 if (phone != null) {
5554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5555 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
chen xu6dac5ab2018-10-26 17:39:23 -07005557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5560 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5561 return success;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 }
chen xu6dac5ab2018-10-26 17:39:23 -07005566 return false;
5567 }
5568
5569 /**
5570 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5571 *
5572 * @param slotIndex - device slot.
5573 *
5574 * @return true on success; false on any failure
5575 */
5576 @Override
5577 public boolean rebootModem(int slotIndex) {
5578 Phone phone = PhoneFactory.getPhone(slotIndex);
5579 if (phone != null) {
5580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5581 mApp, phone.getSubId(), "rebootModem");
5582
5583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5586 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5587 return success;
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
5591 }
5592 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005593 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005594
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005595 public String[] getPcscfAddress(String apnType, String callingPackage,
5596 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5599 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005600 return new String[0];
5601 }
5602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
Wink Saville36469e72014-06-11 15:17:00 -07005609 }
5610
Brad Ebinger51f743a2017-01-23 13:50:20 -08005611 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005612 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5613 * {@link #disableIms(int)}.
5614 * @param slotIndex device slot.
5615 */
5616 public void resetIms(int slotIndex) {
5617 enforceModifyPermission();
5618
5619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 if (mImsResolver == null) {
5622 // may happen if the does not support IMS.
5623 return;
5624 }
5625 mImsResolver.disableIms(slotIndex);
5626 mImsResolver.enableIms(slotIndex);
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
5630 }
5631
5632 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005633 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5634 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005635 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005636 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005641 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005642 // may happen if the device does not support IMS.
5643 return;
5644 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005645 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005649 }
5650
5651 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005652 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5653 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005654 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005655 public void disableIms(int slotId) {
5656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005660 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005661 // may happen if the device does not support IMS.
5662 return;
5663 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005664 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005668 }
5669
5670 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005671 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5672 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005673 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005674 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005675 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
5678 final long identity = Binder.clearCallingIdentity();
5679 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005680 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5682 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005683 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005684 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005688 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005689 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005690 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5691 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005692 @Override
5693 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005694 enforceModifyPermission();
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005699 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
5703 }
5704
5705 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005706 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005707 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005708 */
5709 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711
5712 final long identity = Binder.clearCallingIdentity();
5713 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005714 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005715 // may happen if the device does not support IMS.
5716 return null;
5717 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005722 }
5723
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005724 /**
5725 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005726 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005727 */
5728 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005733 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005734 // may happen if the device does not support IMS.
5735 return null;
5736 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005741 }
5742
Brad Ebinger884c07b2018-02-15 16:17:40 -08005743 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005744 * Sets the ImsService Package Name that Telephony will bind to.
5745 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 * @param slotIndex the slot ID that the ImsService should bind for.
5747 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005748 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005749 * @param featureTypes An integer array of feature types associated with a packageName.
5750 * @param packageName The name of the package that the current configuration will be replaced
5751 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005752 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005753 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005754 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5755 int[] featureTypes, String packageName) {
5756 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5759 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005760 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005764 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005765 // may happen if the device does not support IMS.
5766 return false;
5767 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 Map<Integer, String> featureConfig = new HashMap<>();
5769 for (int featureType : featureTypes) {
5770 featureConfig.put(featureType, packageName);
5771 }
5772 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5773 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005777 }
5778
5779 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005780 * Clears any carrier ImsService overrides for the slot index specified that were previously
5781 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5782 *
5783 * This should only be used for testing.
5784 *
5785 * @param slotIndex the slot ID that the ImsService should bind for.
5786 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5787 */
5788 @Override
5789 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5790 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5792 "clearCarrierImsServiceOverride");
5793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5794 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5795 "clearCarrierImsServiceOverride");
5796
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 if (mImsResolver == null) {
5800 // may happen if the device does not support IMS.
5801 return false;
5802 }
5803 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
5807 }
5808
5809 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005811 *
5812 * @param slotId The slot that the ImsService is associated with.
5813 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5814 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 * @return the package name of the ImsService configuration.
5817 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005818 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5819 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005820 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005822 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5824 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 final long identity = Binder.clearCallingIdentity();
5827 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005828 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005829 // may happen if the device does not support IMS.
5830 return "";
5831 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005832 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005833 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5834 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005838 }
5839
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005840 /**
5841 * Get the MmTelFeature state associated with the requested subscription id.
5842 * @param subId The subscription that the MmTelFeature is associated with.
5843 * @param callback A callback with an integer containing the
5844 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5845 */
5846 @Override
5847 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5848 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5849 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5850 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5851 "IMS not available on device.");
5852 }
5853 final long token = Binder.clearCallingIdentity();
5854 try {
5855 int slotId = getSlotIndex(subId);
5856 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5857 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5858 + subId + "'");
5859 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5860 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005861 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005862 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5863 try {
5864 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5865 } catch (RemoteException e) {
5866 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5867 + "Ignore");
5868 }
5869 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005870 } catch (ImsException e) {
5871 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005872 } finally {
5873 Binder.restoreCallingIdentity(token);
5874 }
5875 }
5876
Daniel Brightbb5840b2021-01-12 15:48:18 -08005877 /**
5878 * Sets the ims registration state on all valid {@link Phone}s.
5879 */
5880 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005881 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005885 // NOTE: Before S, this method only set the default phone.
5886 for (final Phone phone : PhoneFactory.getPhones()) {
5887 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5888 phone.setImsRegistrationState(registered);
5889 }
5890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Wink Saville36469e72014-06-11 15:17:00 -07005894 }
5895
5896 /**
Stuart Scott54788802015-03-30 13:18:01 -07005897 * Set the network selection mode to automatic.
5898 *
5899 */
5900 @Override
5901 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5903 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
shilufc958392020-01-20 11:36:01 -08005907 if (!isActiveSubscription(subId)) {
5908 return;
5909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005911 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5912 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Stuart Scott54788802015-03-30 13:18:01 -07005916 }
5917
Jack Yud10cdd42020-09-28 20:28:01 -07005918 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005919 * Ask the radio to connect to the input network and change selection mode to manual.
5920 *
5921 * @param subId the id of the subscription.
5922 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5923 * the operator to attach to.
5924 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5925 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5926 * normal network selection next time.
5927 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005928 */
5929 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005930 public boolean setNetworkSelectionModeManual(
5931 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5933 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005934
5935 if (!isActiveSubscription(subId)) {
5936 return false;
5937 }
5938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 final long identity = Binder.clearCallingIdentity();
5940 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005941 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005942 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005943 if (DBG) {
5944 log("setNetworkSelectionModeManual: subId: " + subId
5945 + " operator: " + operatorInfo);
5946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005951 }
shilu84f6e8b2019-12-19 13:58:01 -08005952 /**
5953 * Get the manual network selection
5954 *
5955 * @param subId the id of the subscription.
5956 *
5957 * @return the previously saved user selected PLMN
5958 */
5959 @Override
5960 public String getManualNetworkSelectionPlmn(int subId) {
5961 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005962 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005963 mApp, subId, "getManualNetworkSelectionPlmn");
5964
5965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005968 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005969 }
5970
5971 final Phone phone = getPhone(subId);
5972 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005973 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005974 }
5975 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5976 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5977 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
5981 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005982
5983 /**
5984 * Scans for available networks.
5985 */
5986 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005987 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5990 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005991 LocationAccessPolicy.LocationPermissionResult locationResult =
5992 LocationAccessPolicy.checkLocationPermission(mApp,
5993 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5994 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005995 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005996 .setCallingPid(Binder.getCallingPid())
5997 .setCallingUid(Binder.getCallingUid())
5998 .setMethod("getCellNetworkScanResults")
5999 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006000 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6001 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006002 .build());
6003 switch (locationResult) {
6004 case DENIED_HARD:
6005 throw new SecurityException("Not allowed to access scan results -- location");
6006 case DENIED_SOFT:
6007 return null;
6008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009
Pengquan Menga1bb6272018-09-06 09:59:22 -07006010 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 try {
6012 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006013 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006018 }
6019
6020 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006021 * Get the call forwarding info, given the call forwarding reason.
6022 */
6023 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006024 public void getCallForwarding(int subId, int callForwardingReason,
6025 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006026 enforceReadPrivilegedPermission("getCallForwarding");
6027 long identity = Binder.clearCallingIdentity();
6028 try {
6029 if (DBG) {
6030 log("getCallForwarding: subId " + subId
6031 + " callForwardingReason" + callForwardingReason);
6032 }
Hall Liu27d24262020-09-18 19:04:59 -07006033
6034 Phone phone = getPhone(subId);
6035 if (phone == null) {
6036 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006037 callback.onError(
6038 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006039 } catch (RemoteException e) {
6040 // ignore
6041 }
6042 return;
6043 }
6044
6045 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6046 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6047 @Override
6048 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6049 try {
6050 callback.onCallForwardingInfoAvailable(info);
6051 } catch (RemoteException e) {
6052 // ignore
6053 }
6054 }
6055
6056 @Override
6057 public void onError(int error) {
6058 try {
6059 callback.onError(error);
6060 } catch (RemoteException e) {
6061 // ignore
6062 }
6063 }
6064 });
6065 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
6069 }
6070
6071 /**
6072 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6073 * reason, the number to forward, and the timeout before the forwarding is attempted.
6074 */
6075 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006076 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6077 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006078 enforceModifyPermission();
6079 long identity = Binder.clearCallingIdentity();
6080 try {
6081 if (DBG) {
6082 log("setCallForwarding: subId " + subId
6083 + " callForwardingInfo" + callForwardingInfo);
6084 }
Hall Liu27d24262020-09-18 19:04:59 -07006085
6086 Phone phone = getPhone(subId);
6087 if (phone == null) {
6088 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006089 callback.accept(
6090 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006091 } catch (RemoteException e) {
6092 // ignore
6093 }
6094 return;
6095 }
6096
6097 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6098 FunctionalUtils.ignoreRemoteException(callback::accept));
6099
6100 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
6103 }
6104 }
6105
6106 /**
Hall Liu27d24262020-09-18 19:04:59 -07006107 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006108 */
6109 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006110 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006111 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006112 long identity = Binder.clearCallingIdentity();
6113 try {
Hall Liu27d24262020-09-18 19:04:59 -07006114 Phone phone = getPhone(subId);
6115 if (phone == null) {
6116 try {
6117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6118 } catch (RemoteException e) {
6119 // ignore
6120 }
6121 return;
6122 }
SongFerngWang0e767992021-03-31 22:08:45 +08006123 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6124 PersistableBundle c = configManager.getConfigForSubId(subId);
6125 boolean requireUssd = c.getBoolean(
6126 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006127
Shuo Qian4a594052020-01-23 11:59:30 -08006128 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006129 if (requireUssd) {
6130 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6131 getSubscriptionCarrierId(subId));
6132 String newUssdCommand = "";
6133 try {
6134 newUssdCommand = carrierXmlParser.getFeature(
6135 CarrierXmlParser.FEATURE_CALL_WAITING)
6136 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6137 } catch (NullPointerException e) {
6138 loge("Failed to generate USSD number" + e);
6139 }
6140 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6141 mMainThreadHandler, callback, carrierXmlParser,
6142 CarrierXmlParser.SsEntry.SSAction.QUERY);
6143 final String ussdCommand = newUssdCommand;
6144 Executors.newSingleThreadExecutor().execute(() -> {
6145 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6146 });
6147 } else {
6148 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6149 callback::accept);
6150 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6151 }
Shuo Qian4a594052020-01-23 11:59:30 -08006152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
6155 }
6156
6157 /**
Hall Liu27d24262020-09-18 19:04:59 -07006158 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006159 */
6160 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006161 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006162 enforceModifyPermission();
6163 long identity = Binder.clearCallingIdentity();
6164 try {
Hall Liu27d24262020-09-18 19:04:59 -07006165 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6166
6167 Phone phone = getPhone(subId);
6168 if (phone == null) {
6169 try {
6170 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6171 } catch (RemoteException e) {
6172 // ignore
6173 }
6174 return;
6175 }
6176
SongFerngWang0e767992021-03-31 22:08:45 +08006177 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6178 PersistableBundle c = configManager.getConfigForSubId(subId);
6179 boolean requireUssd = c.getBoolean(
6180 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006181
SongFerngWang0e767992021-03-31 22:08:45 +08006182 if (DBG) log("getCallWaitingStatus: subId " + subId);
6183 if (requireUssd) {
6184 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6185 getSubscriptionCarrierId(subId));
6186 CarrierXmlParser.SsEntry.SSAction ssAction =
6187 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6188 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6189 String newUssdCommand = "";
6190 try {
6191 newUssdCommand = carrierXmlParser.getFeature(
6192 CarrierXmlParser.FEATURE_CALL_WAITING)
6193 .makeCommand(ssAction, null);
6194 } catch (NullPointerException e) {
6195 loge("Failed to generate USSD number" + e);
6196 }
6197 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6198 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6199 final String ussdCommand = newUssdCommand;
6200 Executors.newSingleThreadExecutor().execute(() -> {
6201 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6202 });
6203 } else {
6204 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6205 FunctionalUtils.ignoreRemoteException(callback::accept));
6206
6207 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6208 }
Shuo Qian4a594052020-01-23 11:59:30 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
yinxub1bed742017-04-17 11:45:04 -07006215 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006216 *
yinxub1bed742017-04-17 11:45:04 -07006217 * @param subId id of the subscription
6218 * @param request contains the radio access networks with bands/channels to scan
6219 * @param messenger callback messenger for scan results or errors
6220 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006221 * @return the id of the requested scan which can be used to stop the scan.
6222 */
6223 @Override
6224 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006225 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6227 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006228 LocationAccessPolicy.LocationPermissionResult locationResult =
6229 LocationAccessPolicy.checkLocationPermission(mApp,
6230 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6231 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006232 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006233 .setCallingPid(Binder.getCallingPid())
6234 .setCallingUid(Binder.getCallingUid())
6235 .setMethod("requestNetworkScan")
6236 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006237 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6238 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006239 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006240 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006241 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6242 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006243 if (e != null) {
6244 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6245 throw e;
6246 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006247 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006248 return TelephonyScanManager.INVALID_SCAN_ID;
6249 }
6250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 }
Hall Liu912dfd32019-04-25 14:02:26 -07006252 int callingUid = Binder.getCallingUid();
6253 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006254 final long identity = Binder.clearCallingIdentity();
6255 try {
6256 return mNetworkScanRequestTracker.startNetworkScan(
6257 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006258 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
yinxu504e1392017-04-12 16:03:22 -07006262 }
6263
Hall Liub2ac8ef2019-02-28 15:56:23 -08006264 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006265 NetworkScanRequest request, int subId, String callingPackage) {
6266 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006267 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6268 boolean hasNetworkScanPermission =
6269 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6270 == PERMISSION_GRANTED;
6271
6272 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6273 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6274 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006275 }
6276
6277 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6278 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006279 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6280 return new SecurityException("Specific channels must not be"
6281 + " scanned without location access.");
6282 }
6283 }
6284 }
6285
Hall Liub2ac8ef2019-02-28 15:56:23 -08006286 return null;
6287 }
6288
yinxu504e1392017-04-12 16:03:22 -07006289 /**
6290 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006291 *
6292 * @param subId id of the subscription
6293 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006294 */
6295 @Override
6296 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6298 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299
Hall Liu912dfd32019-04-25 14:02:26 -07006300 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006303 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 } finally {
6305 Binder.restoreCallingIdentity(identity);
6306 }
yinxu504e1392017-04-12 16:03:22 -07006307 }
6308
6309 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006310 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006311 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006312 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006313 */
6314 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006315 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006316 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006317 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006318 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
6320 final long identity = Binder.clearCallingIdentity();
6321 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006322 if (DBG) log("getAllowedNetworkTypesBitmask");
6323 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6324 int networkTypesBitmask = (result != null ? result[0] : -1);
6325 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6326 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006330 }
6331
6332 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006333 * Get the allowed network types for certain reason.
6334 *
6335 * @param subId the id of the subscription.
6336 * @param reason the reason the allowed network type change is taking place
6337 * @return the allowed network types.
6338 */
6339 @Override
6340 public long getAllowedNetworkTypesForReason(int subId,
6341 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006342 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006343 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006344 final long identity = Binder.clearCallingIdentity();
6345 try {
6346 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
6350 }
6351
6352 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006353 * Enable/Disable E-UTRA-NR Dual Connectivity
6354 * @param subId subscription id of the sim card
6355 * @param nrDualConnectivityState expected NR dual connectivity state
6356 * This can be passed following states
6357 * <ol>
6358 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6359 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6360 * <li>Disable NR dual connectivity and force secondary cell to be released
6361 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6362 * </ol>
6363 * @return operation result.
6364 */
6365 @Override
6366 public int setNrDualConnectivityState(int subId,
6367 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6369 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006370 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006371 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6372 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6373 }
6374
Sooraj Sasindran37444802020-08-11 10:40:43 -07006375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6379 nrDualConnectivityState, subId,
6380 workSource);
6381 if (DBG) log("enableNRDualConnectivity result: " + result);
6382 return result;
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 }
6387
6388 /**
6389 * Is E-UTRA-NR Dual Connectivity enabled
6390 * @return true if dual connectivity is enabled else false
6391 */
6392 @Override
6393 public boolean isNrDualConnectivityEnabled(int subId) {
6394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006396 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006397 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006398 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6399 return false;
6400 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6405 null, subId, workSource);
6406 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6407 return isEnabled;
6408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
6411 }
6412
6413 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006414 * Set the allowed network types of the device and
6415 * provide the reason triggering the allowed network change.
6416 *
6417 * @param subId the id of the subscription.
6418 * @param reason the reason the allowed network type change is taking place
6419 * @param allowedNetworkTypes the allowed network types.
6420 * @return true on success; false on any failure.
6421 */
6422 @Override
6423 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006424 @TelephonyManager.AllowedNetworkTypesReason int reason,
6425 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6427 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006428 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006429 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6430 return false;
6431 }
6432 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6433 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006434 return false;
6435 }
6436
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006437 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6438 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6439
6440
6441 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6442 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6443 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006444 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006445
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006446 final long identity = Binder.clearCallingIdentity();
6447 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006448 Boolean success = (Boolean) sendRequest(
6449 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6450 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6451
6452 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6453 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
6457 }
6458
6459 /**
Miaoa84611c2019-03-15 09:21:10 +08006460 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006461 *
Miaoa84611c2019-03-15 09:21:10 +08006462 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006463 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006464 * @hide
6465 */
6466 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006467 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006470 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471 try {
Miaoa84611c2019-03-15 09:21:10 +08006472 if (phone != null) {
6473 return phone.hasMatchedTetherApnSetting();
6474 } else {
6475 return false;
6476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 } finally {
6478 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006479 }
Junda Liu475951f2014-11-07 16:45:03 -08006480 }
6481
6482 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006483 * Enable or disable always reporting signal strength changes from radio.
6484 *
6485 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6486 */
6487 @Override
6488 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6489 enforceModifyPermission();
6490 enforceSystemCaller();
6491
6492 final long identity = Binder.clearCallingIdentity();
6493 final Phone phone = getPhone(subId);
6494 try {
6495 if (phone != null) {
6496 if (DBG) {
6497 log("setAlwaysReportSignalStrength: subId=" + subId
6498 + " isEnable=" + isEnable);
6499 }
6500 phone.setAlwaysReportSignalStrength(isEnable);
6501 } else {
6502 loge("setAlwaysReportSignalStrength: no phone found for subId="
6503 + subId);
6504 }
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
6508 }
6509
6510 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006511 * Get the user enabled state of Mobile Data.
6512 *
6513 * TODO: remove and use isUserDataEnabled.
6514 * This can't be removed now because some vendor codes
6515 * calls through ITelephony directly while they should
6516 * use TelephonyManager.
6517 *
6518 * @return true on enabled
6519 */
6520 @Override
6521 public boolean getDataEnabled(int subId) {
6522 return isUserDataEnabled(subId);
6523 }
6524
6525 /**
6526 * Get whether mobile data is enabled per user setting.
6527 *
6528 * There are other factors deciding whether mobile data is actually enabled, but they are
6529 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006530 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006531 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006532 *
6533 * @return {@code true} if data is enabled else {@code false}
6534 */
6535 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006536 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006537 try {
6538 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6539 null);
6540 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6542 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 int phoneId = mSubscriptionController.getPhoneId(subId);
6548 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6549 Phone phone = PhoneFactory.getPhone(phoneId);
6550 if (phone != null) {
6551 boolean retVal = phone.isUserDataEnabled();
6552 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6553 return retVal;
6554 } else {
6555 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6556 return false;
6557 }
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006560 }
6561 }
6562
6563 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006564 * Checks if the device is capable of mobile data by considering whether whether the
6565 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6566 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006567 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006568 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006569 */
6570 @Override
6571 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006572 try {
6573 try {
6574 mApp.enforceCallingOrSelfPermission(
6575 android.Manifest.permission.ACCESS_NETWORK_STATE,
6576 null);
6577 } catch (Exception e) {
6578 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6579 "isDataEnabled");
6580 }
6581 } catch (Exception e) {
6582 enforceReadPrivilegedPermission("isDataEnabled");
6583 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
6587 int phoneId = mSubscriptionController.getPhoneId(subId);
6588 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6589 Phone phone = PhoneFactory.getPhone(phoneId);
6590 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006591 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6593 return retVal;
6594 } else {
6595 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6596 return false;
6597 }
6598 } finally {
6599 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006600 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006601 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006602
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006603 /**
6604 * Check if data is enabled for a specific reason
6605 * @param subId Subscription index
6606 * @param reason the reason the data enable change is taking place
6607 * @return {@code true} if the overall data is enabled; {@code false} if not.
6608 */
6609 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006610 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006611 @TelephonyManager.DataEnabledReason int reason) {
6612 try {
6613 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6614 null);
6615 } catch (Exception e) {
6616 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006617 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006618 }
6619
6620
6621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 int phoneId = mSubscriptionController.getPhoneId(subId);
6624 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006625 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006626 + " reason=" + reason);
6627 }
6628 Phone phone = PhoneFactory.getPhone(phoneId);
6629 if (phone != null) {
6630 boolean retVal;
6631 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6632 retVal = phone.isUserDataEnabled();
6633 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006636 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006637 return retVal;
6638 } else {
6639 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006640 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006641 + subId + " retVal=false");
6642 }
6643 return false;
6644 }
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
6648 }
6649
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006650 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006651 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006652 if (uid == Process.PHONE_UID) {
6653 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6654 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006655 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6656 }
6657
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006658 //load access rules from carrier configs, and check those as well: b/139133814
6659 SubscriptionController subController = SubscriptionController.getInstance();
6660 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6661 || subController == null) return privilegeFromSim;
6662
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006663 PackageManager pkgMgr = phone.getContext().getPackageManager();
6664 String[] packages = pkgMgr.getPackagesForUid(uid);
6665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006668 int subId = phone.getSubId();
6669 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6670 // A test override is in place for the privileges for this subId, so don't try to
6671 // read the subscription privileges.
6672 return privilegeFromSim;
6673 }
6674 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006675 SubscriptionManager subManager = (SubscriptionManager)
6676 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6677 for (String pkg : packages) {
6678 if (subManager.canManageSubscription(subInfo, pkg)) {
6679 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6680 }
6681 }
6682 return privilegeFromSim;
6683 } finally {
6684 Binder.restoreCallingIdentity(identity);
6685 }
6686 }
6687
6688 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6689 String pkgName) {
6690 //load access rules from carrier configs, and check those as well: b/139133814
6691 SubscriptionController subController = SubscriptionController.getInstance();
6692 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6693 || subController == null) return privilegeFromSim;
6694
6695 final long identity = Binder.clearCallingIdentity();
6696 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006697 int subId = phone.getSubId();
6698 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6699 // A test override is in place for the privileges for this subId, so don't try to
6700 // read the subscription privileges.
6701 return privilegeFromSim;
6702 }
6703 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006704 SubscriptionManager subManager = (SubscriptionManager)
6705 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6706 return subManager.canManageSubscription(subInfo, pkgName)
6707 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
6712
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006713 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006714 public int getCarrierPrivilegeStatus(int subId) {
6715 final Phone phone = getPhone(subId);
6716 if (phone == null) {
6717 loge("getCarrierPrivilegeStatus: Invalid subId");
6718 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6719 }
6720 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006721 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006722 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006723 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6724 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006725
6726 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6727 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006728 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006729 }
Junda Liu29340342014-07-10 15:23:27 -07006730
6731 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006732 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006733 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 final Phone phone = getPhone(subId);
6735 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006736 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6738 }
6739 UiccProfile profile =
6740 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6741 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006742 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6744 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006745 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006746 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006747 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006748 }
6749
6750 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006751 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006752 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006753 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006754 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006755 }
6756
6757 int phoneId = SubscriptionManager.getPhoneId(subId);
6758 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006759 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006760 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6762 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006763 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6764 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6765 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006766 }
6767
6768 @Override
6769 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006770 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006771 if (TextUtils.isEmpty(pkgName))
6772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006773 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6774 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6775 UiccCard card = UiccController.getInstance().getUiccCard(i);
6776 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006777 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006778 continue;
6779 }
6780
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006781 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6782 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6783 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006784 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6785 break;
6786 }
6787 }
6788
6789 return result;
Junda Liu29340342014-07-10 15:23:27 -07006790 }
Derek Tan89e89d42014-07-08 17:00:10 -07006791
6792 @Override
Junda Liue64de782015-04-16 17:19:16 -07006793 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006794 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006795 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6796 loge("phoneId " + phoneId + " is not valid.");
6797 return null;
6798 }
6799 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006800 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006801 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006802 return null ;
6803 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006804 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006805 }
6806
Amith Yamasani6e118872016-02-19 12:53:51 -08006807 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006808 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006809 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006810 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006811 List<String> privilegedPackages = new ArrayList<>();
6812 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006813 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6814 // has UICC in that slot.
6815 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006816 if (card.hasCarrierPrivilegeRules()) {
6817 if (packages == null) {
6818 // Only check packages in user 0 for now
6819 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006820 PackageManager.MATCH_DISABLED_COMPONENTS
6821 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006822 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006823 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006824 }
6825 for (int p = packages.size() - 1; p >= 0; p--) {
6826 PackageInfo pkgInfo = packages.get(p);
6827 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006828 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6829 card.getCarrierPrivilegeStatus(pkgInfo),
6830 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006831 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006832 privilegedPackages.add(pkgInfo.packageName);
6833 }
6834 }
6835 }
6836 }
6837 return privilegedPackages;
6838 }
6839
chen xuf7e9fe82019-05-09 19:31:02 -07006840 @Override
6841 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006842 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6843
6844 final long identity = Binder.clearCallingIdentity();
6845
chen xuf7e9fe82019-05-09 19:31:02 -07006846 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006847 try {
6848 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6849 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6850 }
6851 } finally {
6852 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006853 }
6854 return privilegedPackages;
6855 }
6856
Wink Savilleb564aae2014-10-23 10:18:09 -07006857 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006858 final Phone phone = getPhone(subId);
6859 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006860 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006861 return null;
6862 }
6863 String iccId = card.getIccId();
6864 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006865 return null;
6866 }
6867 return iccId;
6868 }
6869
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006870 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006871 public void setCallComposerStatus(int subId, int status) {
6872 enforceModifyPermission();
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 Phone phone = getPhone(subId);
6877 if (phone != null) {
6878 Phone defaultPhone = phone.getImsPhone();
6879 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6880 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6881 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006882 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6883 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006884 }
6885 }
Shuo Qian284ae752020-12-22 19:10:14 -08006886 } catch (ImsException e) {
6887 throw new ServiceSpecificException(e.getCode());
6888 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
6892
6893 @Override
6894 public int getCallComposerStatus(int subId) {
6895 enforceReadPrivilegedPermission("getCallComposerStatus");
6896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 Phone phone = getPhone(subId);
6900 if (phone != null) {
6901 Phone defaultPhone = phone.getImsPhone();
6902 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6903 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6904 return imsPhone.getCallComposerStatus();
6905 }
6906 }
6907 } finally {
6908 Binder.restoreCallingIdentity(identity);
6909 }
6910 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6911 }
6912
6913 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006914 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6915 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006916 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006917 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006918
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 final String iccId = getIccId(subId);
6922 final Phone phone = getPhone(subId);
6923 if (phone == null) {
6924 return false;
6925 }
6926 final String subscriberId = phone.getSubscriberId();
6927
6928 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006929 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 + subscriberId + " to " + number);
6931 }
6932
6933 if (TextUtils.isEmpty(iccId)) {
6934 return false;
6935 }
6936
6937 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6938
6939 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6940 if (alphaTag == null) {
6941 editor.remove(alphaTagPrefKey);
6942 } else {
6943 editor.putString(alphaTagPrefKey, alphaTag);
6944 }
6945
6946 // Record both the line number and IMSI for this ICCID, since we need to
6947 // track all merged IMSIs based on line number
6948 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6949 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6950 if (number == null) {
6951 editor.remove(numberPrefKey);
6952 editor.remove(subscriberPrefKey);
6953 } else {
6954 editor.putString(numberPrefKey, number);
6955 editor.putString(subscriberPrefKey, subscriberId);
6956 }
6957
6958 editor.commit();
6959 return true;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006962 }
Derek Tan7226c842014-07-02 17:42:23 -07006963 }
6964
6965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006966 public String getLine1NumberForDisplay(int subId, String callingPackage,
6967 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006968 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006970 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006971 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006972 return null;
6973 }
Derek Tan97ebb422014-09-05 16:55:38 -07006974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975 final long identity = Binder.clearCallingIdentity();
6976 try {
6977 String iccId = getIccId(subId);
6978 if (iccId != null) {
6979 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6980 if (DBG_MERGE) {
6981 log("getLine1NumberForDisplay returning "
6982 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6983 }
6984 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6987 return null;
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006990 }
Derek Tan7226c842014-07-02 17:42:23 -07006991 }
6992
6993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006994 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006997 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006998 return null;
6999 }
Derek Tan97ebb422014-09-05 16:55:38 -07007000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 String iccId = getIccId(subId);
7004 if (iccId != null) {
7005 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7006 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7007 }
7008 return null;
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007011 }
Derek Tan7226c842014-07-02 17:42:23 -07007012 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007013
7014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007015 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007017 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7018 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007020 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007021 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007022 return null;
7023 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007024
Jordan Liub49b04b2019-05-06 14:45:15 -07007025 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7026 // the process, where TelephonyManager was instantiated.
7027 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007028 final long identity = Binder.clearCallingIdentity();
7029 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 final TelephonyManager tele = TelephonyManager.from(context);
7032 final SubscriptionManager sub = SubscriptionManager.from(context);
7033
7034 // Figure out what subscribers are currently active
7035 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036
Jordan Liub49b04b2019-05-06 14:45:15 -07007037 // Only consider subs which match the current subId
7038 // This logic can be simplified. See b/131189269 for progress.
7039 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007040 activeSubscriberIds.add(tele.getSubscriberId(subId));
7041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042
7043 // First pass, find a number override for an active subscriber
7044 String mergeNumber = null;
7045 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7046 for (String key : prefs.keySet()) {
7047 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7048 final String subscriberId = (String) prefs.get(key);
7049 if (activeSubscriberIds.contains(subscriberId)) {
7050 final String iccId = key.substring(
7051 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7052 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7053 mergeNumber = (String) prefs.get(numberKey);
7054 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007055 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 + " for active subscriber " + subscriberId);
7057 }
7058 if (!TextUtils.isEmpty(mergeNumber)) {
7059 break;
7060 }
7061 }
7062 }
7063 }
7064
7065 // Shortcut when no active merged subscribers
7066 if (TextUtils.isEmpty(mergeNumber)) {
7067 return null;
7068 }
7069
7070 // Second pass, find all subscribers under that line override
7071 final ArraySet<String> result = new ArraySet<>();
7072 for (String key : prefs.keySet()) {
7073 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7074 final String number = (String) prefs.get(key);
7075 if (mergeNumber.equals(number)) {
7076 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7077 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7078 final String subscriberId = (String) prefs.get(subscriberKey);
7079 if (!TextUtils.isEmpty(subscriberId)) {
7080 result.add(subscriberId);
7081 }
7082 }
7083 }
7084 }
7085
7086 final String[] resultArray = result.toArray(new String[result.size()]);
7087 Arrays.sort(resultArray);
7088 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007089 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7091 }
7092 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007095 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007096 }
7097
7098 @Override
zoey chen38003472019-12-13 17:16:31 +08007099 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7100 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007101
7102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 final TelephonyManager telephonyManager = mApp.getSystemService(
7105 TelephonyManager.class);
7106 String subscriberId = telephonyManager.getSubscriberId(subId);
7107 if (subscriberId == null) {
7108 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007109 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007110 + subId);
7111 }
7112 return null;
7113 }
7114
7115 final SubscriptionInfo info = SubscriptionController.getInstance()
7116 .getSubscriptionInfo(subId);
7117 final ParcelUuid groupUuid = info.getGroupUuid();
7118 // If it doesn't belong to any group, return just subscriberId of itself.
7119 if (groupUuid == null) {
7120 return new String[]{subscriberId};
7121 }
7122
7123 // Get all subscriberIds from the group.
7124 final List<String> mergedSubscriberIds = new ArrayList<>();
7125 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007127 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007128 for (SubscriptionInfo subInfo : groupInfos) {
7129 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7130 if (subscriberId != null) {
7131 mergedSubscriberIds.add(subscriberId);
7132 }
7133 }
7134
7135 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138
7139 }
7140 }
7141
7142 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007143 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007144 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007145 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 final Phone phone = getPhone(subId);
7150 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007154 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007155
7156 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007157 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007158 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7159 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007160 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7161 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 final Phone phone = getPhone(subId);
7166 if (phone == null) {
7167 return false;
7168 }
7169 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7170 cdmaNonRoamingList);
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007173 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007174 }
7175
7176 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007177 @Deprecated
7178 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7179 enforceModifyPermission();
7180
7181 int returnValue = 0;
7182 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007183 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007184 if(result.exception == null) {
7185 if (result.result != null) {
7186 byte[] responseData = (byte[])(result.result);
7187 if(responseData.length > oemResp.length) {
7188 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7189 responseData.length + "bytes. Buffer Size is " +
7190 oemResp.length + "bytes.");
7191 }
7192 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7193 returnValue = responseData.length;
7194 }
7195 } else {
7196 CommandException ex = (CommandException) result.exception;
7197 returnValue = ex.getCommandError().ordinal();
7198 if(returnValue > 0) returnValue *= -1;
7199 }
7200 } catch (RuntimeException e) {
7201 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7202 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7203 if(returnValue > 0) returnValue *= -1;
7204 }
7205
7206 return returnValue;
7207 }
7208
7209 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007210 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007211 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007212 try {
7213 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007214 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007215 mApp, phone.getSubId(), "getRadioAccessFamily");
7216 } catch (SecurityException e) {
7217 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7218 throw e;
7219 }
chen xub97461a2018-10-26 14:17:57 -07007220 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007221 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007222 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 final long identity = Binder.clearCallingIdentity();
7225 try {
chen xub97461a2018-10-26 14:17:57 -07007226 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007228 mApp, phone.getSubId(), "getRadioAccessFamily");
7229 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
chen xub97461a2018-10-26 14:17:57 -07007233 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007234 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007235
7236 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007237 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007238 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007239 try {
7240 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7241 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007242 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007243 }
7244 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007245 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007246 }
7247 RoleManager rm = mApp.getSystemService(RoleManager.class);
7248 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7249 if (!dialerRoleHolders.contains(callingPackage)) {
7250 throw new SecurityException("App must be the dialer role holder to"
7251 + " upload a call composer pic");
7252 }
7253
7254 Executors.newSingleThreadExecutor().execute(() -> {
7255 ByteArrayOutputStream output = new ByteArrayOutputStream(
7256 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7257 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7258 boolean readUntilEnd = false;
7259 int totalBytesRead = 0;
7260 byte[] buffer = new byte[16 * 1024];
7261 while (true) {
7262 int numRead;
7263 try {
7264 numRead = input.read(buffer);
7265 } catch (IOException e) {
7266 try {
7267 fd.checkError();
7268 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7269 null);
7270 } catch (IOException e1) {
7271 // This means that the other side closed explicitly with an error. If this
7272 // happens, log and ignore.
7273 loge("Remote end of call composer picture pipe closed: " + e1);
7274 }
7275 break;
7276 }
7277 if (numRead == -1) {
7278 readUntilEnd = true;
7279 break;
7280 }
7281 totalBytesRead += numRead;
7282 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7283 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7284 try {
7285 input.close();
7286 } catch (IOException e) {
7287 // ignore
7288 }
7289 break;
7290 }
7291 output.write(buffer, 0, numRead);
7292 }
7293 // Generally, the remote end will close the file descriptors. The only case where we
7294 // close is above, where the picture size is too big.
7295
7296 try {
7297 fd.checkError();
7298 } catch (IOException e) {
7299 loge("Remote end for call composer closed with an error: " + e);
7300 return;
7301 }
7302
Hall Liuaa4211e2021-01-20 15:43:39 -08007303 if (!readUntilEnd) {
7304 loge("Did not finish reading entire image; aborting");
7305 return;
7306 }
Hall Liu82694d52020-12-11 18:22:04 -08007307
Hall Liuaa4211e2021-01-20 15:43:39 -08007308 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7309 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7310 new CallComposerPictureTransfer.Factory() {},
7311 imageData,
7312 (result) -> {
7313 if (result.first != null) {
7314 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7315 Bundle outputResult = new Bundle();
7316 outputResult.putParcelable(
7317 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7318 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7319 outputResult);
7320 } else {
7321 callback.send(result.second, null);
7322 }
7323 }
7324 );
Hall Liu82694d52020-12-11 18:22:04 -08007325 });
7326 }
7327
7328 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007329 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007330 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332
7333 final long identity = Binder.clearCallingIdentity();
7334 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335 ImsManager.getInstance(defaultPhone.getContext(),
7336 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007340 }
7341
7342 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007344 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7346 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007347 return false;
7348 }
Svet Ganovb320e182015-04-16 12:30:10 -07007349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 // Check the user preference and the system-level IMS setting. Even if the user has
7353 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7354 // In the long run, we may instead need to check if there exists a connection service
7355 // which can support video calling.
7356 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007357 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 return imsManager.isVtEnabledByPlatform()
7359 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7360 && imsManager.isVtEnabledByUser();
7361 } finally {
7362 Binder.restoreCallingIdentity(identity);
7363 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007364 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007365
Andrew Leea1239f22015-03-02 17:44:07 -08007366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007367 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7368 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007370 mApp, subId, callingPackage, callingFeatureId,
7371 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 return false;
7373 }
7374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
7377 CarrierConfigManager configManager =
7378 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007379 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7381 } finally {
7382 Binder.restoreCallingIdentity(identity);
7383 }
Andrew Leea1239f22015-03-02 17:44:07 -08007384 }
7385
7386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007389 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 return false;
7391 }
7392
7393 final long identity = Binder.clearCallingIdentity();
7394 try {
7395 CarrierConfigManager configManager =
7396 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007397 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
Andrew Leea1239f22015-03-02 17:44:07 -08007402 }
7403
Andrew Lee9431b832015-03-09 18:46:45 -07007404 @Override
7405 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007406 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007407 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007408 }
7409
7410 @Override
7411 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 final long identity = Binder.clearCallingIdentity();
7413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007414 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Andrew Lee9431b832015-03-09 18:46:45 -07007418 }
7419
Hall Liuf6668912018-10-31 17:05:23 -07007420 /**
7421 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7422 * support for the feature and device firmware support.
7423 *
7424 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7425 */
7426 @Override
7427 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 final Phone phone = getPhone(subscriptionId);
7430 if (phone == null) {
7431 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7432 return false;
7433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7437 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007438 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 return isCarrierSupported && isDeviceSupported;
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
Hall Liu98187582018-01-22 19:15:32 -08007443 }
7444
Hall Liuf6668912018-10-31 17:05:23 -07007445 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007446 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7447 * RTT setting, will return true if the device and carrier both support RTT.
7448 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007449 */
7450 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 final long identity = Binder.clearCallingIdentity();
7452 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007453 boolean isRttSupported = isRttSupported(subscriptionId);
7454 boolean isUserRttSettingOn = Settings.Secure.getInt(
7455 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7456 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7457 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7458 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007462 }
7463
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007464 @Deprecated
7465 @Override
7466 public String getDeviceId(String callingPackage) {
7467 return getDeviceIdWithFeature(callingPackage, null);
7468 }
7469
Sanket Padawe7310cc72015-01-14 09:53:20 -08007470 /**
7471 * Returns the unique device ID of phone, for example, the IMEI for
7472 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7473 *
7474 * <p>Requires Permission:
7475 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7476 */
7477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007480 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007481 return null;
7482 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007483 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007484 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007486 return null;
7487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488
7489 final long identity = Binder.clearCallingIdentity();
7490 try {
7491 return phone.getDeviceId();
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 }
7496
Ping Sunc67b7c22016-03-02 19:16:45 +08007497 /**
7498 * {@hide}
7499 * Returns the IMS Registration Status on a particular subid
7500 *
7501 * @param subId
7502 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007503 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007504 Phone phone = getPhone(subId);
7505 if (phone != null) {
7506 return phone.isImsRegistered();
7507 } else {
7508 return false;
7509 }
7510 }
7511
Santos Cordon7a1885b2015-02-03 11:15:19 -08007512 @Override
7513 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007520 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007521
Tyler Gunnf70ed162019-04-03 15:28:53 -07007522 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007523 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007526 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7528 }
7529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
7537 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007538 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007539 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007541 mApp,
7542 subscriptionId,
7543 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = getPhone(subscriptionId);
7547 if (phone == null) {
7548 return null;
7549 }
7550 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
7555
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007556 /**
7557 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007558 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007559 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 final long identity = Binder.clearCallingIdentity();
7561 try {
7562 Phone phone = getPhone(subId);
7563 if (phone != null) {
7564 return phone.isWifiCallingEnabled();
7565 } else {
7566 return false;
7567 }
7568 } finally {
7569 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007570 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007571 }
7572
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007573 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007574 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007575 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007576 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
7578 try {
7579 Phone phone = getPhone(subId);
7580 if (phone != null) {
7581 return phone.isVideoEnabled();
7582 } else {
7583 return false;
7584 }
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 }
7588 }
7589
7590 /**
7591 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7592 * defined in {@link ImsRegistrationImplBase}.
7593 */
7594 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = getPhone(subId);
7598 if (phone != null) {
7599 return phone.getImsRegistrationTech();
7600 } else {
7601 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7602 }
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007605 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007606 }
7607
Stuart Scott8eef64f2015-04-08 15:13:54 -07007608 @Override
7609 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007610 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007611 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7612 return;
7613 }
Kai Shif70f46f2021-03-03 13:59:46 -08007614 Phone defaultPhone = getDefaultPhone();
7615 if (defaultPhone != null) {
7616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7617 mApp, getDefaultPhone().getSubId(), "factoryReset");
7618 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007619 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620
Svet Ganovcc087f82015-05-12 20:35:54 -07007621 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007622 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7623 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007625 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007626 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007627 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007628 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007630 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007631 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007632 // There has been issues when Sms raw table somehow stores orphan
7633 // fragments. They lead to garbled message when new fragments come
7634 // in and combined with those stale ones. In case this happens again,
7635 // user can reset all network settings which will clean up this table.
7636 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007637 // Clean up IMS settings as well here.
7638 int slotId = getSlotIndex(subId);
7639 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7640 ImsManager.getInstance(mApp, slotId).factoryReset();
7641 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007642
Kai Shif70f46f2021-03-03 13:59:46 -08007643 if (defaultPhone == null) {
7644 return;
7645 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007646 // Erase modem config if erase modem on network setting is enabled.
7647 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7648 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7649 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007650 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007651 }
Kai Shif70f46f2021-03-03 13:59:46 -08007652
7653 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007656 }
7657 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007658
SongFerngWangfd89b102021-05-27 22:44:54 +08007659 @VisibleForTesting
7660 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7661 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7662 return;
7663 }
7664 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7665 RILConstants.PREFERRED_NETWORK_MODE);
7666 SubscriptionManager.setSubscriptionProperty(subId,
7667 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7668 "user=" + defaultNetworkType);
7669 phone.loadAllowedNetworksFromSubscriptionDatabase();
7670 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7671 defaultNetworkType, null);
7672 }
7673
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007674 private void cleanUpSmsRawTable(Context context) {
7675 ContentResolver resolver = context.getContentResolver();
7676 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7677 resolver.delete(uri, null, null);
7678 }
7679
Narayan Kamath1c496c22015-04-16 14:40:19 +01007680 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007681 public String getSimLocaleForSubscriber(int subId) {
7682 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7683 final Phone phone = getPhone(subId);
7684 if (phone == null) {
7685 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007686 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
chen xu5d3637b2019-01-21 23:31:38 -08007690 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007691 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007692 if (info == null) {
7693 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7694 return null;
7695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 // Try and fetch the locale from the carrier properties or from the SIM language
7697 // preferences (EF-PL and EF-LI)...
7698 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007700 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7701 if (localeFromDefaultSim != null) {
7702 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7703 if (DBG) log("Using locale from subId: " + subId + " locale: "
7704 + localeFromDefaultSim);
7705 return localeFromDefaultSim.toLanguageTag();
7706 } else {
7707 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 }
7709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007711 // The SIM language preferences only store a language (e.g. fr = French), not an
7712 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7713 // the SIM and carrier preferences does not include a country we add the country
7714 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007715 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007717 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718 return mccLocale.toLanguageTag();
7719 }
7720
7721 if (DBG) log("No locale found - returning null");
7722 return null;
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007726 }
7727
7728 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007729 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007730 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007731 }
7732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 /**
7734 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7735 */
7736 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007737 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007738 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007739 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007740
Chenjie Yu1ba97252018-01-11 18:16:20 -08007741 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007742 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007743
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007744 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007745 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7746 * representing the state of the modem.
7747 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007748 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7749 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007750 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007751 */
7752 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007753 public void requestModemActivityInfo(ResultReceiver result) {
7754 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007759 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007762 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007763 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007764
Siddharth Rayb8114062018-06-17 15:02:38 -07007765 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7766 // less than total activity duration.
7767 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7768 if (info == null) {
7769 return false;
7770 }
7771 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007772 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7773 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7774
Siddharth Rayb8114062018-06-17 15:02:38 -07007775 return (info.isValid()
7776 && (info.getSleepTimeMillis() <= activityDurationMs)
7777 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007778 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007779 && (totalTxTimeMs <= activityDurationMs));
7780 }
7781
Jack Yu85bd38a2015-11-09 11:34:32 -08007782 /**
7783 * {@hide}
7784 * Returns the service state information on specified subscription.
7785 */
7786 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007787 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7788 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007790 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007791 return null;
7792 }
7793
Hall Liuf19c44f2018-11-27 14:38:17 -08007794 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7795 LocationAccessPolicy.checkLocationPermission(mApp,
7796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7797 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007798 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007799 .setCallingPid(Binder.getCallingPid())
7800 .setCallingUid(Binder.getCallingUid())
7801 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007802 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007803 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007804 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7805 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007806 .build());
7807
7808 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7809 LocationAccessPolicy.checkLocationPermission(mApp,
7810 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7811 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007812 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007813 .setCallingPid(Binder.getCallingPid())
7814 .setCallingUid(Binder.getCallingUid())
7815 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007816 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007817 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007818 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7819 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007820 .build());
7821 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7822 boolean hasFinePermission =
7823 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7824 boolean hasCoarsePermission =
7825 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7826
Jack Yu479f40e2020-10-27 21:29:25 -07007827 final Phone phone = getPhone(subId);
7828 if (phone == null) {
7829 return null;
7830 }
7831
Jordan Liu0f2bc442020-11-18 16:47:37 -08007832 final long identity = Binder.clearCallingIdentity();
7833
Jack Yu479f40e2020-10-27 21:29:25 -07007834 boolean isCallingPackageDataService = phone.getDataServicePackages()
7835 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007837 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7838 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7839 Rlog.d(LOG_TAG,
7840 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7841 return null;
7842 }
7843
Hall Liuf19c44f2018-11-27 14:38:17 -08007844 ServiceState ss = phone.getServiceState();
7845
7846 // Scrub out the location info in ServiceState depending on what level of access
7847 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007848 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007849 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7850 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007854 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007855
7856 /**
7857 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7858 *
7859 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7860 * voicemail ringtone.
7861 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7862 * PhoneAccount.
7863 */
7864 @Override
7865 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7869 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007877 }
7878
7879 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007880 * Sets the per-account voicemail ringtone.
7881 *
7882 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7883 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7884 *
7885 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7886 * voicemail ringtone.
7887 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7888 * PhoneAccount.
7889 */
7890 @Override
7891 public void setVoicemailRingtoneUri(String callingPackage,
7892 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007893 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007895 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7896 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7898 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7899 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
7904 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7905 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007906 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 }
7908 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007911 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007912 }
7913
7914 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007915 * Returns whether vibration is set for voicemail notification in Phone settings.
7916 *
7917 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7918 * voicemail vibration setting.
7919 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7920 */
7921 @Override
7922 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7926 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007927 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007930 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007934 }
7935
Youhan Wange64578a2016-05-02 15:32:42 -07007936 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 * Sets the per-account voicemail vibration.
7938 *
7939 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7940 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7941 *
7942 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7943 * voicemail vibration setting.
7944 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7945 * specific PhoneAccount.
7946 */
7947 @Override
7948 public void setVoicemailVibrationEnabled(String callingPackage,
7949 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007950 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007952 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7953 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7955 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7956 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007957 }
7958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7962 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007963 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 }
7965 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7966 } finally {
7967 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007968 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007969 }
7970
7971 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007972 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7973 *
7974 * @throws SecurityException if the caller does not have the required permission
7975 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007976 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007977 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007978 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007979 }
7980
7981 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007982 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7983 * permission.
7984 *
7985 * @throws SecurityException if the caller does not have the required permission
7986 */
7987 private void enforceSendSmsPermission() {
7988 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7989 }
7990
7991 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007992 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007993 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007994 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007995 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007996 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 if (componentName == null) {
8002 throw new SecurityException(
8003 "Caller not current active visual voicemail package[null]");
8004 }
8005 String vvmPackage = componentName.getPackageName();
8006 if (!callingPackage.equals(vvmPackage)) {
8007 throw new SecurityException("Caller not current active visual voicemail package["
8008 + vvmPackage + "]");
8009 }
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008012 }
8013 }
8014
8015 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008016 * Return the application ID for the app type.
8017 *
8018 * @param subId the subscription ID that this request applies to.
8019 * @param appType the uicc app type.
8020 * @return Application ID for specificied app type, or null if no uicc.
8021 */
8022 @Override
8023 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008024 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008025 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008028 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 if (phone == null) {
8030 return null;
8031 }
8032 String aid = null;
8033 try {
8034 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8035 .getApplicationByType(appType).getAid();
8036 } catch (Exception e) {
8037 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8038 }
8039 return aid;
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008042 }
Youhan Wange64578a2016-05-02 15:32:42 -07008043 }
8044
Youhan Wang4001d252016-05-11 10:29:41 -07008045 /**
8046 * Return the Electronic Serial Number.
8047 *
8048 * @param subId the subscription ID that this request applies to.
8049 * @return ESN or null if error.
8050 */
8051 @Override
8052 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008053 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008054 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055
8056 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008057 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 if (phone == null) {
8059 return null;
8060 }
8061 String esn = null;
8062 try {
8063 esn = phone.getEsn();
8064 } catch (Exception e) {
8065 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8066 }
8067 return esn;
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008070 }
Youhan Wang4001d252016-05-11 10:29:41 -07008071 }
8072
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008073 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008074 * Return the Preferred Roaming List Version.
8075 *
8076 * @param subId the subscription ID that this request applies to.
8077 * @return PRLVersion or null if error.
8078 */
8079 @Override
8080 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008081 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008082 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083
8084 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008085 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008086 if (phone == null) {
8087 return null;
8088 }
8089 String cdmaPrlVersion = null;
8090 try {
8091 cdmaPrlVersion = phone.getCdmaPrlVersion();
8092 } catch (Exception e) {
8093 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8094 }
8095 return cdmaPrlVersion;
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008098 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008099 }
8100
8101 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008102 * Get snapshot of Telephony histograms
8103 * @return List of Telephony histograms
8104 * @hide
8105 */
8106 @Override
8107 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8109 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 return RIL.getTelephonyRILTimingHistograms();
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008117 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008118
8119 /**
8120 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008121 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8122 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008123 * Require system privileges. In the future we may add this to carrier APIs.
8124 *
Michele Berionne482f8202018-11-27 18:57:59 -08008125 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008126 */
8127 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008128 @TelephonyManager.SetCarrierRestrictionResult
8129 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008130 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008131 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008132
Michele Berionne482f8202018-11-27 18:57:59 -08008133 if (carrierRestrictionRules == null) {
8134 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008135 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 final long identity = Binder.clearCallingIdentity();
8138 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008139 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008140 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 } finally {
8142 Binder.restoreCallingIdentity(identity);
8143 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008144 }
8145
8146 /**
8147 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008148 * Get the allowed carrier list and the excluded carrier list, including the priority between
8149 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008150 * Require system privileges. In the future we may add this to carrier APIs.
8151 *
Michele Berionne482f8202018-11-27 18:57:59 -08008152 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008153 */
8154 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008155 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008156 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008157 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158
8159 final long identity = Binder.clearCallingIdentity();
8160 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008161 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8162 if (response instanceof CarrierRestrictionRules) {
8163 return (CarrierRestrictionRules) response;
8164 }
8165 // Response is an Exception of some kind,
8166 // which is signalled to the user as a NULL retval
8167 return null;
8168 } catch (Exception e) {
8169 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8170 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008174 }
8175
fionaxu59545b42016-05-25 15:53:37 -07008176 /**
fionaxu59545b42016-05-25 15:53:37 -07008177 * Action set from carrier signalling broadcast receivers to enable/disable radio
8178 * @param subId the subscription ID that this action applies to.
8179 * @param enabled control enable or disable radio.
8180 * {@hide}
8181 */
8182 @Override
8183 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8184 enforceModifyPermission();
8185 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008188 if (phone == null) {
8189 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8190 return;
8191 }
8192 try {
8193 phone.carrierActionSetRadioEnabled(enabled);
8194 } catch (Exception e) {
8195 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 } finally {
8197 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008198 }
8199 }
8200
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008201 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008202 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8203 * network status based on which carrier apps could apply actions accordingly,
8204 * enable/disable default url handler for example.
8205 *
8206 * @param subId the subscription ID that this action applies to.
8207 * @param report control start/stop reporting the default network status.
8208 * {@hide}
8209 */
8210 @Override
8211 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8212 enforceModifyPermission();
8213 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214
8215 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008216 if (phone == null) {
8217 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8218 return;
8219 }
8220 try {
8221 phone.carrierActionReportDefaultNetworkStatus(report);
8222 } catch (Exception e) {
8223 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 } finally {
8225 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008226 }
8227 }
8228
8229 /**
fionaxud9622282017-07-17 17:51:30 -07008230 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8231 * @param subId the subscription ID that this action applies to.
8232 * {@hide}
8233 */
8234 @Override
8235 public void carrierActionResetAll(int subId) {
8236 enforceModifyPermission();
8237 final Phone phone = getPhone(subId);
8238 if (phone == null) {
8239 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8240 return;
8241 }
8242 try {
8243 phone.carrierActionResetAll();
8244 } catch (Exception e) {
8245 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8246 }
8247 }
8248
8249 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008250 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8251 * bug report is being generated.
8252 */
8253 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008254 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8256 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008257 writer.println("Permission Denial: can't dump Phone from pid="
8258 + Binder.getCallingPid()
8259 + ", uid=" + Binder.getCallingUid()
8260 + "without permission "
8261 + android.Manifest.permission.DUMP);
8262 return;
8263 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008264 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008265 }
Jack Yueb89b242016-06-22 13:27:47 -07008266
Brad Ebingerdac2f002018-04-03 15:17:52 -07008267 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008268 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8269 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8270 @NonNull String[] args) {
8271 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8272 this, in.getFileDescriptor(), out.getFileDescriptor(),
8273 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008274 }
8275
Jack Yueb89b242016-06-22 13:27:47 -07008276 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008277 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008278 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008279 * @param reason the reason the data enable change is taking place
8280 * @param enabled True if enabling the data, otherwise disabling.
8281 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008282 */
8283 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008284 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008285 boolean enabled) {
8286 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8287 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8288 try {
8289 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008290 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008291 } catch (SecurityException se) {
8292 enforceModifyPermission();
8293 }
8294 } else {
8295 enforceModifyPermission();
8296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = getPhone(subId);
8301 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008302 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8303 phone.carrierActionSetMeteredApnsEnabled(enabled);
8304 } else {
8305 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 }
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008310 }
8311 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008312
8313 /**
8314 * Get Client request stats
8315 * @return List of Client Request Stats
8316 * @hide
8317 */
8318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008319 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8320 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008322 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008323 return null;
8324 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008325 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 if (phone != null) {
8330 return phone.getClientRequestStats();
8331 }
8332
8333 return null;
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008337 }
8338
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008339 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008340 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008341 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008342 }
Jack Yueb4124c2017-02-16 15:32:43 -08008343
8344 /**
Grace Chen70990072017-03-24 17:21:30 -07008345 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008346 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008347 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008348 * @param state State of SIM (power down, power up, pass through)
8349 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8350 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8351 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008352 *
8353 **/
8354 @Override
Grace Chen70990072017-03-24 17:21:30 -07008355 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008356 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008357 Phone phone = PhoneFactory.getPhone(slotIndex);
8358
vagdeviaf9a5b92018-08-15 16:01:53 -07008359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008364 phone.setSimPowerState(state, null, workSource);
8365 }
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
8369 }
8370
8371 /**
8372 * Set SIM card power state.
8373 *
8374 * @param slotIndex SIM slot id.
8375 * @param state State of SIM (power down, power up, pass through)
8376 * @param callback callback to trigger after success or failure
8377 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8378 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8379 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8380 *
8381 **/
8382 @Override
8383 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8384 IIntegerConsumer callback) {
8385 enforceModifyPermission();
8386 Phone phone = PhoneFactory.getPhone(slotIndex);
8387
8388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8389
8390 final long identity = Binder.clearCallingIdentity();
8391 try {
8392 if (phone != null) {
8393 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8394 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 }
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008398 }
8399 }
Shuo Qiandd210312017-04-12 22:11:33 +00008400
Tyler Gunn65d45c22017-06-05 11:22:26 -07008401 private boolean isUssdApiAllowed(int subId) {
8402 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008404 if (configManager == null) {
8405 return false;
8406 }
8407 PersistableBundle pb = configManager.getConfigForSubId(subId);
8408 if (pb == null) {
8409 return false;
8410 }
8411 return pb.getBoolean(
8412 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8413 }
8414
Shuo Qiandd210312017-04-12 22:11:33 +00008415 /**
8416 * Check if phone is in emergency callback mode
8417 * @return true if phone is in emergency callback mode
8418 * @param subId sub id
8419 */
goneil9c5f4872017-12-05 14:07:56 -08008420 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008421 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008422 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008423 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424
8425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 if (phone != null) {
8428 return phone.isInEcm();
8429 } else {
8430 return false;
8431 }
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008434 }
8435 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008436
8437 /**
8438 * Get the current signal strength information for the given subscription.
8439 * Because this information is not updated when the device is in a low power state
8440 * it should not be relied-upon to be current.
8441 * @param subId Subscription index
8442 * @return the most recent cached signal strength info from the modem
8443 */
8444 @Override
8445 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone p = getPhone(subId);
8449 if (p == null) {
8450 return null;
8451 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 return p.getSignalStrength();
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008457 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008458
Pengquan Meng77b7f132018-08-22 14:49:57 -07008459 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008460 * Get the current modem radio state for the given slot.
8461 * @param slotIndex slot index.
8462 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008463 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008464 * @return the current radio power state from the modem
8465 */
8466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008467 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008468 Phone phone = PhoneFactory.getPhone(slotIndex);
8469 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8471 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008472 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8473 }
8474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 return phone.getRadioPowerState();
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
8481 }
8482 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8483 }
8484
8485 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008486 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8487 *
8488 * <p>Requires one of the following permissions:
8489 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8490 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8491 * privileges.
8492 *
8493 * @param subId subscription id
8494 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8495 * {@code false}.
8496 */
8497 @Override
8498 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008499 try {
8500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8501 null);
8502 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008503 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008504 mApp, subId, "isDataRoamingEnabled");
8505 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008506
Pengquan Menga1bb6272018-09-06 09:59:22 -07008507 boolean isEnabled = false;
8508 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008509 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008510 Phone phone = getPhone(subId);
8511 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008512 } finally {
8513 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008515 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008516 }
8517
8518
8519 /**
8520 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8521 *
8522 * <p> Requires permission:
8523 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8524 * privileges.
8525 *
8526 * @param subId subscription id
8527 * @param isEnabled {@code true} means enable, {@code false} means disable.
8528 */
8529 @Override
8530 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8532 mApp, subId, "setDataRoamingEnabled");
8533
Pengquan Menga1bb6272018-09-06 09:59:22 -07008534 final long identity = Binder.clearCallingIdentity();
8535 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008536 Phone phone = getPhone(subId);
8537 if (phone != null) {
8538 phone.setDataRoamingEnabled(isEnabled);
8539 }
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008542 }
8543 }
8544
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008545 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008546 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008549 mApp, subId, "isManualNetworkSelectionAllowed");
8550
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008551 boolean isAllowed = true;
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008554 Phone phone = getPhone(subId);
8555 if (phone != null) {
8556 isAllowed = phone.isCspPlmnEnabled();
8557 }
8558 } finally {
8559 Binder.restoreCallingIdentity(identity);
8560 }
8561 return isAllowed;
8562 }
8563
8564 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008565 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008566 // Verify that tha callingPackage belongs to the calling UID
8567 mApp.getSystemService(AppOpsManager.class)
8568 .checkPackage(Binder.getCallingUid(), callingPackage);
8569
Jordan Liu1e142fc2019-04-22 15:10:43 -07008570 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008571 try {
8572 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008573 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008574 } catch (SecurityException e) {
8575 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8576 // has carrier privileges on an active UICC
8577 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8578 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008579 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008580 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008581 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008582
8583 final long identity = Binder.clearCallingIdentity();
8584 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008585 UiccController uiccController = UiccController.getInstance();
8586 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008587 if (hasReadPermission) {
8588 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008589 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008590
8591 // Remove private info if the caller doesn't have access
8592 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8593 for (UiccCardInfo cardInfo : cardInfos) {
8594 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8595 // is available
8596 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8597 if (card == null || card.getUiccProfile() == null) {
8598 // assume no access if the card or profile is unavailable
8599 filteredInfos.add(cardInfo.getUnprivileged());
8600 continue;
8601 }
8602 UiccProfile profile = card.getUiccProfile();
8603 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8604 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8605 filteredInfos.add(cardInfo);
8606 } else {
8607 filteredInfos.add(cardInfo.getUnprivileged());
8608 }
8609 }
8610 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
8615
8616 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008617 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008618 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8623 if (slots == null) {
8624 Rlog.i(LOG_TAG, "slots is null.");
8625 return null;
8626 }
8627
8628 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8629 for (int i = 0; i < slots.length; i++) {
8630 UiccSlot slot = slots[i];
8631 if (slot == null) {
8632 continue;
8633 }
8634
Jordan Liu7be7e652019-05-06 18:55:02 +00008635 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 UiccCard card = slot.getUiccCard();
8637 if (card != null) {
8638 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008639 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008640 cardId = slot.getEid();
8641 if (TextUtils.isEmpty(cardId)) {
8642 cardId = slot.getIccId();
8643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 }
8645
Jordan Liu857451f2019-05-09 16:35:35 -07008646 if (cardId != null) {
8647 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8648 // if cardId is an EID, it's all digits so this is fine
8649 cardId = IccUtils.stripTrailingFs(cardId);
8650 }
8651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008652 int cardState = 0;
8653 switch (slot.getCardState()) {
8654 case CARDSTATE_ABSENT:
8655 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8656 break;
8657 case CARDSTATE_PRESENT:
8658 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8659 break;
8660 case CARDSTATE_ERROR:
8661 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8662 break;
8663 case CARDSTATE_RESTRICTED:
8664 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8665 break;
8666 default:
8667 break;
8668
8669 }
8670
8671 infos[i] = new UiccSlotInfo(
8672 slot.isActive(),
8673 slot.isEuicc(),
8674 cardId,
8675 cardState,
8676 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008677 slot.isExtendedApduSupported(),
8678 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008679 }
8680 return infos;
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008683 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008684 }
8685
8686 @Override
8687 public boolean switchSlots(int[] physicalSlots) {
8688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
8692 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
8695 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008696 }
Jack Yu4c988042018-02-27 15:30:01 -08008697
8698 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008699 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008700 final long identity = Binder.clearCallingIdentity();
8701 try {
8702 return UiccController.getInstance().getCardIdForDefaultEuicc();
8703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
Pengquan Meng85728fb2018-03-12 16:31:21 -07008708 /**
goneil47ffb6e2018-04-06 15:40:58 -07008709 * A test API to reload the UICC profile.
8710 *
8711 * <p>Requires that the calling app has permission
8712 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8713 * @hide
8714 */
8715 @Override
8716 public void refreshUiccProfile(int subId) {
8717 enforceModifyPermission();
8718
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 Phone phone = getPhone(subId);
8722 if (phone == null) {
8723 return;
8724 }
8725 UiccCard uiccCard = phone.getUiccCard();
8726 if (uiccCard == null) {
8727 return;
8728 }
8729 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8730 if (uiccProfile == null) {
8731 return;
8732 }
8733 uiccProfile.refresh();
8734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 }
8738
8739 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008740 * Returns false if the mobile data is disabled by default, otherwise return true.
8741 */
8742 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008743 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008744 }
8745
8746 /**
8747 * Returns true if the data roaming is enabled by default, i.e the system property
8748 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8749 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8750 */
8751 private boolean getDefaultDataRoamingEnabled(int subId) {
8752 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008753 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008754 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008755 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8756 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8757 return isDataRoamingEnabled;
8758 }
8759
8760 /**
8761 * Returns the default network type for the given {@code subId}, if the default network type is
8762 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8763 */
8764 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008765 List<Integer> list = TelephonyProperties.default_network();
8766 int phoneId = mSubscriptionController.getPhoneId(subId);
8767 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8768 return list.get(phoneId);
8769 }
8770 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008771 }
fionaxua13278b2018-03-21 00:08:13 -07008772
8773 @Override
8774 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008775 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 final Phone phone = getPhone(subId);
8781 if (phone == null) {
8782 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8783 return;
8784 }
chen xueaba88a2019-03-15 13:15:10 -07008785 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8786 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008787 if (carrierPrivilegeRules == null) {
8788 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8789 } else {
8790 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008792 } finally {
8793 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008794 }
fionaxua13278b2018-03-21 00:08:13 -07008795 }
8796
8797 @Override
8798 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008799 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008800
8801 final long identity = Binder.clearCallingIdentity();
8802 try {
8803 final Phone phone = getPhone(subId);
8804 if (phone == null) {
8805 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8806 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8807 }
8808 return phone.getCarrierIdListVersion();
8809 } finally {
8810 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008811 }
fionaxua13278b2018-03-21 00:08:13 -07008812 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008813
8814 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008815 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8816 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008818 mApp, subId, callingPackage, callingFeatureId,
8819 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008820 return -1;
8821 }
8822
8823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8826 } finally {
8827 Binder.restoreCallingIdentity(identity);
8828 }
8829 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008830
8831 @Override
8832 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008833 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008834 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008835 mApp, subId, "getCdmaRoamingMode");
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
8844
8845 @Override
8846 public boolean setCdmaRoamingMode(int subId, int mode) {
8847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8848 mApp, subId, "setCdmaRoamingMode");
8849
8850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8853 } finally {
8854 Binder.restoreCallingIdentity(identity);
8855 }
8856 }
8857
8858 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008859 public int getCdmaSubscriptionMode(int subId) {
8860 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008861 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008862 mApp, subId, "getCdmaSubscriptionMode");
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
8869 }
8870 }
8871
8872 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008873 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8875 mApp, subId, "setCdmaSubscriptionMode");
8876
8877 final long identity = Binder.clearCallingIdentity();
8878 try {
8879 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
8883 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008884
sqianc5eccab2018-10-19 18:46:41 -07008885 @Override
sqian8c685422019-02-22 15:55:18 -08008886 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008887 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008889 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8890 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008891 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8892 }
8893 final long identity = Binder.clearCallingIdentity();
8894 try {
sqian854d44b2018-12-12 16:48:18 -08008895 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8896 for (Phone phone: PhoneFactory.getPhones()) {
8897 if (phone.getEmergencyNumberTracker() != null
8898 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8899 emergencyNumberListInternal.put(
8900 phone.getSubId(),
8901 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8902 }
sqian11b7a0e2018-12-05 18:48:28 -08008903 }
sqian854d44b2018-12-12 16:48:18 -08008904 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
sqianc5eccab2018-10-19 18:46:41 -07008908 }
8909
8910 @Override
sqian8c685422019-02-22 15:55:18 -08008911 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008912 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008913 if (!exactMatch) {
8914 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008915 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008916 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008917 }
8918 final long identity = Binder.clearCallingIdentity();
8919 try {
sqian854d44b2018-12-12 16:48:18 -08008920 for (Phone phone: PhoneFactory.getPhones()) {
8921 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008922 && phone.getEmergencyNumberTracker()
8923 .isEmergencyNumber(number, exactMatch)) {
8924 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008925 }
sqian11b7a0e2018-12-05 18:48:28 -08008926 }
8927 return false;
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
sqianf4ca7ed2019-01-15 18:32:07 -08008933 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008934 * Start emergency callback mode for GsmCdmaPhone for testing.
8935 */
8936 @Override
8937 public void startEmergencyCallbackMode() {
8938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8939 "startEmergencyCallbackMode");
8940 enforceModifyPermission();
8941 final long identity = Binder.clearCallingIdentity();
8942 try {
8943 for (Phone phone : PhoneFactory.getPhones()) {
8944 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8945 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8946 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8947 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8948 gsmCdmaPhone.obtainMessage(
8949 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8950 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8951 }
8952 }
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
8957
8958 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008959 * Update emergency number list for test mode.
8960 */
8961 @Override
8962 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8964 "updateEmergencyNumberListTestMode");
8965
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 for (Phone phone: PhoneFactory.getPhones()) {
8969 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8970 if (tracker != null) {
8971 tracker.executeEmergencyNumberTestModeCommand(action, num);
8972 }
8973 }
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
8978
8979 /**
8980 * Get the full emergency number list for test mode.
8981 */
8982 @Override
8983 public List<String> getEmergencyNumberListTestMode() {
8984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8985 "getEmergencyNumberListTestMode");
8986
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 Set<String> emergencyNumbers = new HashSet<>();
8990 for (Phone phone: PhoneFactory.getPhones()) {
8991 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8992 if (tracker != null) {
8993 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8994 emergencyNumbers.add(num.getNumber());
8995 }
8996 }
8997 }
8998 return new ArrayList<>(emergencyNumbers);
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
chen xud6b45bd2018-10-30 22:27:10 -07009004 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009005 public int getEmergencyNumberDbVersion(int subId) {
9006 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 final Phone phone = getPhone(subId);
9011 if (phone == null) {
9012 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9013 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9014 }
9015 return phone.getEmergencyNumberDbVersion();
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
9021 @Override
9022 public void notifyOtaEmergencyNumberDbInstalled() {
9023 enforceModifyPermission();
9024
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 for (Phone phone: PhoneFactory.getPhones()) {
9028 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9029 if (tracker != null) {
9030 tracker.updateOtaEmergencyNumberDatabase();
9031 }
9032 }
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
9036 }
9037
9038 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009039 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009040 enforceActiveEmergencySessionPermission();
9041
9042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 for (Phone phone: PhoneFactory.getPhones()) {
9045 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9046 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009047 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9048 }
9049 }
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
9055 @Override
9056 public void resetOtaEmergencyNumberDbFilePath() {
9057 enforceActiveEmergencySessionPermission();
9058
9059 final long identity = Binder.clearCallingIdentity();
9060 try {
9061 for (Phone phone: PhoneFactory.getPhones()) {
9062 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9063 if (tracker != null) {
9064 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009065 }
9066 }
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
9072 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009073 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9074 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9075 Phone phone = getPhone(subId);
9076 if (phone == null) {
9077 return null;
9078 }
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 UiccProfile profile = UiccController.getInstance()
9082 .getUiccProfileForPhone(phone.getPhoneId());
9083 if (profile != null) {
9084 return profile.getCertsFromCarrierPrivilegeAccessRules();
9085 }
9086 } finally {
9087 Binder.restoreCallingIdentity(identity);
9088 }
9089 return null;
9090 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009091
9092 /**
9093 * Enable or disable a modem stack.
9094 */
9095 @Override
9096 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9097 enforceModifyPermission();
9098
9099 final long identity = Binder.clearCallingIdentity();
9100 try {
9101 Phone phone = PhoneFactory.getPhone(slotIndex);
9102 if (phone == null) {
9103 return false;
9104 } else {
9105 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9106 }
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 }
Michelecea4cf22018-12-21 15:00:11 -08009111
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009112 /**
9113 * Whether a modem stack is enabled or not.
9114 */
9115 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009116 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9117 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009118 Phone phone = PhoneFactory.getPhone(slotIndex);
9119 if (phone == null) return false;
9120
9121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009122 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9123 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009124 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9125 }
9126
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009129 try {
9130 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9131 } catch (NoSuchElementException ex) {
9132 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9133 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009134 } finally {
9135 Binder.restoreCallingIdentity(identity);
9136 }
9137 }
9138
Michelecea4cf22018-12-21 15:00:11 -08009139 @Override
Michele0ea7d782019-03-19 14:58:42 -07009140 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009141 enforceModifyPermission();
9142
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009146 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009147 .commit();
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
9153 @Override
Michele0ea7d782019-03-19 14:58:42 -07009154 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009155 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009157 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9158 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009159 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009160 }
Michelecea4cf22018-12-21 15:00:11 -08009161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
Michele0ea7d782019-03-19 14:58:42 -07009164 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009169
Michele0ea7d782019-03-19 14:58:42 -07009170 @TelephonyManager.IsMultiSimSupportedResult
9171 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009172 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9173 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9174 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009175 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9176 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009177 }
9178 // Check if the hardware supports multisim functionality. If usage of multisim is not
9179 // supported by the modem, indicate that it is restricted.
9180 PhoneCapability staticCapability =
9181 mPhoneConfigurationManager.getStaticPhoneCapability();
9182 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009183 loge("isMultiSimSupportedInternal: no static configuration available");
9184 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009185 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009186 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009187 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9188 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009189 }
9190 // Check if support of multiple SIMs is restricted by carrier
9191 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009192 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009193 }
9194
Michele0ea7d782019-03-19 14:58:42 -07009195 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009196 }
9197
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009198 /**
9199 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009200 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9201 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9202 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009203 * @param numOfSims number of active sims we want to switch to
9204 */
9205 @Override
9206 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009207 if (numOfSims == 1) {
9208 enforceModifyPermission();
9209 } else {
9210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9211 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9212 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009213 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009214
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009215 try {
Michele30b57b22019-03-01 12:01:14 -08009216 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009217 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009218 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9219 return;
9220 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009221 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
9226
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009227 @Override
9228 public boolean isApplicationOnUicc(int subId, int appType) {
9229 enforceReadPrivilegedPermission("isApplicationOnUicc");
9230 Phone phone = getPhone(subId);
9231 if (phone == null) {
9232 return false;
9233 }
9234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 UiccCard uiccCard = phone.getUiccCard();
9237 if (uiccCard == null) {
9238 return false;
9239 }
9240 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9241 if (uiccProfile == null) {
9242 return false;
9243 }
9244 if (TelephonyManager.APPTYPE_SIM <= appType
9245 && appType <= TelephonyManager.APPTYPE_ISIM) {
9246 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9247 }
9248 return false;
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
9253
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009254 /**
chen xub4baa772019-04-03 10:23:41 -07009255 * Get whether making changes to modem configurations will trigger reboot.
9256 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009257 */
9258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009259 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9260 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009262 mApp, subId, callingPackage, callingFeatureId,
9263 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009264 return false;
9265 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009266 final long identity = Binder.clearCallingIdentity();
9267 try {
9268 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9269 } finally {
9270 Binder.restoreCallingIdentity(identity);
9271 }
9272 }
9273
Nathan Harold29f5f052019-02-15 13:41:57 -08009274 private void updateModemStateMetrics() {
9275 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9276 // TODO: check the state for each modem if the api is ready.
9277 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9278 }
9279
Pengquan Meng3889a572019-01-23 11:16:29 -08009280 @Override
9281 public int[] getSlotsMapping() {
9282 enforceReadPrivilegedPermission("getSlotsMapping");
9283
9284 final long identity = Binder.clearCallingIdentity();
9285 try {
9286 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9287 // All logical slots should have a mapping to a physical slot.
9288 int[] logicalSlotsMapping = new int[phoneCount];
9289 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9290 for (int i = 0; i < slotInfos.length; i++) {
9291 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9292 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9293 }
9294 }
9295 return logicalSlotsMapping;
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009300
9301 /**
9302 * Get the IRadio HAL Version
9303 */
9304 @Override
9305 public int getRadioHalVersion() {
9306 Phone phone = getDefaultPhone();
9307 if (phone == null) return -1;
9308 HalVersion hv = phone.getHalVersion();
9309 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9310 return hv.major * 100 + hv.minor;
9311 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009312
9313 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009314 * Get the current calling package name.
9315 * @return the current calling package name
9316 */
9317 @Override
9318 public String getCurrentPackageName() {
9319 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9320 }
9321
9322 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009323 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9324 * corresponding network requests on a subId.
9325 *
9326 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009327 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009328 * 2) APN is un-metered for this subscription, or
9329 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009330 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009331 *
9332 * @return whether data is allowed for a apn type.
9333 *
9334 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009335 */
9336 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009337 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009338 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9339 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009340
9341 // Now that all security checks passes, perform the operation as ourselves.
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 Phone phone = getPhone(subId);
9345 if (phone == null) return false;
9346
Jack Yu41407ee2019-05-13 16:54:09 -07009347 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009348 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 }
9353
9354 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009355 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009356 enforceReadPrivilegedPermission("isApnMetered");
9357
9358 // Now that all security checks passes, perform the operation as ourselves.
9359 final long identity = Binder.clearCallingIdentity();
9360 try {
9361 Phone phone = getPhone(subId);
9362 if (phone == null) return true; // By default return true.
9363
Jack Yu41407ee2019-05-13 16:54:09 -07009364 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009369
9370 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009371 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9372 int subscriptionId, IBooleanConsumer resultCallback) {
9373 enforceModifyPermission();
9374 long token = Binder.clearCallingIdentity();
9375 try {
9376 Phone phone = getPhone(subscriptionId);
9377 if (phone == null) {
9378 try {
9379 if (resultCallback != null) {
9380 resultCallback.accept(false);
9381 }
9382 } catch (RemoteException e) {
9383 // ignore
9384 }
9385 return;
9386 }
9387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9388 Pair.create(specifiers, (x) -> {
9389 try {
9390 if (resultCallback != null) {
9391 resultCallback.accept(x);
9392 }
9393 } catch (RemoteException e) {
9394 // ignore
9395 }
9396 });
9397 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9398 } finally {
9399 Binder.restoreCallingIdentity(token);
9400 }
9401 }
9402
9403 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009404 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9405 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009406 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009407 mApp, subId, "getSystemSelectionChannels");
9408 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009411 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9412 if (result instanceof IllegalStateException) {
9413 throw (IllegalStateException) result;
9414 }
9415 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009416 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9417 return specifiers;
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009424 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009425 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009426 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9427 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9428 if (iccRecords == null) {
9429 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9430 return false;
9431 }
9432 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9433 }
9434
9435 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009436 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9437 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009438 if (callingPackage == null) {
9439 callingPackage = getCurrentPackageName();
9440 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009441 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9442 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009443 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9444 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009445 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9446 }
9447 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9448 Intent intent = new Intent();
9449 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9450 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9451 // Bring up choose default SMS subscription dialog right now
9452 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9453 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9454 mApp.startActivity(intent);
9455 }
chen xud5ca2d52019-05-28 15:20:57 -07009456
9457 @Override
9458 public String getMmsUAProfUrl(int subId) {
9459 //TODO investigate if this API should require proper permission check in R b/133791609
9460 final long identity = Binder.clearCallingIdentity();
9461 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009462 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9463 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9464 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9465 return carrierUAProfUrl;
9466 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009467 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9468 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
9474 @Override
9475 public String getMmsUserAgent(int subId) {
9476 //TODO investigate if this API should require proper permission check in R b/133791609
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009479 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9480 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9481 if (!TextUtils.isEmpty(carrierUserAgent)) {
9482 return carrierUserAgent;
9483 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009484 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9485 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009486 } finally {
9487 Binder.restoreCallingIdentity(identity);
9488 }
9489 }
Jack Yub07d4972019-05-28 16:12:25 -07009490
9491 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009492 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9493 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009494
Jack Yub07d4972019-05-28 16:12:25 -07009495 final long identity = Binder.clearCallingIdentity();
9496 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009497 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009498 if (phone == null) return false;
9499
Hall Liua62f5da2020-09-25 10:42:19 -07009500 switch (policy) {
9501 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9502 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9503 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9504 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9505 default:
9506 throw new IllegalArgumentException(policy + " is not a valid policy");
9507 }
Jack Yub07d4972019-05-28 16:12:25 -07009508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009514 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009515 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009516 enforceModifyPermission();
9517
changbettyd5c246e2019-12-24 15:40:37 +08009518 final long identity = Binder.clearCallingIdentity();
9519 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009520 Phone phone = getPhone(subscriptionId);
9521 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009522
Hall Liua62f5da2020-09-25 10:42:19 -07009523 switch (policy) {
9524 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9525 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9526 break;
9527 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9528 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9529 break;
9530 default:
9531 throw new IllegalArgumentException(policy + " is not a valid policy");
9532 }
changbettyd5c246e2019-12-24 15:40:37 +08009533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009538 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009539 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009540 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9541 * otherwise.
9542 */
9543 @Override
9544 public void setCepEnabled(boolean isCepEnabled) {
9545 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9550 for (Phone phone : PhoneFactory.getPhones()) {
9551 Phone defaultPhone = phone.getImsPhone();
9552 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9553 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9554 ImsPhoneCallTracker imsPhoneCallTracker =
9555 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9556 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9557 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9558 + imsPhone.getMsisdn());
9559 }
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
allenwtsu46dcc572020-01-08 18:24:03 +08009565
9566 /**
9567 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9568 *
9569 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9570 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9571 * before being read.
9572 */
9573 @Override
9574 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9575 isCompressed) {
9576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9577 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009578 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9579 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9580 }
9581 if (!isImsAvailableOnDevice()) {
9582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9583 "IMS not available on device.");
9584 }
9585
9586 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009587 try {
Hui Wang761a6682020-10-31 05:12:53 +00009588 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9589 } finally {
9590 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009591 }
9592 }
zoey chene02881a2019-12-30 16:11:23 +08009593
9594 @Override
9595 public boolean isIccLockEnabled(int subId) {
9596 enforceReadPrivilegedPermission("isIccLockEnabled");
9597
9598 // Now that all security checks passes, perform the operation as ourselves.
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
9601 Phone phone = getPhone(subId);
9602 if (phone != null && phone.getIccCard() != null) {
9603 return phone.getIccCard().getIccLockEnabled();
9604 } else {
9605 return false;
9606 }
9607 } finally {
9608 Binder.restoreCallingIdentity(identity);
9609 }
9610 }
9611
9612 /**
9613 * Set the ICC pin lock enabled or disabled.
9614 *
9615 * @return an integer representing the status of IccLock enabled or disabled in the following
9616 * three cases:
9617 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9618 * successfully.
9619 * - Positive number and zero for remaining password attempts.
9620 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9621 *
9622 */
9623 @Override
9624 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9625 enforceModifyPermission();
9626
9627 Phone phone = getPhone(subId);
9628 if (phone == null) {
9629 return 0;
9630 }
9631 // Now that all security checks passes, perform the operation as ourselves.
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9635 new Pair<Boolean, String>(enabled, password), phone, null);
9636 return attemptsRemaining;
9637
9638 } catch (Exception e) {
9639 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 return 0;
9644 }
9645
9646 /**
9647 * Change the ICC password used in ICC pin lock.
9648 *
9649 * @return an integer representing the status of IccLock changed in the following three cases:
9650 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9651 * - Positive number and zero for remaining password attempts.
9652 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9653 *
9654 */
9655 @Override
9656 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9657 enforceModifyPermission();
9658
9659 Phone phone = getPhone(subId);
9660 if (phone == null) {
9661 return 0;
9662 }
9663 // Now that all security checks passes, perform the operation as ourselves.
9664 final long identity = Binder.clearCallingIdentity();
9665 try {
9666 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9667 new Pair<String, String>(oldPassword, newPassword), phone, null);
9668 return attemptsRemaining;
9669
9670 } catch (Exception e) {
9671 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 return 0;
9676 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009677
9678 /**
9679 * Request for receiving user activity notification
9680 */
9681 @Override
9682 public void requestUserActivityNotification() {
9683 if (!mNotifyUserActivity.get()
9684 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9685 mNotifyUserActivity.set(true);
9686 }
9687 }
9688
9689 /**
9690 * Called when userActivity is signalled in the power manager.
9691 * This is safe to call from any thread, with any window manager locks held or not.
9692 */
9693 @Override
9694 public void userActivity() {
9695 // ***************************************
9696 // * Inherited from PhoneWindowManager *
9697 // ***************************************
9698 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9699 // WITH ITS LOCKS HELD.
9700 //
9701 // This code must be VERY careful about the locks
9702 // it acquires.
9703 // In fact, the current code acquires way too many,
9704 // and probably has lurking deadlocks.
9705
9706 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9707 throw new SecurityException("Only the OS may call notifyUserActivity()");
9708 }
9709
9710 if (mNotifyUserActivity.getAndSet(false)) {
9711 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9712 USER_ACTIVITY_NOTIFICATION_DELAY);
9713 }
9714 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009715
9716 @Override
9717 public boolean canConnectTo5GInDsdsMode() {
9718 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9719 }
Jack Yud10cdd42020-09-28 20:28:01 -07009720
9721 @Override
9722 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9723 String callingFeatureId) {
9724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9725 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9726 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9727 }
9728
9729 Phone phone = getPhone(subId);
9730 if (phone == null) {
9731 throw new RuntimeException("phone is not available");
9732 }
9733 // Now that all security checks passes, perform the operation as ourselves.
9734 final long identity = Binder.clearCallingIdentity();
9735 try {
9736 return phone.getEquivalentHomePlmns();
9737 } finally {
9738 Binder.restoreCallingIdentity(identity);
9739 }
9740 }
Daniel Bright59e67312020-11-13 11:49:37 -08009741
9742 @Override
9743 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009744 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9745 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009746 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009747 if (radioInterfaceCapabilities == null) {
9748 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009749 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009750 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009751 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009752
Hui Wang641e81c2020-10-12 12:14:23 -07009753 @Override
9754 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9755 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009756 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9757 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9758 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9759 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9760 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009761 if (DBG) {
9762 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9763 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9764 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9765 }
9766
9767 if (!SubscriptionManager.isValidSubscriptionId(subId)
9768 || appType < TelephonyManager.APPTYPE_UNKNOWN
9769 || appType > TelephonyManager.APPTYPE_ISIM
9770 || nafUrl == null || securityProtocol == null || callback == null) {
9771 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9772 if (callback != null) {
9773 try {
9774 callback.onAuthenticationFailure(
9775 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9776 } catch (RemoteException exception) {
9777 log("Fail to notify onAuthenticationFailure due to " + exception);
9778 }
9779 return;
9780 }
9781 }
9782
9783 final long token = Binder.clearCallingIdentity();
9784 try {
9785 getGbaManager(subId).bootstrapAuthenticationRequest(
9786 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9787 forceBootStrapping, callback));
9788 } finally {
9789 Binder.restoreCallingIdentity(token);
9790 }
9791 }
9792
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009793 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009794 * Attempts to set the radio power state for all phones for thermal reason.
9795 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009796 * requested radio power state will actually be set. See {@link
9797 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9798 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009799 * @param enable {@code true} if trying to turn radio on.
9800 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9801 * false}.
9802 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009803 private boolean setRadioPowerForThermal(boolean enable) {
9804 boolean isPhoneAvailable = false;
9805 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9806 Phone phone = PhoneFactory.getPhone(i);
9807 if (phone != null) {
9808 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9809 isPhoneAvailable = true;
9810 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009811 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009812
9813 // return true if successfully informed the phone object about the thermal radio power
9814 // request.
9815 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009816 }
9817
9818 private int handleDataThrottlingRequest(int subId,
9819 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009820 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9821 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9822 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9823 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9824 throw new IllegalArgumentException("modem does not support data throttling");
9825 }
9826
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009827 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9828 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009829 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009830 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9831 }
9832
9833 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9834
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009835 if (isDataThrottlingSupported) {
9836 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009837 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009838 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9839 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9840 } else if (thermalMitigationResult
9841 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009842 log("Modem likely does not support data throttling on secondary carrier. Data " +
9843 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9844 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009845 }
9846 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009847 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009848
9849 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009850 }
9851
Jack Nudelman644b91a2021-03-12 14:09:48 -08009852 private static List<String> getThermalMitigationAllowlist(Context context) {
9853 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9854 for (String pckg : context.getResources()
9855 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9856 sThermalMitigationAllowlistedPackages.add(pckg);
9857 }
9858 }
9859
9860 return sThermalMitigationAllowlistedPackages;
9861 }
9862
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009863 private boolean isAnyPhoneInEmergencyState() {
9864 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9865 if (tm.isInEmergencyCall()) {
9866 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9867 return true;
9868 }
9869 for (Phone phone : PhoneFactory.getPhones()) {
9870 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9871 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9872 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9873 + phone.isInEcm());
9874 return true;
9875 }
9876 }
9877
9878 return false;
9879 }
9880
Jack Nudelman644b91a2021-03-12 14:09:48 -08009881 /**
9882 * Used by shell commands to add an authorized package name for thermal mitigation.
9883 * @param packageName name of package to be allowlisted
9884 * @param context
9885 */
9886 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9887 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9888 sThermalMitigationAllowlistedPackages.add(packageName);
9889 }
9890
9891 /**
9892 * Used by shell commands to remove an authorized package name for thermal mitigation.
9893 * @param packageName name of package to remove from allowlist
9894 * @param context
9895 */
9896 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9897 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9898 sThermalMitigationAllowlistedPackages.remove(packageName);
9899 }
9900
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009901 /**
9902 * Thermal mitigation request to control functionalities at modem.
9903 *
9904 * @param subId the id of the subscription.
9905 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009906 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009907 *
9908 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9909 */
9910 @Override
9911 @ThermalMitigationResult
9912 public int sendThermalMitigationRequest(
9913 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009914 ThermalMitigationRequest thermalMitigationRequest,
9915 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009916 enforceModifyPermission();
9917
Jack Nudelman644b91a2021-03-12 14:09:48 -08009918 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9919 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9920 .contains(callingPackage)) {
9921 throw new SecurityException("Calling package must be configured in the device config. "
9922 + "calling package: " + callingPackage);
9923 }
9924
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9926 final long identity = Binder.clearCallingIdentity();
9927
9928 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9929 try {
9930 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9931 switch (thermalMitigationAction) {
9932 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9933 thermalMitigationResult =
9934 handleDataThrottlingRequest(subId,
9935 thermalMitigationRequest.getDataThrottlingRequest());
9936 break;
9937 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9938 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9939 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9940 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9941 }
9942
9943 // Ensure that radio is on. If not able to power on due to phone being
9944 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009945 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009946 thermalMitigationResult =
9947 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9948 break;
9949 }
9950
9951 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9952 false);
9953 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9954 break;
9955 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9956 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9957 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9958 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9959 }
9960
9961 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9962 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009963 Phone phone = getPhone(subId);
9964 if (phone == null) {
9965 thermalMitigationResult =
9966 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9967 break;
9968 }
9969
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009970 TelephonyConnectionService service =
9971 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009972 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009973 Log.e(LOG_TAG, "An emergency call is pending");
9974 thermalMitigationResult =
9975 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9976 break;
9977 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009978 thermalMitigationResult =
9979 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9980 break;
9981 }
9982 } else {
9983 thermalMitigationResult =
9984 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9985 break;
9986 }
9987
9988 // Turn radio off. If not able to power off due to phone being unavailable,
9989 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009990 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 thermalMitigationResult =
9992 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9993 break;
9994 }
9995 thermalMitigationResult =
9996 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9997 break;
9998 default:
9999 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10000 + "not exist. Requested action: " + thermalMitigationAction);
10001 }
10002 } catch (IllegalArgumentException e) {
10003 throw e;
10004 } catch (Exception e) {
10005 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10006 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10007 } finally {
10008 Binder.restoreCallingIdentity(identity);
10009 }
10010
10011 if (DBG) {
10012 log("thermalMitigationRequest returning with thermalMitigationResult: "
10013 + thermalMitigationResult);
10014 }
10015
10016 return thermalMitigationResult;
10017 }
Hui Wang641e81c2020-10-12 12:14:23 -070010018
10019 /**
10020 * Set the GbaService Package Name that Telephony will bind to.
10021 *
10022 * @param subId The sim that the GbaService is associated with.
10023 * @param packageName The name of the package to be replaced with.
10024 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10025 */
10026 @Override
10027 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10028 enforceModifyPermission();
10029
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 return getGbaManager(subId).overrideServicePackage(packageName);
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 /**
10039 * Return the package name of the currently bound GbaService.
10040 *
10041 * @param subId The sim that the GbaService is associated with.
10042 * @return the package name of the GbaService configuration, null if GBA is not supported.
10043 */
10044 @Override
10045 public String getBoundGbaService(int subId) {
10046 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10047
10048 final long identity = Binder.clearCallingIdentity();
10049 try {
10050 return getGbaManager(subId).getServicePackage();
10051 } finally {
10052 Binder.restoreCallingIdentity(identity);
10053 }
10054 }
10055
10056 /**
10057 * Set the release time for telephony to unbind GbaService.
10058 *
10059 * @param subId The sim that the GbaService is associated with.
10060 * @param interval The release time to unbind GbaService by millisecond.
10061 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10062 */
10063 @Override
10064 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10065 enforceModifyPermission();
10066
10067 final long identity = Binder.clearCallingIdentity();
10068 try {
10069 return getGbaManager(subId).overrideReleaseTime(interval);
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
10072 }
10073 }
10074
10075 /**
10076 * Return the release time for telephony to unbind GbaService.
10077 *
10078 * @param subId The sim that the GbaService is associated with.
10079 * @return The release time to unbind GbaService by millisecond.
10080 */
10081 @Override
10082 public int getGbaReleaseTime(int subId) {
10083 enforceReadPrivilegedPermission("getGbaReleaseTime");
10084
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 return getGbaManager(subId).getReleaseTime();
10088 } finally {
10089 Binder.restoreCallingIdentity(identity);
10090 }
10091 }
10092
10093 private GbaManager getGbaManager(int subId) {
10094 GbaManager instance = GbaManager.getInstance(subId);
10095 if (instance == null) {
10096 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10097 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10098 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10099 }
10100 return instance;
10101 }
Hui Wang761a6682020-10-31 05:12:53 +000010102
10103 /**
10104 * indicate whether the device and the carrier can support
10105 * RCS VoLTE single registration.
10106 */
10107 @Override
10108 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010109 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10110 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10111 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10112 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010113
10114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10116 }
10117
10118 final long identity = Binder.clearCallingIdentity();
10119 try {
10120 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10121 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010122 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10123 if (isCapable != null) {
10124 return isCapable;
10125 }
Hui Wang761a6682020-10-31 05:12:53 +000010126 }
Hui Wang67af90e2021-06-04 16:57:15 -070010127 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10128 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010129 } finally {
10130 Binder.restoreCallingIdentity(identity);
10131 }
10132 }
10133
10134 /**
10135 * Register RCS provisioning callback.
10136 */
10137 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010138 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010139 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010140 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010141 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010142 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10143 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010144
10145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10146 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10147 }
10148 if (!isImsAvailableOnDevice()) {
10149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10150 "IMS not available on device.");
10151 }
10152
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010155 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010156 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010157 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10158 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010159 }
Hui Wang761a6682020-10-31 05:12:53 +000010160 } finally {
10161 Binder.restoreCallingIdentity(identity);
10162 }
10163 }
10164
10165 /**
10166 * Unregister RCS provisioning callback.
10167 */
10168 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010169 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010170 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010171 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010172 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010173 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10174 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010175
10176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10178 }
10179 if (!isImsAvailableOnDevice()) {
10180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10181 "IMS not available on device.");
10182 }
10183
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010186 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010187 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
10193 /**
10194 * trigger RCS reconfiguration.
10195 */
10196 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010197 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10198 "triggerRcsReconfiguration",
10199 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010200
10201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10202 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10203 }
10204 if (!isImsAvailableOnDevice()) {
10205 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10206 "IMS not available on device.");
10207 }
10208
10209 final long identity = Binder.clearCallingIdentity();
10210 try {
10211 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10212 } finally {
10213 Binder.restoreCallingIdentity(identity);
10214 }
10215 }
10216
10217 /**
10218 * Provide the client configuration parameters of the RCS application.
10219 */
10220 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010221 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10222 "setRcsClientConfiguration",
10223 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010224
10225 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10226 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10227 }
10228 if (!isImsAvailableOnDevice()) {
10229 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10230 "IMS not available on device.");
10231 }
10232
10233 final long identity = Binder.clearCallingIdentity();
10234
10235 try {
10236 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10237 if (configBinder == null) {
10238 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010239 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10240 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010241 } else {
10242 configBinder.setRcsClientConfiguration(rcc);
10243 }
10244 } catch (RemoteException e) {
10245 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010246 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10247 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010248 } finally {
10249 Binder.restoreCallingIdentity(identity);
10250 }
10251 }
10252
10253 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010254 * Enables or disables the test mode for RCS VoLTE single registration.
10255 */
10256 @Override
10257 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10258 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10259 "setRcsSingleRegistrationTestModeEnabled");
10260
10261 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10262 }
10263
10264 /**
10265 * Gets the test mode for RCS VoLTE single registration.
10266 */
10267 @Override
10268 public boolean getRcsSingleRegistrationTestModeEnabled() {
10269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10270 "getRcsSingleRegistrationTestModeEnabled");
10271
10272 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10273 }
10274
10275 /**
Hui Wang761a6682020-10-31 05:12:53 +000010276 * Overrides the config of RCS VoLTE single registration enabled for the device.
10277 */
10278 @Override
10279 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10281 "setDeviceSingleRegistrationEnabledOverride");
10282 enforceModifyPermission();
10283
10284 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10285 : Boolean.parseBoolean(enabledStr);
10286 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010287 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010288 }
10289
10290 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010291 * Sends a device to device communication message. Only usable via shell.
10292 * @param message message to send.
10293 * @param value message value.
10294 */
10295 @Override
10296 public void sendDeviceToDeviceMessage(int message, int value) {
10297 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010298 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010299 enforceModifyPermission();
10300
10301 final long identity = Binder.clearCallingIdentity();
10302 try {
10303 TelephonyConnectionService service =
10304 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10305 if (service == null) {
10306 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10307 return;
10308 }
10309 service.sendTestDeviceToDeviceMessage(message, value);
10310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
Tyler Gunnbabbda02021-02-10 11:05:02 -080010315 /**
10316 * Sets the specified device to device transport active.
10317 * @param transport The transport to set active.
10318 */
10319 @Override
10320 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10321 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10322 "setActiveDeviceToDeviceTransport");
10323 enforceModifyPermission();
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 TelephonyConnectionService service =
10328 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10329 if (service == null) {
10330 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10331 return;
10332 }
10333 service.setActiveDeviceToDeviceTransport(transport);
10334 } finally {
10335 Binder.restoreCallingIdentity(identity);
10336 }
10337 }
Tyler Gunn92479152021-01-20 16:30:10 -080010338
Tyler Gunnd4575212021-05-03 14:46:49 -070010339 @Override
10340 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10341 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10342 "setDeviceToDeviceForceEnabled");
10343
10344 final long identity = Binder.clearCallingIdentity();
10345 try {
10346 Arrays.stream(PhoneFactory.getPhones()).forEach(
10347 p -> {
10348 Phone thePhone = p.getImsPhone();
10349 if (thePhone != null && thePhone instanceof ImsPhone) {
10350 ImsPhone imsPhone = (ImsPhone) thePhone;
10351 CallTracker tracker = imsPhone.getCallTracker();
10352 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10353 ImsPhoneCallTracker imsPhoneCallTracker =
10354 (ImsPhoneCallTracker) tracker;
10355 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10356 }
10357 }
10358 }
10359 );
10360 } finally {
10361 Binder.restoreCallingIdentity(identity);
10362 }
10363 }
10364
Tyler Gunn92479152021-01-20 16:30:10 -080010365 /**
Hui Wang761a6682020-10-31 05:12:53 +000010366 * Gets the config of RCS VoLTE single registration enabled for the device.
10367 */
10368 @Override
10369 public boolean getDeviceSingleRegistrationEnabled() {
10370 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10371 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10372 }
10373
10374 /**
10375 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10376 */
10377 @Override
10378 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10380 "setCarrierSingleRegistrationEnabledOverride");
10381 enforceModifyPermission();
10382
10383 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10384 : Boolean.parseBoolean(enabledStr);
10385 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10386 subId, enabled);
10387 }
10388
10389 /**
10390 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10391 */
10392 @Override
10393 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10394 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10395 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10396 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010397
10398 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010399 * Overrides the ims feature validation result
10400 */
10401 @Override
10402 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10403 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10404 "setImsFeatureValidationOverride");
10405
10406 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10407 : Boolean.parseBoolean(enabledStr);
10408 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10409 subId, enabled);
10410 }
10411
10412 /**
10413 * Gets the ims feature validation override value
10414 */
10415 @Override
10416 public boolean getImsFeatureValidationOverride(int subId) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "getImsFeatureValidationOverride");
10419 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10420 }
10421
10422 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010423 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10424 * their mobile plan.
10425 */
10426 @Override
10427 public String getMobileProvisioningUrl() {
10428 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 return getDefaultPhone().getMobileProvisioningUrl();
10432 } finally {
10433 Binder.restoreCallingIdentity(identity);
10434 }
10435 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010436
James.cf Linbcdf8b32021-01-14 16:44:13 +080010437 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010438 * Get the EAB contact from the EAB database.
10439 */
10440 @Override
10441 public String getContactFromEab(String contact) {
10442 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10443 enforceModifyPermission();
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10447 } finally {
10448 Binder.restoreCallingIdentity(identity);
10449 }
10450 }
10451
10452 /**
Calvin Pana1434322021-07-01 19:27:01 +080010453 * Get the EAB capability from the EAB database.
10454 */
10455 @Override
10456 public String getCapabilityFromEab(String contact) {
10457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10458 enforceModifyPermission();
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10462 } finally {
10463 Binder.restoreCallingIdentity(identity);
10464 }
10465 }
10466
10467 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010468 * Remove the EAB contacts from the EAB database.
10469 */
10470 @Override
10471 public int removeContactFromEab(int subId, String contacts) {
10472 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10473 enforceModifyPermission();
10474 final long identity = Binder.clearCallingIdentity();
10475 try {
10476 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010482 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010483 public boolean getDeviceUceEnabled() {
10484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 return mApp.getDeviceUceEnabled();
10488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
10492
10493 @Override
10494 public void setDeviceUceEnabled(boolean isEnabled) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 mApp.setDeviceUceEnabled(isEnabled);
10499 } finally {
10500 Binder.restoreCallingIdentity(identity);
10501 }
10502 }
10503
Brad Ebinger14d467f2021-02-12 06:18:28 +000010504 /**
10505 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10506 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10507 */
10508 // Used for SHELL command only right now.
10509 @Override
10510 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10511 List<String> featureTags) {
10512 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10513 "addUceRegistrationOverrideShell");
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10517 new ArraySet<>(featureTags));
10518 } catch (ImsException e) {
10519 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10520 } finally {
10521 Binder.restoreCallingIdentity(identity);
10522 }
10523 }
10524
10525 /**
10526 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10527 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10528 */
10529 // Used for SHELL command only right now.
10530 @Override
10531 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10532 List<String> featureTags) {
10533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10534 "removeUceRegistrationOverrideShell");
10535 final long identity = Binder.clearCallingIdentity();
10536 try {
10537 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10538 new ArraySet<>(featureTags));
10539 } catch (ImsException e) {
10540 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10541 } finally {
10542 Binder.restoreCallingIdentity(identity);
10543 }
10544 }
10545
10546 /**
10547 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10548 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10549 */
10550 // Used for SHELL command only right now.
10551 @Override
10552 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "clearUceRegistrationOverrideShell");
10555 final long identity = Binder.clearCallingIdentity();
10556 try {
10557 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10558 } catch (ImsException e) {
10559 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10560 } finally {
10561 Binder.restoreCallingIdentity(identity);
10562 }
10563 }
10564
10565 /**
10566 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10567 */
10568 // Used for SHELL command only right now.
10569 @Override
10570 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "getLatestRcsContactUceCapabilityShell");
10573 final long identity = Binder.clearCallingIdentity();
10574 try {
10575 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10576 } catch (ImsException e) {
10577 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10578 } finally {
10579 Binder.restoreCallingIdentity(identity);
10580 }
10581 }
10582
10583 /**
10584 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10585 * device does not have an active PUBLISH.
10586 */
10587 // Used for SHELL command only right now.
10588 @Override
10589 public String getLastUcePidfXmlShell(int subId) {
10590 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10591 final long identity = Binder.clearCallingIdentity();
10592 try {
10593 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10594 } catch (ImsException e) {
10595 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
10600
James.cf Line8713a42021-04-29 16:04:26 +080010601 /**
10602 * Remove UCE requests cannot be sent to the network status.
10603 */
10604 // Used for SHELL command only right now.
10605 @Override
10606 public boolean removeUceRequestDisallowedStatus(int subId) {
10607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10611 } catch (ImsException e) {
10612 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
James.cf Lin0fc71b02021-05-25 01:37:38 +080010618 /**
10619 * Remove UCE requests cannot be sent to the network status.
10620 */
10621 // Used for SHELL command only.
10622 @Override
10623 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10624 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10625 final long identity = Binder.clearCallingIdentity();
10626 try {
10627 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10628 } catch (ImsException e) {
10629 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10630 } finally {
10631 Binder.restoreCallingIdentity(identity);
10632 }
10633 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010634
James.cf Lin4b784aa2021-01-31 03:25:15 +080010635 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010636 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10637 String callingPackage) {
10638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10639 mApp, subId, "setSignalStrengthUpdateRequest");
10640
10641 final int callingUid = Binder.getCallingUid();
10642 // Verify that tha callingPackage belongs to the calling UID
10643 mApp.getSystemService(AppOpsManager.class)
10644 .checkPackage(callingUid, callingPackage);
10645
10646 validateSignalStrengthUpdateRequest(request, callingUid);
10647
10648 final long identity = Binder.clearCallingIdentity();
10649 try {
10650 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10651 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10652
10653 if (result instanceof IllegalStateException) {
10654 throw (IllegalStateException) result;
10655 }
10656 } finally {
10657 Binder.restoreCallingIdentity(identity);
10658 }
10659 }
10660
10661 @Override
10662 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10663 String callingPackage) {
10664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10665 mApp, subId, "clearSignalStrengthUpdateRequest");
10666
10667 final int callingUid = Binder.getCallingUid();
10668 // Verify that tha callingPackage belongs to the calling UID
10669 mApp.getSystemService(AppOpsManager.class)
10670 .checkPackage(callingUid, callingPackage);
10671
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
10674 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10675 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10676
10677 if (result instanceof IllegalStateException) {
10678 throw (IllegalStateException) result;
10679 }
10680 } finally {
10681 Binder.restoreCallingIdentity(identity);
10682 }
10683 }
10684
10685 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10686 int callingUid) {
10687 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10688 // phone/system process do not have further restriction on request
10689 return;
10690 }
10691
10692 // Applications has restrictions on how to use the request:
10693 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10694 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10695 // This is not system caller which has been checked above
10696 throw new IllegalArgumentException(
10697 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10698 }
10699
10700 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10701 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10702 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10703 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10704 || info.isEnabled()) {
10705 throw new IllegalArgumentException(
10706 "Only system can set hide fields in SignalThresholdInfo");
10707 }
10708
10709 // Thresholds length for each RAN need in range. This has been validated in
10710 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10711 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10712 final int[] thresholds = info.getThresholds();
10713 Objects.requireNonNull(thresholds);
10714 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10715 || thresholds.length
10716 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10717 throw new IllegalArgumentException(
10718 "thresholds length is out of range: " + thresholds.length);
10719 }
10720 }
10721 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010722
10723 /**
10724 * Gets the current phone capability.
10725 *
10726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10727 * @return the PhoneCapability which describes the data connection capability of modem.
10728 * It's used to evaluate possible phone config change, for example from single
10729 * SIM device to multi-SIM device.
10730 */
10731 @Override
10732 public PhoneCapability getPhoneCapability() {
10733 enforceReadPrivilegedPermission("getPhoneCapability");
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
Michele Berionne5e411512020-11-13 02:36:59 +000010741
10742 /**
10743 * Prepare TelephonyManager for an unattended reboot. The reboot is
10744 * required to be done shortly after the API is invoked.
10745 */
10746 @Override
10747 @TelephonyManager.PrepareUnattendedRebootResult
10748 public int prepareForUnattendedReboot() {
10749 enforceRebootPermission();
10750
10751 final long identity = Binder.clearCallingIdentity();
10752 try {
10753 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10754 } finally {
10755 Binder.restoreCallingIdentity(identity);
10756 }
10757 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010758
10759 /**
10760 * Request to get the current slicing configuration including URSP rules and
10761 * NSSAIs (configured, allowed and rejected).
10762 *
10763 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10764 */
10765 @Override
10766 public void getSlicingConfig(ResultReceiver callback) {
10767 enforceReadPrivilegedPermission("getSlicingConfig");
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 Phone phone = getDefaultPhone();
10772 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010777}