blob: 4254a35a3687c78adaa89bbb6935ac402bfbbbac [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) {
Hall Liu27d24262020-09-18 19:04:59 -07001012 callForwardingInfo = new CallForwardingInfo(true,
1013 callForwardInfo.reason,
1014 callForwardInfo.number,
1015 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 break;
1017 }
1018 }
1019 // Didn't find a call forward info for voice call.
1020 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001021 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1022 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 }
Hall Liu27d24262020-09-18 19:04:59 -07001024 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 } else {
1026 if (ar.result == null) {
1027 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1028 }
1029 if (ar.exception != null) {
1030 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1031 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 int errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001034 if (ar.exception instanceof CommandException) {
1035 CommandException.Error error =
1036 ((CommandException) (ar.exception)).getCommandError();
1037 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager
1039 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001041 errorCode = TelephonyManager
1042 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001043 }
1044 }
Hall Liu27d24262020-09-18 19:04:59 -07001045 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047 break;
Hall Liu27d24262020-09-18 19:04:59 -07001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049
Hall Liu27d24262020-09-18 19:04:59 -07001050 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001053 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001054 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001055 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1056 request.argument).first;
1057 request.phone.setCallForwardingOption(
1058 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001059 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001060 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001061 callForwardingInfoToSet.getReason(),
1062 callForwardingInfoToSet.getNumber(),
1063 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1064 break;
Hall Liu27d24262020-09-18 19:04:59 -07001065 }
Shuo Qian4a594052020-01-23 11:59:30 -08001066
Hall Liu27d24262020-09-18 19:04:59 -07001067 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001070 Consumer<Integer> callback =
1071 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1072 request.argument).second;
1073 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001074 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001075 int errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 errorCode = TelephonyManager.CallForwardingInfoCallback
1082 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001084 errorCode = TelephonyManager.CallForwardingInfoCallback
1085 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 }
1088 callback.accept(errorCode);
1089 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001090 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092 break;
Hall Liu27d24262020-09-18 19:04:59 -07001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1098 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1099 break;
Hall Liu27d24262020-09-18 19:04:59 -07001100 }
Shuo Qian4a594052020-01-23 11:59:30 -08001101
Hall Liu27d24262020-09-18 19:04:59 -07001102 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001105 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001106 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1107 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 // Service Class is a bit mask per 3gpp 27.007.
1110 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001111 if (callForwardResults.length > 1
1112 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001113 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001114 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001115 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1116 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001118 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001119 }
1120 } else {
1121 if (ar.result == null) {
1122 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1123 }
1124 if (ar.exception != null) {
1125 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1126 }
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 callForwardingStatus =
1132 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1133 }
1134 }
1135 }
Hall Liu27d24262020-09-18 19:04:59 -07001136 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001143 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1144 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001145 break;
Hall Liu27d24262020-09-18 19:04:59 -07001146 }
Shuo Qian4a594052020-01-23 11:59:30 -08001147
Hall Liu27d24262020-09-18 19:04:59 -07001148 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001151 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1152 Consumer<Integer> callback =
1153 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1154 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001156 if (ar.exception instanceof CommandException) {
1157 CommandException.Error error =
1158 ((CommandException) (ar.exception)).getCommandError();
1159 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1161 } else {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1163 }
1164 } else {
1165 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1166 }
1167 } else {
1168 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1169 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001170 }
Shuo Qian4a594052020-01-23 11:59:30 -08001171 break;
Hall Liu27d24262020-09-18 19:04:59 -07001172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001173 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1174 ar = (AsyncResult) msg.obj;
1175 request = (MainThreadRequest) ar.userObj;
1176 CellNetworkScanResult cellScanResult;
1177 if (ar.exception == null && ar.result != null) {
1178 cellScanResult = new CellNetworkScanResult(
1179 CellNetworkScanResult.STATUS_SUCCESS,
1180 (List<OperatorInfo>) ar.result);
1181 } else {
1182 if (ar.result == null) {
1183 loge("getCellNetworkScanResults: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1187 }
1188 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1189 if (ar.exception instanceof CommandException) {
1190 CommandException.Error error =
1191 ((CommandException) (ar.exception)).getCommandError();
1192 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1193 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1194 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1195 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1196 }
1197 }
1198 cellScanResult = new CellNetworkScanResult(errorCode, null);
1199 }
1200 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 break;
1203
1204 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1205 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001206 ManualNetworkSelectionArgument selArg =
1207 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1209 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001210 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1211 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
1214 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
1217 if (ar.exception == null) {
1218 request.result = true;
1219 } else {
1220 request.result = false;
1221 loge("setNetworkSelectionModeManual " + ar.exception);
1222 }
1223 notifyRequester(request);
1224 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001225 break;
1226
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 case CMD_GET_MODEM_ACTIVITY_INFO:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001230 if (defaultPhone != null) {
1231 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 } else {
1233 ResultReceiver result = (ResultReceiver) request.argument;
1234 Bundle bundle = new Bundle();
1235 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001236 new ModemActivityInfo(0, 0, 0,
1237 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001238 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001239 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 break;
1241
Hall Liud0f208c2020-10-14 16:54:44 -07001242 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 ResultReceiver result = (ResultReceiver) request.argument;
1246
Hall Liud0f208c2020-10-14 16:54:44 -07001247 ModemActivityInfo ret = null;
1248 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001250 // Update the last modem activity info and the result of the request.
1251 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1252 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001253 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 int[] txTimeMs = info.getTransmitTimeMillis();
1255 int[] lastModemTxTimeMs = mLastModemActivityInfo
1256 .getTransmitTimeMillis();
1257 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1258 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1259 }
Hall Liu49656c02020-10-09 19:00:11 -07001260 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1262 + mLastModemActivityInfo.getSleepTimeMillis());
1263 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1264 + mLastModemActivityInfo.getIdleTimeMillis());
1265 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1266 mLastModemActivityInfo.setReceiveTimeMillis(
1267 info.getReceiveTimeMillis()
1268 + mLastModemActivityInfo.getReceiveTimeMillis());
1269 }
Hall Liu49656c02020-10-09 19:00:11 -07001270 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001271 mLastModemActivityInfo.getSleepTimeMillis(),
1272 mLastModemActivityInfo.getIdleTimeMillis(),
1273 mLastModemActivityInfo.getTransmitTimeMillis(),
1274 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001275 } else {
1276 if (ar.result == null) {
1277 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 } else if (ar.exception instanceof CommandException) {
1281 loge("queryModemActivityInfo: CommandException: " +
1282 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001283 error = TelephonyManager.ModemActivityInfoException
1284 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001285 } else {
1286 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001287 error = TelephonyManager.ModemActivityInfoException
1288 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001289 }
1290 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001291 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001292 if (ret != null) {
1293 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1294 } else {
1295 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1296 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001297 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001298 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001299 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001300 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001301
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 case CMD_SET_ALLOWED_CARRIERS:
1303 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001304 CarrierRestrictionRules argument =
1305 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001307 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
1310 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
1313 if (ar.exception == null && ar.result != null) {
1314 request.result = ar.result;
1315 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001316 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1317 if (ar.exception instanceof CommandException) {
1318 loge("setAllowedCarriers: CommandException: " + ar.exception);
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1322 request.result =
1323 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1324 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001325 } else {
1326 loge("setAllowedCarriers: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001330 break;
1331
1332 case CMD_GET_ALLOWED_CARRIERS:
1333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001335 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001336 break;
1337
1338 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 if (ar.exception == null && ar.result != null) {
1342 request.result = ar.result;
1343 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001344 request.result = new IllegalStateException(
1345 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001346 if (ar.result == null) {
1347 loge("getAllowedCarriers: Empty response");
1348 } else if (ar.exception instanceof CommandException) {
1349 loge("getAllowedCarriers: CommandException: " +
1350 ar.exception);
1351 } else {
1352 loge("getAllowedCarriers: Unknown exception");
1353 }
1354 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001356 break;
1357
Nathan Haroldb3014052017-01-25 15:57:32 -08001358 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 if (ar.exception == null && ar.result != null) {
1362 request.result = ar.result;
1363 } else {
1364 request.result = new IllegalArgumentException(
1365 "Failed to retrieve Forbidden Plmns");
1366 if (ar.result == null) {
1367 loge("getForbiddenPlmns: Empty response");
1368 } else {
1369 loge("getForbiddenPlmns: Unknown exception");
1370 }
1371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001373 break;
1374
1375 case CMD_GET_FORBIDDEN_PLMNS:
1376 request = (MainThreadRequest) msg.obj;
1377 uiccCard = getUiccCardFromRequest(request);
1378 if (uiccCard == null) {
1379 loge("getForbiddenPlmns() UiccCard is null");
1380 request.result = new IllegalArgumentException(
1381 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001382 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001383 break;
1384 }
1385 Integer appType = (Integer) request.argument;
1386 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1387 if (uiccApp == null) {
1388 loge("getForbiddenPlmns() no app with specified type -- "
1389 + appType);
1390 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001392 break;
1393 } else {
1394 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1395 + " specified type -- " + appType);
1396 }
1397 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1398 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1399 onCompleted);
1400 break;
1401
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001402 case CMD_SWITCH_SLOTS:
1403 request = (MainThreadRequest) msg.obj;
1404 int[] physicalSlots = (int[]) request.argument;
1405 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1406 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1407 break;
1408
1409 case EVENT_SWITCH_SLOTS_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001413 notifyRequester(request);
1414 break;
1415 case CMD_GET_NETWORK_SELECTION_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1418 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1419 break;
1420
1421 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception != null) {
1425 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1426 } else {
1427 int mode = ((int[]) ar.result)[0];
1428 if (mode == 0) {
1429 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1430 } else {
1431 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1432 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001433 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
1435 break;
1436 case CMD_GET_CDMA_ROAMING_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1439 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1440 break;
1441 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception != null) {
1445 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1446 } else {
1447 request.result = ((int[]) ar.result)[0];
1448 }
1449 notifyRequester(request);
1450 break;
1451 case CMD_SET_CDMA_ROAMING_MODE:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1454 int mode = (int) request.argument;
1455 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1456 break;
1457 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 request.result = ar.exception == null;
1461 notifyRequester(request);
1462 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001463 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1466 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1467 break;
1468 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception != null) {
1472 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1473 } else {
1474 request.result = ((int[]) ar.result)[0];
1475 }
1476 notifyRequester(request);
1477 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1479 request = (MainThreadRequest) msg.obj;
1480 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1481 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001482 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1483 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001484 break;
1485 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 request.result = ar.exception == null;
1489 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 case CMD_GET_ALL_CELL_INFO:
1492 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001494 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 case EVENT_GET_ALL_CELL_INFO_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001499 // If a timeout occurs, the response will be null
1500 request.result = (ar.exception == null && ar.result != null)
1501 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001506 case CMD_REQUEST_CELL_INFO_UPDATE:
1507 request = (MainThreadRequest) msg.obj;
1508 request.phone.requestCellInfoUpdate(request.workSource,
1509 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1510 break;
1511 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1515 try {
1516 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001517 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001518 cb.onError(
1519 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1520 ar.exception.getClass().getName(),
1521 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001524 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001525 } else {
1526 // use the result as returned
1527 cb.onCellInfo((List<CellInfo>) ar.result);
1528 }
1529 } catch (RemoteException re) {
1530 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1531 }
1532 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 request = (MainThreadRequest) msg.obj;
1535 WorkSource ws = (WorkSource) request.argument;
1536 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001537 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001539 }
1540 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 if (ar.exception == null) {
1544 request.result = ar.result;
1545 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001546 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001547 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001548 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001549 }
1550
1551 synchronized (request) {
1552 request.notifyAll();
1553 }
1554 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001555 }
chen xu6dac5ab2018-10-26 17:39:23 -07001556 case CMD_MODEM_REBOOT:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001560 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001561 case EVENT_CMD_MODEM_REBOOT_DONE:
1562 handleNullReturnEvent(msg, "rebootModem");
1563 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 case CMD_REQUEST_ENABLE_MODEM:
1565 request = (MainThreadRequest) msg.obj;
1566 boolean enable = (boolean) request.argument;
1567 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001568 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 PhoneConfigurationManager.getInstance()
1570 .enablePhone(request.phone, enable, onCompleted);
1571 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001572 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001576 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001577 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 if ((boolean) request.result) {
1579 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1580 updateModemStateMetrics();
1581 } else {
1582 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1583 + ar.exception);
1584 }
1585 notifyRequester(request);
1586 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001587 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001588 case CMD_GET_MODEM_STATUS:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1591 PhoneConfigurationManager.getInstance()
1592 .getPhoneStatusFromModem(request.phone, onCompleted);
1593 break;
1594 case EVENT_GET_MODEM_STATUS_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 int id = request.phone.getPhoneId();
1598 if (ar.exception == null && ar.result != null) {
1599 request.result = ar.result;
1600 //update the cache as modem status has changed
1601 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1602 (boolean) request.result);
1603 } else {
1604 // Return true if modem status cannot be retrieved. For most cases,
1605 // modem status is on. And for older version modems, GET_MODEM_STATUS
1606 // and disable modem are not supported. Modem is always on.
1607 // TODO: this should be fixed in R to support a third
1608 // status UNKNOWN b/131631629
1609 request.result = true;
1610 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1611 + ar.exception);
1612 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001613 notifyRequester(request);
1614 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001615 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1616 request = (MainThreadRequest) msg.obj;
1617 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1618 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1619 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1620 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1621 break;
1622 }
1623 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1624 ar = (AsyncResult) msg.obj;
1625 request = (MainThreadRequest) ar.userObj;
1626 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1627 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1628 args.second.accept(ar.exception == null);
1629 notifyRequester(request);
1630 break;
1631 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001632 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1635 Phone phone = getPhoneFromRequest(request);
1636 if (phone != null) {
1637 phone.getSystemSelectionChannels(onCompleted);
1638 } else {
1639 loge("getSystemSelectionChannels: No phone object");
1640 request.result = new ArrayList<RadioAccessSpecifier>();
1641 notifyRequester(request);
1642 }
1643 break;
1644 }
1645 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 if (ar.exception == null && ar.result != null) {
1649 request.result = ar.result;
1650 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001651 request.result = new IllegalStateException(
1652 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001653 if (ar.result == null) {
1654 loge("getSystemSelectionChannels: Empty response");
1655 } else {
1656 loge("getSystemSelectionChannels: Unknown exception");
1657 }
1658 }
1659 notifyRequester(request);
1660 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001661 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 if (ar.exception == null && ar.result != null) {
1665 request.result = ar.result;
1666 } else {
1667 request.result = -1;
1668 loge("Failed to set Forbidden Plmns");
1669 if (ar.result == null) {
1670 loge("setForbidenPlmns: Empty response");
1671 } else if (ar.exception != null) {
1672 loge("setForbiddenPlmns: Exception: " + ar.exception);
1673 request.result = -1;
1674 } else {
1675 loge("setForbiddenPlmns: Unknown exception");
1676 }
1677 }
1678 notifyRequester(request);
1679 break;
1680 case CMD_SET_FORBIDDEN_PLMNS:
1681 request = (MainThreadRequest) msg.obj;
1682 uiccCard = getUiccCardFromRequest(request);
1683 if (uiccCard == null) {
1684 loge("setForbiddenPlmns: UiccCard is null");
1685 request.result = -1;
1686 notifyRequester(request);
1687 break;
1688 }
1689 Pair<Integer, List<String>> setFplmnsArgs =
1690 (Pair<Integer, List<String>>) request.argument;
1691 appType = setFplmnsArgs.first;
1692 List<String> fplmns = setFplmnsArgs.second;
1693 uiccApp = uiccCard.getApplicationByType(appType);
1694 if (uiccApp == null) {
1695 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1696 request.result = -1;
1697 loge("Failed to get UICC App");
1698 notifyRequester(request);
1699 } else {
1700 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1701 ((SIMRecords) uiccApp.getIccRecords())
1702 .setForbiddenPlmns(onCompleted, fplmns);
1703 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001704 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001705 case CMD_ERASE_MODEM_CONFIG:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1708 defaultPhone.eraseModemConfig(onCompleted);
1709 break;
1710 case EVENT_ERASE_MODEM_CONFIG_DONE:
1711 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001712 break;
zoey chene02881a2019-12-30 16:11:23 +08001713
Kai Shif70f46f2021-03-03 13:59:46 -08001714 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1715 request = (MainThreadRequest) msg.obj;
1716 request.result = defaultPhone.eraseDataInSharedPreferences();
1717 notifyRequester(request);
1718 break;
1719
zoey chene02881a2019-12-30 16:11:23 +08001720 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1723 Pair<String, String> changed = (Pair<String, String>) request.argument;
1724 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1725 changed.first, changed.second, onCompleted);
1726 break;
1727 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 if (ar.exception == null) {
1731 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 // If the operation is successful, update the PIN storage
1733 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1734 int phoneId = getPhoneFromRequest(request).getPhoneId();
1735 UiccController.getInstance().getPinStorage()
1736 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001737 } else {
1738 request.result = msg.arg1;
1739 }
1740 notifyRequester(request);
1741 break;
1742
Michele Berionne5e411512020-11-13 02:36:59 +00001743 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1746 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1747 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1748 enabled.first, enabled.second, onCompleted);
1749 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001750 }
zoey chene02881a2019-12-30 16:11:23 +08001751 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 if (ar.exception == null) {
1755 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 // If the operation is successful, update the PIN storage
1757 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1758 int phoneId = getPhoneFromRequest(request).getPhoneId();
1759 if (enabled.first) {
1760 UiccController.getInstance().getPinStorage()
1761 .storePin(enabled.second, phoneId);
1762 } else {
1763 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1764 }
zoey chene02881a2019-12-30 16:11:23 +08001765 } else {
1766 request.result = msg.arg1;
1767 }
Michele Berionne5e411512020-11-13 02:36:59 +00001768
1769
zoey chene02881a2019-12-30 16:11:23 +08001770 notifyRequester(request);
1771 break;
1772
Peter Wangdafb9ac2020-01-15 14:13:38 -08001773 case MSG_NOTIFY_USER_ACTIVITY:
1774 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001775 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001776 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1777 getDefaultPhone().getContext().sendBroadcastAsUser(
1778 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1779 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001780
1781 case CMD_SET_DATA_THROTTLING: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1784 DataThrottlingRequest dataThrottlingRequest =
1785 (DataThrottlingRequest) request.argument;
1786 Phone phone = getPhoneFromRequest(request);
1787 if (phone != null) {
1788 phone.setDataThrottling(onCompleted,
1789 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1790 dataThrottlingRequest.getCompletionDurationMillis());
1791 } else {
1792 loge("setDataThrottling: No phone object");
1793 request.result =
1794 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1795 notifyRequester(request);
1796 }
1797
1798 break;
1799 }
1800 case EVENT_SET_DATA_THROTTLING_DONE:
1801 ar = (AsyncResult) msg.obj;
1802 request = (MainThreadRequest) ar.userObj;
1803
1804 if (ar.exception == null) {
1805 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1806 } else if (ar.exception instanceof CommandException) {
1807 loge("setDataThrottling: CommandException: " + ar.exception);
1808 CommandException.Error error =
1809 ((CommandException) (ar.exception)).getCommandError();
1810
1811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1812 request.result = TelephonyManager
1813 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1814 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1815 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001816 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1817 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001818 } else {
1819 request.result =
1820 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1821 }
1822 } else {
1823 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1824 }
1825 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1826 notifyRequester(request);
1827 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001828
1829 case CMD_SET_SIM_POWER: {
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1832 request = (MainThreadRequest) msg.obj;
1833 int stateToSet =
1834 ((Pair<Integer, IIntegerConsumer>)
1835 request.argument).first;
1836 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1837 break;
1838 }
1839 case EVENT_SET_SIM_POWER_DONE: {
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 IIntegerConsumer callback =
1843 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1844 if (ar.exception != null) {
1845 loge("setSimPower exception: " + ar.exception);
1846 int errorCode = TelephonyManager.CallForwardingInfoCallback
1847 .RESULT_ERROR_UNKNOWN;
1848 if (ar.exception instanceof CommandException) {
1849 CommandException.Error error =
1850 ((CommandException) (ar.exception)).getCommandError();
1851 if (error == CommandException.Error.SIM_ERR) {
1852 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1853 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1855 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1857 } else {
1858 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1859 }
1860 }
1861 try {
1862 callback.accept(errorCode);
1863 } catch (RemoteException e) {
1864 // Ignore if the remote process is no longer available to call back.
1865 Log.w(LOG_TAG, "setSimPower: callback not available.");
1866 }
1867 } else {
1868 try {
1869 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1870 } catch (RemoteException e) {
1871 // Ignore if the remote process is no longer available to call back.
1872 Log.w(LOG_TAG, "setSimPower: callback not available.");
1873 }
1874 }
1875 break;
1876 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001877 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1878 request = (MainThreadRequest) msg.obj;
1879
1880 final Phone phone = getPhoneFromRequest(request);
1881 if (phone == null || phone.getServiceStateTracker() == null) {
1882 request.result = new IllegalStateException("Phone or SST is null");
1883 notifyRequester(request);
1884 break;
1885 }
1886
1887 Pair<Integer, SignalStrengthUpdateRequest> pair =
1888 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1889 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1890 request);
1891 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1892 request.subId, pair.first /*callingUid*/,
1893 pair.second /*request*/, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 // request.result will be the exception of ar if present, true otherwise.
1900 // Be cautious not to leave result null which will wait() forever
1901 request.result = ar.exception != null ? ar.exception : true;
1902 notifyRequester(request);
1903 break;
1904 }
1905 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1906 request = (MainThreadRequest) msg.obj;
1907
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone == null || phone.getServiceStateTracker() == null) {
1910 request.result = new IllegalStateException("Phone or SST is null");
1911 notifyRequester(request);
1912 break;
1913 }
1914
1915 Pair<Integer, SignalStrengthUpdateRequest> pair =
1916 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1917 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1918 request);
1919 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1920 request.subId, pair.first /*callingUid*/,
1921 pair.second /*request*/, onCompleted);
1922 break;
1923 }
1924 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 request.result = ar.exception != null ? ar.exception : true;
1928 notifyRequester(request);
1929 break;
1930 }
Jordan Liu109698e2020-11-24 14:50:34 -08001931
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001932 case CMD_GET_SLICING_CONFIG: {
1933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1935 request.phone.getSlicingConfig(onCompleted);
1936 break;
1937 }
1938 case EVENT_GET_SLICING_CONFIG_DONE: {
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 ResultReceiver result = (ResultReceiver) request.argument;
1942
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001943 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001944 Bundle bundle = new Bundle();
1945 int resultCode = 0;
1946 if (ar.exception != null) {
1947 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1948 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001949 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001950 } else if (ar.result == null) {
1951 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001952 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001953 } else {
1954 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001955 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1956 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001957 }
1958
1959 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001960 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001961 }
1962 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1963 result.send(resultCode, bundle);
1964 notifyRequester(request);
1965 break;
1966 }
1967
Michele Berionne5e411512020-11-13 02:36:59 +00001968 case CMD_PREPARE_UNATTENDED_REBOOT:
1969 request = (MainThreadRequest) msg.obj;
1970 request.result =
1971 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1972 notifyRequester(request);
1973 break;
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 default:
1976 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1977 break;
1978 }
1979 }
Jake Hambye994d462014-02-03 13:10:13 -08001980
Pengquan Menga1bb6272018-09-06 09:59:22 -07001981 private void notifyRequester(MainThreadRequest request) {
1982 synchronized (request) {
1983 request.notifyAll();
1984 }
1985 }
1986
Jake Hambye994d462014-02-03 13:10:13 -08001987 private void handleNullReturnEvent(Message msg, String command) {
1988 AsyncResult ar = (AsyncResult) msg.obj;
1989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1990 if (ar.exception == null) {
1991 request.result = true;
1992 } else {
1993 request.result = false;
1994 if (ar.exception instanceof CommandException) {
1995 loge(command + ": CommandException: " + ar.exception);
1996 } else {
1997 loge(command + ": Unknown exception");
1998 }
1999 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002000 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 /**
2005 * Posts the specified command to be executed on the main thread,
2006 * waits for the request to complete, and returns the result.
2007 * @see #sendRequestAsync
2008 */
2009 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002010 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2011 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002012 }
2013
2014 /**
2015 * Posts the specified command to be executed on the main thread,
2016 * waits for the request to complete, and returns the result.
2017 * @see #sendRequestAsync
2018 */
2019 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2020 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002022 }
2023
2024 /**
2025 * Posts the specified command to be executed on the main thread,
2026 * waits for the request to complete, and returns the result.
2027 * @see #sendRequestAsync
2028 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002029 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2031 }
2032
2033 /**
2034 * Posts the specified command to be executed on the main thread,
2035 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2036 * if not timeout or null otherwise.
2037 * @see #sendRequestAsync
2038 */
2039 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2040 long timeoutInMs) {
2041 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002042 }
2043
2044 /**
2045 * Posts the specified command to be executed on the main thread,
2046 * waits for the request to complete, and returns the result.
2047 * @see #sendRequestAsync
2048 */
Nathan Harold92bed182018-10-12 18:16:49 -07002049 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002050 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002051 }
2052
2053 /**
2054 * Posts the specified command to be executed on the main thread,
2055 * waits for the request to complete, and returns the result.
2056 * @see #sendRequestAsync
2057 */
2058 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002059 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2060 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002061 }
2062
2063 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002064 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2065 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2066 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002067 * @see #sendRequestAsync
2068 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002069 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2070 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2072 throw new RuntimeException("This method will deadlock if called from the main thread.");
2073 }
2074
Nathan Harold92bed182018-10-12 18:16:49 -07002075 MainThreadRequest request = null;
2076 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2077 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2078 } else if (phone != null) {
2079 request = new MainThreadRequest(argument, phone, workSource);
2080 } else {
2081 request = new MainThreadRequest(argument, subId, workSource);
2082 }
2083
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 Message msg = mMainThreadHandler.obtainMessage(command, request);
2085 msg.sendToTarget();
2086
Rambo Wang0f050d82021-02-12 11:43:36 -08002087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002089 if (timeoutInMs >= 0) {
2090 // Wait for at least timeoutInMs before returning null request result
2091 long now = SystemClock.elapsedRealtime();
2092 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002093 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002094 try {
2095 request.wait(deadline - now);
2096 } catch (InterruptedException e) {
2097 // Do nothing, go back and check if request is completed or timeout
2098 } finally {
2099 now = SystemClock.elapsedRealtime();
2100 }
2101 }
2102 } else {
2103 // Wait for the request to complete
2104 while (request.result == null) {
2105 try {
2106 request.wait();
2107 } catch (InterruptedException e) {
2108 // Do nothing, go back and wait until the request is complete
2109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111 }
2112 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002113 if (request.result == null) {
2114 Log.wtf(LOG_TAG,
2115 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 return request.result;
2118 }
2119
2120 /**
2121 * Asynchronous ("fire and forget") version of sendRequest():
2122 * Posts the specified command to be executed on the main thread, and
2123 * returns immediately.
2124 * @see #sendRequest
2125 */
2126 private void sendRequestAsync(int command) {
2127 mMainThreadHandler.sendEmptyMessage(command);
2128 }
2129
2130 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 */
2134 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 sendRequestAsync(command, argument, null, null);
2136 }
2137
2138 /**
2139 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2140 * @see {@link #sendRequest(int,Object)}
2141 */
2142 private void sendRequestAsync(
2143 int command, Object argument, Phone phone, WorkSource workSource) {
2144 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002145 Message msg = mMainThreadHandler.obtainMessage(command, request);
2146 msg.sendToTarget();
2147 }
2148
2149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 * Initialize the singleton PhoneInterfaceManager instance.
2151 * This is only done once, at startup, from PhoneApp.onCreate().
2152 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002153 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 synchronized (PhoneInterfaceManager.class) {
2155 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 } else {
2158 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2159 }
2160 return sInstance;
2161 }
2162 }
2163
2164 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002165 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002168 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002169 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002171 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002173 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002174 mTelephonySharedPreferences =
2175 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002176 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002177 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002178 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002179 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 publish();
2182 }
2183
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002184 private Phone getDefaultPhone() {
2185 Phone thePhone = getPhone(getDefaultSubscription());
2186 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2187 }
2188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 private void publish() {
2190 if (DBG) log("publish: " + this);
2191
Peter Wangc035ce42020-01-08 21:00:22 -08002192 TelephonyFrameworkInitializer
2193 .getTelephonyServiceManager()
2194 .getTelephonyServiceRegisterer()
2195 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Stuart Scott584921c2015-01-15 17:10:34 -08002198 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002199 if (request.phone != null) {
2200 return request.phone;
2201 } else {
2202 return getPhoneFromSubId(request.subId);
2203 }
2204 }
2205
2206 private Phone getPhoneFromSubId(int subId) {
2207 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2208 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002209 }
2210
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002211 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2212 Phone phone = getPhoneFromRequest(request);
2213 return phone == null ? null :
2214 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2215 }
2216
Wink Saville36469e72014-06-11 15:17:00 -07002217 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002218 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002219 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221
Kai Shif70f46f2021-03-03 13:59:46 -08002222 private void sendEraseModemConfig(@NonNull Phone phone) {
2223 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2224 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2225 }
2226
2227 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2228 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2229 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002230 }
2231
Peter Wang44b186e2020-01-13 23:33:09 -08002232 private boolean isImsAvailableOnDevice() {
2233 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2234 if (pm == null) {
2235 // For some reason package manger is not available.. This will fail internally anyway,
2236 // so do not throw error and allow.
2237 return true;
2238 }
2239 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2240 }
2241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 if (DBG) log("dial: " + number);
2248 // No permission check needed here: This is just a wrapper around the
2249 // ACTION_DIAL intent, which is available to any app since it puts up
2250 // the UI before it does anything.
2251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 String url = createTelUrl(number);
2255 if (url == null) {
2256 return;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 // PENDING: should we just silently fail if phone is offhook or ringing?
2260 PhoneConstants.State state = mCM.getState(subId);
2261 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2262 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2264 mApp.startActivity(intent);
2265 }
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269 }
2270
2271 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002272 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002273 }
2274
Wink Savilleb564aae2014-10-23 10:18:09 -07002275 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 if (DBG) log("call: " + number);
2277
2278 // This is just a wrapper around the ACTION_CALL intent, but we still
2279 // need to do a permission check since we're calling startActivity()
2280 // from the context of the phone app.
2281 enforceCallPermission();
2282
Jordan Liu1617b712019-07-10 15:06:26 -07002283 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 != AppOpsManager.MODE_ALLOWED) {
2285 return;
2286 }
2287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 String url = createTelUrl(number);
2291 if (url == null) {
2292 return;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 boolean isValid = false;
2296 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2297 if (slist != null) {
2298 for (SubscriptionInfo subInfoRecord : slist) {
2299 if (subInfoRecord.getSubscriptionId() == subId) {
2300 isValid = true;
2301 break;
2302 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002303 }
Wink Saville08874612014-08-31 19:19:58 -07002304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (!isValid) {
2306 return;
2307 }
Wink Saville08874612014-08-31 19:19:58 -07002308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2310 intent.putExtra(SUBSCRIPTION_KEY, subId);
2311 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2312 mApp.startActivity(intent);
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002319 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002320 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2321 }
2322
Wink Savilleb564aae2014-10-23 10:18:09 -07002323 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2326 }
2327
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002333 Phone phone = getPhone(subId);
2334 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 checkSimPin.start();
2336 return checkSimPin.unlockSim(null, pin);
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002347 Phone phone = getPhone(subId);
2348 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 checkSimPuk.start();
2350 return checkSimPuk.unlockSim(puk, pin);
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
2356 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002357 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 * a synchronous one.
2359 */
2360 private static class UnlockSim extends Thread {
2361
2362 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002363 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002366 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2367 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
2369 // For replies from SimCard interface
2370 private Handler mHandler;
2371
2372 // For async handler to identify request type
2373 private static final int SUPPLY_PIN_COMPLETE = 100;
2374
Michele Berionne5e411512020-11-13 02:36:59 +00002375 UnlockSim(int phoneId, IccCard simCard) {
2376 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 mSimCard = simCard;
2378 }
2379
2380 @Override
2381 public void run() {
2382 Looper.prepare();
2383 synchronized (UnlockSim.this) {
2384 mHandler = new Handler() {
2385 @Override
2386 public void handleMessage(Message msg) {
2387 AsyncResult ar = (AsyncResult) msg.obj;
2388 switch (msg.what) {
2389 case SUPPLY_PIN_COMPLETE:
2390 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2391 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002392 mRetryCount = msg.arg1;
2393 if (ar.exception != null) {
2394 if (ar.exception instanceof CommandException &&
2395 ((CommandException)(ar.exception)).getCommandError()
2396 == CommandException.Error.PASSWORD_INCORRECT) {
2397 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002398 } //When UiccCardApp dispose,handle message and return exception
2399 else if (ar.exception instanceof CommandException &&
2400 ((CommandException) (ar.exception)).getCommandError()
2401 == CommandException.Error.ABORTED) {
2402 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002403 } else {
2404 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2405 }
2406 } else {
2407 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 mDone = true;
2410 UnlockSim.this.notifyAll();
2411 }
2412 break;
2413 }
2414 }
2415 };
2416 UnlockSim.this.notifyAll();
2417 }
2418 Looper.loop();
2419 }
2420
2421 /*
2422 * Use PIN or PUK to unlock SIM card
2423 *
2424 * If PUK is null, unlock SIM card with PIN
2425 *
2426 * If PUK is not null, unlock SIM card with PUK and set PIN code
2427 */
Wink Saville9de0f752013-10-22 19:04:03 -07002428 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429
2430 while (mHandler == null) {
2431 try {
2432 wait();
2433 } catch (InterruptedException e) {
2434 Thread.currentThread().interrupt();
2435 }
2436 }
2437 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2438
2439 if (puk == null) {
2440 mSimCard.supplyPin(pin, callback);
2441 } else {
2442 mSimCard.supplyPuk(puk, pin, callback);
2443 }
2444
2445 while (!mDone) {
2446 try {
2447 Log.d(LOG_TAG, "wait for done");
2448 wait();
2449 } catch (InterruptedException e) {
2450 // Restore the interrupted status
2451 Thread.currentThread().interrupt();
2452 }
2453 }
2454 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002455 int[] resultArray = new int[2];
2456 resultArray[0] = mResult;
2457 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002458
2459 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2460 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2461 }
2462
Wink Saville9de0f752013-10-22 19:04:03 -07002463 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002467 /**
2468 * This method has been removed due to privacy and stability concerns.
2469 */
2470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002472 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2473 return;
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
Nathan Harold1f889d82020-06-04 17:05:26 -07002476 @Override
2477 public void updateServiceLocationWithPackageName(String callingPackage) {
2478 mApp.getSystemService(AppOpsManager.class)
2479 .checkPackage(Binder.getCallingUid(), callingPackage);
2480
Nathan Haroldf096d982020-11-18 17:18:06 -08002481 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002482 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2483 // Callers targeting S have no business invoking this method.
2484 return;
2485 }
2486
2487 LocationAccessPolicy.LocationPermissionResult locationResult =
2488 LocationAccessPolicy.checkLocationPermission(mApp,
2489 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2490 .setCallingPackage(callingPackage)
2491 .setCallingFeatureId(null)
2492 .setCallingPid(Binder.getCallingPid())
2493 .setCallingUid(Binder.getCallingUid())
2494 .setMethod("updateServiceLocation")
2495 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2496 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2497 .build());
2498 // Apps that lack location permission have no business calling this method;
2499 // however, because no permission was declared in the public API, denials must
2500 // all be "soft".
2501 switch (locationResult) {
2502 case DENIED_HARD: /* fall through */
2503 case DENIED_SOFT:
2504 return;
2505 }
2506
2507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002510 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002512 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002519 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
2521 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 return isRadioOnWithFeature(callingPackage, null);
2523 }
2524
2525
2526 @Override
2527 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2528 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2529 callingFeatureId);
2530 }
2531
2532 @Deprecated
2533 @Override
2534 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2535 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002542 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 return false;
2544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 return isRadioOnForSubscriber(subId);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 }
2553
2554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2560 } else {
2561 return false;
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
2568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
Wink Saville36469e72014-06-11 15:17:00 -07002571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 }
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
2586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = getPhone(subId);
2596 if (phone == null) {
2597 return false;
2598 }
2599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2600 toggleRadioOnOffForSubscriber(subId);
2601 }
2602 return true;
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
Wink Saville36469e72014-06-11 15:17:00 -07002607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002608 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002609 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002610 /*
2611 * If any of the Radios are available, it will need to be
2612 * shutdown. So return true if any Radio is available.
2613 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2617 Phone phone = PhoneFactory.getPhone(i);
2618 if (phone != null && phone.isRadioAvailable()) return true;
2619 }
2620 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2621 return false;
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002625 }
2626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002628 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 enforceModifyPermission();
2630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2634 logv("Shutting down Phone " + i);
2635 shutdownRadioUsingPhoneId(i);
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002639 }
2640 }
2641
2642 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002643 Phone phone = PhoneFactory.getPhone(phoneId);
2644 if (phone != null && phone.isRadioAvailable()) {
2645 phone.shutdownRadio();
2646 }
2647 }
2648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2655 if (defaultPhone != null) {
2656 defaultPhone.setRadioPower(turnOn);
2657 return true;
2658 } else {
2659 loge("There's no default phone.");
2660 return false;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002664 }
Wink Saville36469e72014-06-11 15:17:00 -07002665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 final Phone phone = getPhone(subId);
2673 if (phone != null) {
2674 phone.setRadioPower(turnOn);
2675 return true;
2676 } else {
2677 return false;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Wink Saville36469e72014-06-11 15:17:00 -07002684 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 public boolean enableDataConnectivity() {
2687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 int subId = mSubscriptionController.getDefaultDataSubId();
2692 final Phone phone = getPhone(subId);
2693 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002694 phone.getDataEnabledSettings().setDataEnabled(
2695 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 return true;
2697 } else {
2698 return false;
2699 }
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Wink Saville36469e72014-06-11 15:17:00 -07002705 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 public boolean disableDataConnectivity() {
2708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 int subId = mSubscriptionController.getDefaultDataSubId();
2713 final Phone phone = getPhone(subId);
2714 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002715 phone.getDataEnabledSettings().setDataEnabled(
2716 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 return true;
2718 } else {
2719 return false;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002727 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 final Phone phone = getPhone(subId);
2731 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002732 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 } else {
2734 return false;
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
2741 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002742 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002743 }
2744
pkanwarae03a6b2016-11-06 20:37:09 -08002745 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 enforceCallPermission();
2747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2751 return;
2752 }
2753 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2754 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
pkanwar32d516d2016-10-14 19:37:38 -07002758 };
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2766 return false;
2767 }
2768 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002774 /**
2775 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2776 * tag on getCallState Binder call.
2777 */
2778 @Deprecated
2779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002781 if (CompatChanges.isChangeEnabled(
2782 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2783 Binder.getCallingUid())) {
2784 // Do not allow this API to be called on API version 31+, it should only be
2785 // called on old apps using this Binder call directly.
2786 throw new SecurityException("This method can only be used for applications "
2787 + "targeting API version 30 or less.");
2788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002791 Phone phone = getPhone(getDefaultSubscription());
2792 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2793 PhoneConstantConversions.convertCallState(phone.getState());
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
2797 }
2798
2799 @Override
2800 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2801 if (CompatChanges.isChangeEnabled(
2802 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2803 Binder.getCallingUid())) {
2804 // Check READ_PHONE_STATE for API version 31+
2805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2806 featureId, "getCallStateForSubscription")) {
2807 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2808 + "targeting API level 31+.");
2809 }
2810 }
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2815 PhoneConstantConversions.convertCallState(phone.getState());
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002822 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002823 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2824 }
2825
2826 @Override
2827 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 if (phone != null) {
2832 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2833 } else {
2834 return PhoneConstantConversions.convertDataState(
2835 PhoneConstants.DataState.DISCONNECTED);
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002843 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002844 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2845 }
2846
2847 @Override
2848 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 final long identity = Binder.clearCallingIdentity();
2850 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 if (phone != null) {
2853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2854 } else {
2855 return TelephonyManager.DATA_ACTIVITY_NONE;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002863 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002866
2867 LocationAccessPolicy.LocationPermissionResult locationResult =
2868 LocationAccessPolicy.checkLocationPermission(mApp,
2869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2870 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002871 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002872 .setCallingPid(Binder.getCallingPid())
2873 .setCallingUid(Binder.getCallingUid())
2874 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002875 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2877 .build());
2878 switch (locationResult) {
2879 case DENIED_HARD:
2880 throw new SecurityException("Not allowed to access cell location");
2881 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002882 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2883 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002890 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002891 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
Svetoslav64fad262015-04-14 14:35:21 -07002895 }
2896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002898 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2900 // registered cell info, so return a NULL country instead.
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2904 // Get default phone in this case.
2905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002909 if (phone == null) return "";
2910 ServiceStateTracker sst = phone.getServiceStateTracker();
2911 if (sst == null) return "";
2912 LocaleTracker lt = sst.getLocaleTracker();
2913 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002914 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002918 }
2919
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002920 /**
2921 * This method was removed due to potential issues caused by performing partial
2922 * updates of service state, and lack of a credible use case.
2923 *
2924 * This has the ability to break the telephony implementation by disabling notification of
2925 * changes in device connectivity. DO NOT USE THIS!
2926 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 public void enableLocationUpdates() {
2929 mApp.enforceCallingOrSelfPermission(
2930 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002933 /**
2934 * This method was removed due to potential issues caused by performing partial
2935 * updates of service state, and lack of a credible use case.
2936 *
2937 * This has the ability to break the telephony implementation by disabling notification of
2938 * changes in device connectivity. DO NOT USE THIS!
2939 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 @Override
2941 public void disableLocationUpdates() {
2942 mApp.enforceCallingOrSelfPermission(
2943 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
2946 @Override
2947 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002948 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2949 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07002950 try {
2951 mApp.getSystemService(AppOpsManager.class)
2952 .checkPackage(Binder.getCallingUid(), callingPackage);
2953 } catch (SecurityException e) {
2954 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
2955 throw e;
2956 }
2957
Nathan Haroldf096d982020-11-18 17:18:06 -08002958 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002959 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2960 throw new SecurityException(
2961 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2962 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002963
Jordan Liu1617b712019-07-10 15:06:26 -07002964 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2966 return null;
2967 }
Svetoslav64fad262015-04-14 14:35:21 -07002968
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002969 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002971 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002972 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973
Nathan Haroldf180aac2018-06-01 18:43:55 -07002974 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2975 for (CellInfo ci : info) {
2976 if (ci instanceof CellInfoGsm) {
2977 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2978 } else if (ci instanceof CellInfoWcdma) {
2979 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002982 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 }
2984
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002985 private List<CellInfo> getCachedCellInfo() {
2986 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2987 for (Phone phone : PhoneFactory.getPhones()) {
2988 List<CellInfo> info = phone.getAllCellInfo();
2989 if (info != null) cellInfos.addAll(info);
2990 }
2991 return cellInfos;
2992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993
2994 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002995 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002997 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002998
2999 LocationAccessPolicy.LocationPermissionResult locationResult =
3000 LocationAccessPolicy.checkLocationPermission(mApp,
3001 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3002 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003003 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003004 .setCallingPid(Binder.getCallingPid())
3005 .setCallingUid(Binder.getCallingUid())
3006 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003007 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003008 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3009 .build());
3010 switch (locationResult) {
3011 case DENIED_HARD:
3012 throw new SecurityException("Not allowed to access cell info");
3013 case DENIED_SOFT:
3014 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Nathan Haroldf096d982020-11-18 17:18:06 -08003017 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003018 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3019 return getCachedCellInfo();
3020 }
3021
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003022 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3027 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003028 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003029 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 if (info != null) cellInfos.addAll(info);
3031 }
3032 return cellInfos;
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036 }
3037
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003038 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003039 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3040 String callingFeatureId) {
3041 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3042 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003043 }
3044
3045 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003046 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3047 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003048 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003049 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003050 }
3051
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003052 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3053 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003054 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003055 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003056
3057 LocationAccessPolicy.LocationPermissionResult locationResult =
3058 LocationAccessPolicy.checkLocationPermission(mApp,
3059 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3060 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003061 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003062 .setCallingPid(Binder.getCallingPid())
3063 .setCallingUid(Binder.getCallingUid())
3064 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003065 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3066 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003067 .build());
3068 switch (locationResult) {
3069 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003070 if (TelephonyPermissions
3071 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003072 // Safetynet logging for b/154934934
3073 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3074 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003075 throw new SecurityException("Not allowed to access cell info");
3076 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003077 if (TelephonyPermissions
3078 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003079 // Safetynet logging for b/154934934
3080 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3081 }
Nathan Harold5320c422019-05-09 10:26:08 -07003082 try {
3083 cb.onCellInfo(new ArrayList<CellInfo>());
3084 } catch (RemoteException re) {
3085 // Drop without consequences
3086 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003087 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003088 }
3089
Nathan Harolda939a962019-05-09 10:13:47 -07003090
3091 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003092 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3093
3094 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3095 }
3096
3097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003099 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003108 }
3109
Shishir Agrawala9f32182016-04-12 12:00:16 -07003110 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003111 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003112 Phone phone = PhoneFactory.getPhone(slotIndex);
3113 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003114 return null;
3115 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003116 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003117 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003118 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003119 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003120 return null;
3121 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 return phone.getImei();
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
3128 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003129 }
3130
3131 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003132 public String getTypeAllocationCodeForSlot(int slotIndex) {
3133 Phone phone = PhoneFactory.getPhone(slotIndex);
3134 String tac = null;
3135 if (phone != null) {
3136 String imei = phone.getImei();
3137 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3138 }
3139 return tac;
3140 }
3141
3142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003143 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003144 try {
3145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3146 } catch (SecurityException se) {
3147 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3148 throw new SecurityException("Package " + callingPackage + " does not belong to "
3149 + Binder.getCallingUid());
3150 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003151 Phone phone = PhoneFactory.getPhone(slotIndex);
3152 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003153 return null;
3154 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003155
Jeff Davidson913390f2018-02-23 17:11:49 -08003156 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003157 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003158 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003159 return null;
3160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 return phone.getMeid();
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
Jack Yu2af8d712017-03-15 17:14:14 -07003168 }
3169
3170 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003171 public String getManufacturerCodeForSlot(int slotIndex) {
3172 Phone phone = PhoneFactory.getPhone(slotIndex);
3173 String manufacturerCode = null;
3174 if (phone != null) {
3175 String meid = phone.getMeid();
3176 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3177 }
3178 return manufacturerCode;
3179 }
3180
3181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003182 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3183 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003184 Phone phone = PhoneFactory.getPhone(slotIndex);
3185 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003186 return null;
3187 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003188 int subId = phone.getSubId();
3189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003190 mApp, subId, callingPackage, callingFeatureId,
3191 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003192 return null;
3193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 return phone.getDeviceSvn();
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003201 }
3202
fionaxu43304da2017-11-27 22:51:16 -08003203 @Override
3204 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 final Phone phone = getPhone(subId);
3208 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
fionaxu43304da2017-11-27 22:51:16 -08003212 }
3213
3214 @Override
3215 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 final Phone phone = getPhone(subId);
3219 return phone == null ? null : phone.getCarrierName();
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
fionaxu43304da2017-11-27 22:51:16 -08003223 }
3224
calvinpanffe225e2018-11-01 19:43:06 +08003225 @Override
chen xu0026ca62019-03-06 15:28:50 -08003226 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = getPhone(subId);
3230 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003231 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
chen xu0026ca62019-03-06 15:28:50 -08003238 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003242 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
chen xu651eec72018-11-11 19:03:44 -08003248 @Override
chen xu864e11c2018-12-06 22:10:03 -08003249 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3250 if (!isSubscriptionMccMnc) {
3251 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3252 }
chen xu651eec72018-11-11 19:03:44 -08003253 final Phone phone = PhoneFactory.getPhone(slotIndex);
3254 if (phone == null) {
3255 return TelephonyManager.UNKNOWN_CARRIER_ID;
3256 }
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 //
3266 // Internal helper methods.
3267 //
3268
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003269 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003270 * Make sure the caller is the calling package itself
3271 *
3272 * @throws SecurityException if the caller is not the calling package
3273 */
3274 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3275 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003276 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3277 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003278 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003279 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003280 } catch (PackageManager.NameNotFoundException e) {
3281 // packageUid is -1
3282 }
3283 if (packageUid != callingUid) {
3284 throw new SecurityException(message + ": Package " + callingPackage
3285 + " does not belong to " + callingUid);
3286 }
3287 }
3288
3289 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3291 *
3292 * @throws SecurityException if the caller does not have the required permission
3293 */
3294 private void enforceModifyPermission() {
3295 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3296 }
3297
Shuo Qiancd19c462020-01-16 20:51:11 -08003298 /**
3299 * Make sure the caller is system.
3300 *
3301 * @throws SecurityException if the caller is not system.
3302 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003303 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003304 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3305 throw new SecurityException("Caller must be system");
3306 }
3307 }
3308
Shuo Qian3b6ee772019-11-13 17:43:31 -08003309 private void enforceActiveEmergencySessionPermission() {
3310 mApp.enforceCallingOrSelfPermission(
3311 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3312 }
3313
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003314 /**
3315 * Make sure the caller has the CALL_PHONE permission.
3316 *
3317 * @throws SecurityException if the caller does not have the required permission
3318 */
3319 private void enforceCallPermission() {
3320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3321 }
3322
paulhu5a773602019-08-23 19:17:33 +08003323 private void enforceSettingsPermission() {
3324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003325 }
3326
Michele Berionne5e411512020-11-13 02:36:59 +00003327 private void enforceRebootPermission() {
3328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3329 }
3330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 private String createTelUrl(String number) {
3332 if (TextUtils.isEmpty(number)) {
3333 return null;
3334 }
3335
Jake Hambye994d462014-02-03 13:10:13 -08003336 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 }
3338
Ihab Awadf9e92732013-12-05 18:02:52 -08003339 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003340 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3341 }
3342
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003343 private static void logv(String msg) {
3344 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3345 }
3346
Ihab Awadf9e92732013-12-05 18:02:52 -08003347 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3349 }
3350
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003351 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003353 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003354 }
3355
Sanket Padawe356d7632015-06-22 14:03:32 -07003356 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003357 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 final Phone phone = PhoneFactory.getPhone(slotIndex);
3361 if (phone == null) {
3362 return PhoneConstants.PHONE_TYPE_NONE;
3363 } else {
3364 return phone.getPhoneType();
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003369 }
3370
3371 /**
3372 * Returns the CDMA ERI icon index to display
3373 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003375 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3376 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3377 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003378 }
3379
Sanket Padawe356d7632015-06-22 14:03:32 -07003380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003381 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3382 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003384 mApp, subId, callingPackage, callingFeatureId,
3385 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003386 return -1;
3387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003388
3389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 final Phone phone = getPhone(subId);
3392 if (phone != null) {
3393 return phone.getCdmaEriIconIndex();
3394 } else {
3395 return -1;
3396 }
3397 } finally {
3398 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003400 }
3401
3402 /**
3403 * Returns the CDMA ERI icon mode,
3404 * 0 - ON
3405 * 1 - FLASHING
3406 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003407 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003408 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3409 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3410 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003411 }
3412
Sanket Padawe356d7632015-06-22 14:03:32 -07003413 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003414 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3415 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003417 mApp, subId, callingPackage, callingFeatureId,
3418 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003419 return -1;
3420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 return phone.getCdmaEriIconMode();
3427 } else {
3428 return -1;
3429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003433 }
3434
3435 /**
3436 * Returns the CDMA ERI text,
3437 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003439 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3440 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3441 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003442 }
3443
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003445 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3446 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003448 mApp, subId, callingPackage, callingFeatureId,
3449 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003450 return null;
3451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452
3453 final long identity = Binder.clearCallingIdentity();
3454 try {
3455 final Phone phone = getPhone(subId);
3456 if (phone != null) {
3457 return phone.getCdmaEriText();
3458 } else {
3459 return null;
3460 }
3461 } finally {
3462 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 }
3465
3466 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003467 * Returns the CDMA MDN.
3468 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003469 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003470 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3472 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 return phone.getLine1Number();
3479 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 return null;
3482 }
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003485 }
3486 }
3487
3488 /**
3489 * Returns the CDMA MIN.
3490 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003492 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3494 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 final Phone phone = getPhone(subId);
3499 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3500 return phone.getCdmaMin();
3501 } else {
3502 return null;
3503 }
3504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003506 }
3507 }
3508
Hall Liud892bec2018-11-30 14:51:45 -08003509 @Override
3510 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3511 INumberVerificationCallback callback, String callingPackage) {
3512 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3513 != PERMISSION_GRANTED) {
3514 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3515 }
3516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3517
3518 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3519 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003520 throw new SecurityException("Calling package must be configured in the device config: "
3521 + "calling package: " + callingPackage
3522 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003523 }
3524
3525 if (range == null) {
3526 throw new NullPointerException("Range must be non-null");
3527 }
3528
3529 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003530 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003531
3532 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3533 }
3534
Junda Liuca05d5d2014-08-14 22:36:34 -07003535 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 * Returns true if CDMA provisioning needs to run.
3537 */
3538 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 final long identity = Binder.clearCallingIdentity();
3540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003541 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003545 }
3546
3547 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003548 * Sets the voice mail number of a given subId.
3549 */
3550 @Override
3551 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003552 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3553 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3558 new Pair<String, String>(alphaTag, number), new Integer(subId));
3559 return success;
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003563 }
3564
Ta-wei Yen87c49842016-05-13 21:19:52 -07003565 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003566 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003568 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3569 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003570 if (!TextUtils.equals(callingPackage, systemDialer)) {
3571 throw new SecurityException("caller must be system dialer");
3572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3577 if (phoneAccountHandle == null) {
3578 return null;
3579 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003583 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003584 }
3585
3586 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3588 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003591 mApp, subId, callingPackage, callingFeatureId,
3592 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003593 return null;
3594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003596 final long identity = Binder.clearCallingIdentity();
3597 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003598 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003599 } finally {
3600 Binder.restoreCallingIdentity(identity);
3601 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003602 }
3603
3604 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003605 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3606 VisualVoicemailSmsFilterSettings settings) {
3607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003616 }
3617
3618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003619 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3620 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003625 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003629 }
3630
3631 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003632 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3633 String callingPackage, int subId) {
3634 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003643 }
3644
3645 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003646 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003647 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003656 }
3657
3658 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003659 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3660 String callingAttributionTag, int subId, String number, int port, String text,
3661 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003663 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003664 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003665 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003666 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3667 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003668 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003669
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003670 /**
fionaxu0152e512016-11-14 13:36:14 -08003671 * Sets the voice activation state of a given subId.
3672 */
3673 @Override
3674 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3676 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677
3678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 final Phone phone = getPhone(subId);
3681 if (phone != null) {
3682 phone.setVoiceActivationState(activationState);
3683 } else {
3684 loge("setVoiceActivationState fails with invalid subId: " + subId);
3685 }
3686 } finally {
3687 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003688 }
3689 }
3690
3691 /**
3692 * Sets the data activation state of a given subId.
3693 */
3694 @Override
3695 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3697 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 final Phone phone = getPhone(subId);
3702 if (phone != null) {
3703 phone.setDataActivationState(activationState);
3704 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003705 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 }
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003709 }
3710 }
3711
3712 /**
3713 * Returns the voice activation state of a given subId.
3714 */
3715 @Override
3716 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718
fionaxu0152e512016-11-14 13:36:14 -08003719 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 if (phone != null) {
3723 return phone.getVoiceActivationState();
3724 } else {
3725 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3726 }
3727 } finally {
3728 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003729 }
3730 }
3731
3732 /**
3733 * Returns the data activation state of a given subId.
3734 */
3735 @Override
3736 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
fionaxu0152e512016-11-14 13:36:14 -08003739 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 if (phone != null) {
3743 return phone.getDataActivationState();
3744 } else {
3745 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3746 }
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003749 }
3750 }
3751
3752 /**
Wink Saville36469e72014-06-11 15:17:00 -07003753 * Returns the unread count of voicemails for a subId
3754 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3757 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003759 mApp, subId, callingPackage, callingFeatureId,
3760 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003761 return 0;
3762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 final Phone phone = getPhone(subId);
3766 if (phone != null) {
3767 return phone.getVoiceMessageCount();
3768 } else {
3769 return 0;
3770 }
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003774 }
3775
3776 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003777 * returns true, if the device is in a state where both voice and data
3778 * are supported simultaneously. This can change based on location or network condition.
3779 */
3780 @Override
3781 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 final long identity = Binder.clearCallingIdentity();
3783 try {
3784 final Phone phone = getPhone(subId);
3785 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003789 }
3790
3791 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003792 * Send the dialer code if called from the current default dialer or the caller has
3793 * carrier privilege.
3794 * @param inputCode The dialer code to send
3795 */
3796 @Override
3797 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003800 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3801 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003802 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003803 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
fionaxu235cc5e2017-03-06 22:25:57 -08003813 }
3814
Pengquan Menga1bb6272018-09-06 09:59:22 -07003815 @Override
3816 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003817 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003818 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003819 mApp, subId, "getNetworkSelectionMode");
3820 final long identity = Binder.clearCallingIdentity();
3821 try {
3822 if (!isActiveSubscription(subId)) {
3823 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3824 }
3825 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003828 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003829 }
3830
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003832 public boolean isInEmergencySmsMode() {
3833 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 for (Phone phone : PhoneFactory.getPhones()) {
3837 if (phone.isInEmergencySmsMode()) {
3838 return true;
3839 }
3840 }
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
3843 }
3844 return false;
3845 }
3846
shilu366312e2019-12-17 09:28:10 -08003847 /**
3848 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3849 * @param subId The subscription to use to check the configuration.
3850 * @param c The callback that will be used to send the result.
3851 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3854 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003855 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003856 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003857
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003858 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3859 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3860 "IMS not available on device.");
3861 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003862 final long token = Binder.clearCallingIdentity();
3863 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003864 int slotId = getSlotIndexOrException(subId);
3865 verifyImsMmTelConfiguredOrThrow(slotId);
3866 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003867 } catch (ImsException e) {
3868 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 } finally {
3870 Binder.restoreCallingIdentity(token);
3871 }
3872 }
3873
shilu366312e2019-12-17 09:28:10 -08003874 /**
3875 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3876 * @param subId The subscription to use to check the configuration.
3877 * @param c The callback that will be used to send the result.
3878 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003880 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003881 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003882 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003883 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3884 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3885 }
Meng Wangafbc5852019-09-19 17:37:13 -07003886 final long token = Binder.clearCallingIdentity();
3887 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003888 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3889 .removeRegistrationCallbackForSubscription(c, subId);
3890 } catch (ImsException e) {
3891 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3892 + "is inactive, ignoring unregister.");
3893 // If the subscription is no longer active, just return, since the callback
3894 // will already have been removed internally.
3895 } finally {
3896 Binder.restoreCallingIdentity(token);
3897 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 }
3899
Brad Ebingera34a6c22019-10-22 17:36:18 -07003900 /**
3901 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3902 */
3903 @Override
3904 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3905 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3906 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3908 "IMS not available on device.");
3909 }
3910 final long token = Binder.clearCallingIdentity();
3911 try {
3912 Phone phone = getPhone(subId);
3913 if (phone == null) {
3914 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3915 + subId + "'");
3916 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3917 }
3918 phone.getImsRegistrationState(regState -> {
3919 try {
3920 consumer.accept((regState == null)
3921 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3922 } catch (RemoteException e) {
3923 // Ignore if the remote process is no longer available to call back.
3924 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3925 }
3926 });
3927 } finally {
3928 Binder.restoreCallingIdentity(token);
3929 }
3930 }
3931
3932 /**
3933 * Get the transport type for the IMS service registration state.
3934 */
3935 @Override
3936 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003937 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003938 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003939 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3941 "IMS not available on device.");
3942 }
3943 final long token = Binder.clearCallingIdentity();
3944 try {
3945 Phone phone = getPhone(subId);
3946 if (phone == null) {
3947 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3948 + subId + "'");
3949 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3950 }
3951 phone.getImsRegistrationTech(regTech -> {
3952 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3953 int regTechConverted = (regTech == null)
3954 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3955 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3956 regTechConverted);
3957 try {
3958 consumer.accept(regTechConverted);
3959 } catch (RemoteException e) {
3960 // Ignore if the remote process is no longer available to call back.
3961 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3962 }
3963 });
3964 } finally {
3965 Binder.restoreCallingIdentity(token);
3966 }
3967 }
3968
shilu366312e2019-12-17 09:28:10 -08003969 /**
3970 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3971 * @param subId The subscription to use to check the configuration.
3972 * @param c The callback that will be used to send the result.
3973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003975 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3976 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003977 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003978 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003979 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3980 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3981 "IMS not available on device.");
3982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 final long token = Binder.clearCallingIdentity();
3984 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003985 int slotId = getSlotIndexOrException(subId);
3986 verifyImsMmTelConfiguredOrThrow(slotId);
3987 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003988 } catch (ImsException e) {
3989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 } finally {
3991 Binder.restoreCallingIdentity(token);
3992 }
3993 }
3994
shilu366312e2019-12-17 09:28:10 -08003995 /**
3996 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3997 * @param subId The subscription to use to check the configuration.
3998 * @param c The callback that will be used to send the result.
3999 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004001 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004002 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004003 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4005 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4006 }
Meng Wangafbc5852019-09-19 17:37:13 -07004007
4008 final long token = Binder.clearCallingIdentity();
4009 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004010 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004011 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004012 } catch (ImsException e) {
4013 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4014 + "is inactive, ignoring unregister.");
4015 // If the subscription is no longer active, just return, since the callback
4016 // will already have been removed internally.
4017 } finally {
4018 Binder.restoreCallingIdentity(token);
4019 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 }
4021
4022 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004023 public boolean isCapable(int subId, int capability, int regTech) {
4024 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 final long token = Binder.clearCallingIdentity();
4026 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004027 int slotId = getSlotIndexOrException(subId);
4028 verifyImsMmTelConfiguredOrThrow(slotId);
4029 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004030 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4032 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004033 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004034 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4035 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(token);
4038 }
4039 }
4040
4041 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004042 public boolean isAvailable(int subId, int capability, int regTech) {
4043 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 final long token = Binder.clearCallingIdentity();
4045 try {
4046 Phone phone = getPhone(subId);
4047 if (phone == null) return false;
4048 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004049 } catch (com.android.ims.ImsException e) {
4050 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4051 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 } finally {
4053 Binder.restoreCallingIdentity(token);
4054 }
4055 }
4056
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004057 /**
4058 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4059 * subscription.
4060 * @param subId The subscription to use to check the configuration.
4061 * @param callback The callback that will be used to send the result.
4062 * @param capability The MmTelFeature capability that will be used to send the result.
4063 * @param transportType The transport type of the MmTelFeature capability.
4064 */
4065 @Override
4066 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4067 int transportType) {
4068 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4069 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4070 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4071 "IMS not available on device.");
4072 }
4073 final long token = Binder.clearCallingIdentity();
4074 try {
4075 int slotId = getSlotIndex(subId);
4076 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4077 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4078 + subId + "'");
4079 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4080 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004081 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004082 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4083 transportType, aBoolean -> {
4084 try {
4085 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4086 } catch (RemoteException e) {
4087 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4088 + "running. Ignore");
4089 }
4090 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
4096 }
4097
shilu366312e2019-12-17 09:28:10 -08004098 /**
4099 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4100 * @param subId The subscription to use to check the configuration.
4101 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 @Override
4103 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004104 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004105 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004106
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long token = Binder.clearCallingIdentity();
4108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004109 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004110 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004111 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(token);
4116 }
4117 }
4118
4119 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004120 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004122 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004125 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004126 // This setting doesn't require an active ImsService connection, so do not verify. The
4127 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004128 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004129 } catch (ImsException e) {
4130 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 } finally {
4132 Binder.restoreCallingIdentity(identity);
4133 }
4134 }
4135
shilu366312e2019-12-17 09:28:10 -08004136 /**
4137 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4138 * @param subId The subscription to use to check the configuration.
4139 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004141 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004142 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004143 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 final long identity = Binder.clearCallingIdentity();
4145 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004146 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004147 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004148 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004149 } catch (ImsException e) {
4150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
4154 }
4155
4156 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004157 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004159 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long identity = Binder.clearCallingIdentity();
4161 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004162 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004163 // This setting doesn't require an active ImsService connection, so do not verify. The
4164 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004165 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
shilu366312e2019-12-17 09:28:10 -08004173 /**
4174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004179 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004180 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004183 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004184 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004194 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long identity = Binder.clearCallingIdentity();
4198 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004200 // This setting doesn't require an active ImsService connection, so do not verify. The
4201 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
shilu366312e2019-12-17 09:28:10 -08004210 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004211 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4212 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4213 * @param subId The subscription to use to check the configuration.
4214 */
4215 @Override
4216 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004217 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004218 mApp, subId, "isCrossSimCallingEnabledByUser");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004221 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004222 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004224 } catch (ImsException e) {
4225 throw new ServiceSpecificException(e.getCode());
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
4229 }
4230
4231 /**
4232 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4233 * Requires MODIFY_PHONE_STATE permission.
4234 * @param subId The subscription to use to check the configuration.
4235 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4236 * false otherwise
4237 */
4238 @Override
4239 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4241 "setCrossSimCallingEnabled");
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004244 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004245 // This setting doesn't require an active ImsService connection, so do not verify. The
4246 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004247 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004248 } catch (ImsException e) {
4249 throw new ServiceSpecificException(e.getCode());
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
4255 /**
shilu366312e2019-12-17 09:28:10 -08004256 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4257 * @param subId The subscription to use to check the configuration.
4258 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004260
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004262 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004263 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004267 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
4276 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004277 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004279 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify. The
4284 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004285 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004286 } catch (ImsException e) {
4287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 } finally {
4289 Binder.restoreCallingIdentity(identity);
4290 }
4291 }
4292
4293 @Override
4294 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4296 "setVoWiFiNonPersistent");
4297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004300 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
4314 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004316 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 @Override
4330 public void setVoWiFiModeSetting(int subId, int mode) {
4331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4332 "setVoWiFiModeSetting");
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004336 // This setting doesn't require an active ImsService connection, so do not verify. The
4337 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 @Override
4347 public int getVoWiFiRoamingModeSetting(int subId) {
4348 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4349 final long identity = Binder.clearCallingIdentity();
4350 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004351 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004352 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004353 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004354 } catch (ImsException e) {
4355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
4359 }
4360
4361 @Override
4362 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4364 "setVoWiFiRoamingModeSetting");
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004368 // This setting doesn't require an active ImsService connection, so do not verify. The
4369 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004371 } catch (ImsException e) {
4372 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
4376 }
4377
4378 @Override
4379 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4381 "setRttCapabilityEnabled");
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004384 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004385 // This setting doesn't require an active ImsService connection, so do not verify. The
4386 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004388 } catch (ImsException e) {
4389 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
4393 }
4394
shilu366312e2019-12-17 09:28:10 -08004395 /**
4396 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4397 * @param subId The subscription to use to check the configuration.
4398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 @Override
4400 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004401 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004402 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 final long identity = Binder.clearCallingIdentity();
4404 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004405 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004406 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004408 } catch (ImsException e) {
4409 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004415 @Override
4416 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4417 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4418 final long identity = Binder.clearCallingIdentity();
4419 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004420 if (!isImsAvailableOnDevice()) {
4421 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4422 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004423 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 int slotId = getSlotIndexOrException(subId);
4425 verifyImsMmTelConfiguredOrThrow(slotId);
4426 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004427 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004428 } catch (ImsException e) {
4429 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
4433 }
4434
4435 @Override
4436 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4437 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4438 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004439 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4440 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4441 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004442 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004443 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004444 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004445 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004446 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4447 + "is inactive, ignoring unregister.");
4448 // If the subscription is no longer active, just return, since the callback will already
4449 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
4453 }
4454
allenwtsu99c623b2020-01-03 18:24:23 +08004455
4456 private void checkModifyPhoneStatePermission(int subId, String message) {
4457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4458 message);
4459 }
4460
4461 private boolean isImsProvisioningRequired(int subId, int capability,
4462 boolean isMmtelCapability) {
4463 Phone phone = getPhone(subId);
4464 if (phone == null) {
4465 loge("phone instance null for subid " + subId);
4466 return false;
4467 }
4468 if (isMmtelCapability) {
4469 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4470 return false;
4471 }
4472 } else {
4473 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4474 return false;
4475 }
4476 }
4477 return true;
4478 }
4479
4480 @Override
4481 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4482 boolean isProvisioned) {
4483 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4484
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4488 if (!isImsProvisioningRequired(subId, capability, false)) {
4489 return;
4490 }
4491
4492 // this capability requires provisioning, route to the correct API.
4493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4494 switch (capability) {
4495 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4496 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4497 ims.setEabProvisioned(isProvisioned);
4498 break;
4499 default: {
4500 throw new IllegalArgumentException("Tried to set provisioning for "
4501 + "rcs capability '" + capability + "', which does not require "
4502 + "provisioning.");
4503 }
4504 }
4505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508
4509 }
4510
4511
4512 @Override
4513 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4514 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4518 if (!isImsProvisioningRequired(subId, capability, false)) {
4519 return true;
4520 }
4521
4522 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4523 switch (capability) {
4524 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4525 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4526 return ims.isEabProvisionedOnDevice();
4527
4528 default: {
4529 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4530 + "capability '" + capability + "', which does not require "
4531 + "provisioning.");
4532 }
4533 }
4534
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
4538 }
4539
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004541 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4542 boolean isProvisioned) {
4543 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004544 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4545 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4546 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4548 }
allenwtsu99c623b2020-01-03 18:24:23 +08004549 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004553 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004554 return;
4555 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004556 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4557 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4558 loge("setImsProvisioningStatusForCapability: called for technology that does "
4559 + "not support provisioning - " + tech);
4560 return;
4561 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562
4563 // this capability requires provisioning, route to the correct API.
4564 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4565 switch (capability) {
4566 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4567 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4568 ims.setVolteProvisioned(isProvisioned);
4569 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4570 ims.setWfcProvisioned(isProvisioned);
4571 }
4572 break;
4573 }
4574 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4575 // There is currently no difference in VT provisioning type.
4576 ims.setVtProvisioned(isProvisioned);
4577 break;
4578 }
4579 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4580 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4581 // change the capability of the feature instead if needed.
4582 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4583 == isProvisioned) {
4584 // No change in provisioning.
4585 return;
4586 }
4587 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4588 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004589 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004590 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4592 + ", Exception" + e.getMessage());
4593 }
4594 break;
4595 }
4596 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004597 throw new IllegalArgumentException("Tried to set provisioning for "
4598 + "MmTel capability '" + capability + "', which does not require "
4599 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004600 }
4601 }
4602
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
4608 @Override
4609 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4610 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004611 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4612 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4613 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004614 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4615 }
4616 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4617 final long identity = Binder.clearCallingIdentity();
4618 try {
4619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004620 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 return true;
4622 }
4623
Brad Ebinger0d79c572021-04-17 15:20:49 -07004624 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4625 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4626 loge("getImsProvisioningStatusForCapability: called for technology that does "
4627 + "not support provisioning - " + tech);
4628 return true;
4629 }
4630
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4632 switch (capability) {
4633 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4634 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4635 return ims.isVolteProvisionedOnDevice();
4636 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4637 return ims.isWfcProvisionedOnDevice();
4638 }
4639 // This should never happen, since we are checking tech above to make sure it
4640 // is either LTE or IWLAN.
4641 throw new IllegalArgumentException("Invalid radio technology for voice "
4642 + "capability.");
4643 }
4644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4645 // There is currently no difference in VT provisioning type.
4646 return ims.isVtProvisionedOnDevice();
4647 }
4648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4649 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4650 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4651 }
4652 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004653 throw new IllegalArgumentException(
4654 "Tried to get provisioning for MmTel capability '" + capability
4655 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 }
4657 }
4658
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4666 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4667 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4668 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4669 }
4670 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4671 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4672 return (provisionedBits & capability) > 0;
4673 }
4674
4675 @Override
4676 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4677 boolean isProvisioned) {
4678 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4679 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4680 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4681 }
4682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4683 "setProvisioningStatusForCapability");
4684 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4685 // If the current provisioning status for capability already matches isProvisioned,
4686 // do nothing.
4687 if (((provisionedBits & capability) > 0) == isProvisioned) {
4688 return;
4689 }
4690 if (isProvisioned) {
4691 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4692 } else {
4693 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4694 }
4695 }
4696
4697 /**
4698 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4699 * technology. The bitfield should mirror the bitfield defined by
4700 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4701 */
4702 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4703 String key = getMmTelProvisioningKey(subId, tech);
4704 // Default is no capabilities are provisioned.
4705 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4706 }
4707
4708 /**
4709 * Sets the MmTel capability provisioning bitfield (defined by
4710 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4711 * technology specified.
4712 *
4713 * Note: This is a synchronous command and should not be called on UI thread.
4714 */
4715 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4716 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4717 String key = getMmTelProvisioningKey(subId, tech);
4718 editor.putInt(key, newField);
4719 editor.commit();
4720 }
4721
4722 private static String getMmTelProvisioningKey(int subId, int tech) {
4723 // resulting key is provision_ims_mmtel_{subId}_{tech}
4724 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4725 }
4726
4727 /**
4728 * Query CarrierConfig to see if the specified capability requires provisioning for the
4729 * carrier associated with the subscription id.
4730 */
4731 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4732 int capability) {
4733 CarrierConfigManager configManager = new CarrierConfigManager(context);
4734 PersistableBundle c = configManager.getConfigForSubId(subId);
4735 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004736 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004737 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4738 false);
4739 boolean requireVoiceVtProvisioning = c.getBoolean(
4740 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4741
4742 // First check to make sure that the capability requires provisioning.
4743 switch (capability) {
4744 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4745 // intentional fallthrough
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4747 if (requireVoiceVtProvisioning) {
4748 // Voice and Video requires provisioning
4749 return true;
4750 }
4751 break;
4752 }
4753 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4754 if (requireUtProvisioning) {
4755 // UT requires provisioning
4756 return true;
4757 }
4758 break;
4759 }
4760 }
4761 return false;
4762 }
4763
allenwtsu99c623b2020-01-03 18:24:23 +08004764 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4765 int capability) {
4766 CarrierConfigManager configManager = new CarrierConfigManager(context);
4767 PersistableBundle c = configManager.getConfigForSubId(subId);
4768
4769 boolean requireRcsProvisioning = c.getBoolean(
4770 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4771
4772 // First check to make sure that the capability requires provisioning.
4773 switch (capability) {
4774 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4775 // intentional fallthrough
4776 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4777 if (requireRcsProvisioning) {
4778 // OPTION or PRESENCE requires provisioning
4779 return true;
4780 }
4781 break;
4782 }
4783 }
4784 return false;
4785 }
4786
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004787 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004788 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4790 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004792 enforceReadPrivilegedPermission("getImsProvisioningInt");
4793 final long identity = Binder.clearCallingIdentity();
4794 try {
4795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004796 int slotId = getSlotIndex(subId);
4797 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4798 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4799 + subId + "' for key:" + key);
4800 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4801 }
calvinpanb5a34062021-02-08 19:59:36 +08004802 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004803 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4805 + subId + "' for key:" + key);
4806 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
4810 }
4811
4812 @Override
4813 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4815 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4816 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004817 enforceReadPrivilegedPermission("getImsProvisioningString");
4818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004821 int slotId = getSlotIndex(subId);
4822 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4823 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4824 + subId + "' for key:" + key);
4825 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4826 }
calvinpanb5a34062021-02-08 19:59:36 +08004827 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004828 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4830 + subId + "' for key:" + key);
4831 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
4835 }
4836
4837 @Override
4838 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4840 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4841 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4843 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004847 int slotId = getSlotIndex(subId);
4848 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4849 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4850 + subId + "' for key:" + key);
4851 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4852 }
calvinpanb5a34062021-02-08 19:59:36 +08004853 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4854 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004855 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004856 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
4861 }
4862
4863 @Override
4864 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4867 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4869 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004873 int slotId = getSlotIndex(subId);
4874 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4875 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4876 + subId + "' for key:" + key);
4877 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4878 }
calvinpanb5a34062021-02-08 19:59:36 +08004879 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4880 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004882 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
4887 }
4888
Brad Ebinger919631e2021-06-02 17:46:35 -07004889 /**
4890 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4891 * for the given slot ID or no ImsResolver instance has been created.
4892 * @param slotId The slot ID that the IMS service is created for.
4893 * @throws ImsException If there is no ImsService configured for this slot.
4894 */
4895 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4896 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4897 ImsFeature.FEATURE_MMTEL)) {
4898 throw new ImsException("This subscription does not support MMTEL over IMS",
4899 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4900 }
4901 }
4902
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004903 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 int slotId = SubscriptionManager.getSlotIndex(subId);
4905 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4907 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004908 }
4909 return slotId;
4910 }
4911
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 private int getSlotIndex(int subId) {
4913 int slotId = SubscriptionManager.getSlotIndex(subId);
4914 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4915 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4916 }
4917 return slotId;
4918 }
4919
Wink Saville36469e72014-06-11 15:17:00 -07004920 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004921 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004922 */
4923 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004924 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4925 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004926 try {
4927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4928 } catch (SecurityException se) {
4929 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4930 throw new SecurityException("Package " + callingPackage + " does not belong to "
4931 + Binder.getCallingUid());
4932 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004933 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004934 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004935 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004936 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004937 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004938 mApp, subId, callingPackage, callingFeatureId,
4939 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004940 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4941 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 final Phone phone = getPhone(subId);
4946 if (phone != null) {
4947 return phone.getServiceState().getDataNetworkType();
4948 } else {
4949 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4950 }
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004954 }
4955
4956 /**
4957 * Returns the data network type
4958 */
4959 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004960 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004961 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4962 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004963 }
4964
4965 /**
4966 * Returns the data network type for a subId
4967 */
4968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004969 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4970 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004972 mApp, subId, callingPackage, callingFeatureId,
4973 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004974 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4975 }
4976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 final Phone phone = getPhone(subId);
4980 if (phone != null) {
4981 return phone.getServiceState().getDataNetworkType();
4982 } else {
4983 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4984 }
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004988 }
4989
4990 /**
Wink Saville36469e72014-06-11 15:17:00 -07004991 * Returns the Voice network type for a subId
4992 */
4993 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004994 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4995 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004997 mApp, subId, callingPackage, callingFeatureId,
4998 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004999 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5000 }
5001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 final Phone phone = getPhone(subId);
5005 if (phone != null) {
5006 return phone.getServiceState().getVoiceNetworkType();
5007 } else {
5008 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5009 }
5010 } finally {
5011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005013 }
5014
5015 /**
5016 * @return true if a ICC card is present
5017 */
5018 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005019 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005020 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5021 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005022 }
5023
5024 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005025 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005026 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005028 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 final Phone phone = PhoneFactory.getPhone(slotIndex);
5032 if (phone != null) {
5033 return phone.getIccCard().hasIccCard();
5034 } else {
5035 return false;
5036 }
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005040 }
5041
5042 /**
5043 * Return if the current radio is LTE on CDMA. This
5044 * is a tri-state return value as for a period of time
5045 * the mode may be unknown.
5046 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005047 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005048 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005049 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005050 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5053 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5054 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005055 }
5056
Sanket Padawe356d7632015-06-22 14:03:32 -07005057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005058 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5059 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005060 try {
5061 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5062 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005063 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5064 }
5065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 final Phone phone = getPhone(subId);
5069 if (phone == null) {
5070 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5071 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005072 return TelephonyProperties.lte_on_cdma_device()
5073 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 }
5075 } finally {
5076 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005077 }
Wink Saville36469e72014-06-11 15:17:00 -07005078 }
5079
Wink Saville36469e72014-06-11 15:17:00 -07005080 /**
5081 * {@hide}
5082 * Returns Default subId, 0 in the case of single standby.
5083 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005084 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005085 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005086 }
5087
Shishir Agrawala9f32182016-04-12 12:00:16 -07005088 private int getSlotForDefaultSubscription() {
5089 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5090 }
5091
Wink Savilleb564aae2014-10-23 10:18:09 -07005092 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005093 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005094 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005095
Pengquan Menge92a50d2018-09-21 15:54:48 -07005096 private boolean isActiveSubscription(int subId) {
5097 return mSubscriptionController.isActiveSubId(subId);
5098 }
5099
Ihab Awadf2177b72013-11-25 13:33:23 -08005100 /**
5101 * @see android.telephony.TelephonyManager.WifiCallingChoices
5102 */
5103 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005106 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5108 getWhenToMakeWifiCallsDefaultPreference());
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
5111 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005112 }
5113
5114 /**
5115 * @see android.telephony.TelephonyManager.WifiCallingChoices
5116 */
5117 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
5125 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005126 }
5127
Sailesh Nepald1e68152013-12-12 19:08:02 -08005128 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005129 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005130 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005131 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005132
Jordan Liu4c733742019-02-28 12:03:40 -08005133 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5134 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5135 if (phoneId == -1) {
5136 throw new IllegalArgumentException("Given slot index: " + slotIndex
5137 + " does not correspond to an active phone");
5138 }
5139 return PhoneFactory.getPhone(phoneId);
5140 }
5141
Shishir Agrawal566b7612013-10-28 14:41:00 -07005142 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005143 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5144 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5146 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005148 if (DBG) {
5149 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5150 }
5151 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5152 p2);
5153 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005154
Jordan Liu4c733742019-02-28 12:03:40 -08005155
5156 @Override
5157 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5158 int slotIndex, String callingPackage, String aid, int p2) {
5159 enforceModifyPermission();
5160 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5161 if (DBG) {
5162 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5163 }
5164 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5165 callingPackage, aid, p2);
5166 }
5167
5168 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5169 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 if (TextUtils.equals(ISDR_AID, aid)) {
5173 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5175 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 if (bestComponent == null
5177 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5178 loge("The calling package is not allowed to access ISD-R.");
5179 throw new SecurityException(
5180 "The calling package is not allowed to access ISD-R.");
5181 }
Derek Tan740e1672017-06-27 14:56:27 -07005182 }
Derek Tan740e1672017-06-27 14:56:27 -07005183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005185 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5186 null /* workSource */);
5187 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 return response;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 }
5193
5194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005195 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5197 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005198 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5199 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5200 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005201
Jordan Liu4c733742019-02-28 12:03:40 -08005202 @Override
5203 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5204 enforceModifyPermission();
5205 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5206 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5207 channel);
5208 }
5209
5210 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 if (channel < 0) {
5214 return false;
5215 }
Jordan Liu4c733742019-02-28 12:03:40 -08005216 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5217 null /* workSource */);
5218 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 return success;
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005222 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223 }
5224
5225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005226 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005227 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005230 if (DBG) {
5231 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5232 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5233 + p3 + " data=" + data);
5234 }
5235 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5236 command, p1, p2, p3, data);
5237 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005238
Jordan Liu4c733742019-02-28 12:03:40 -08005239 @Override
5240 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5241 int command, int p1, int p2, int p3, String data) {
5242 enforceModifyPermission();
5243 if (DBG) {
5244 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5245 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5246 + p3 + " data=" + data);
5247 }
5248 return iccTransmitApduLogicalChannelWithPermission(
5249 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5250 data);
5251 }
5252
5253 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5254 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
5256 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005257 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 return "";
5259 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005262 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5263 null /* workSource */);
5264 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 // Append the returned status code to the end of the response payload.
5267 String s = Integer.toHexString(
5268 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5269 if (response.payload != null) {
5270 s = IccUtils.bytesToHexString(response.payload) + s;
5271 }
5272 return s;
5273 } finally {
5274 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005275 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005276 }
Jake Hambye994d462014-02-03 13:10:13 -08005277
Evan Charltonc66da362014-05-16 14:06:40 -07005278 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005279 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5280 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5282 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005284 if (DBG) {
5285 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5286 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5287 }
5288 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5289 cla, command, p1, p2, p3, data);
5290 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005291
Jordan Liu4c733742019-02-28 12:03:40 -08005292 @Override
5293 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5294 int command, int p1, int p2, int p3, String data) {
5295 enforceModifyPermission();
5296 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5297 if (DBG) {
5298 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5299 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5300 + " data=" + data);
5301 }
5302
5303 return iccTransmitApduBasicChannelWithPermission(
5304 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5305 p2, p3, data);
5306 }
5307
5308 // open APDU basic channel assuming the caller has sufficient permissions
5309 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5310 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5314 && TextUtils.equals(ISDR_AID, data)) {
5315 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005316 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5317 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 if (bestComponent == null
5319 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5320 loge("The calling package is not allowed to select ISD-R.");
5321 throw new SecurityException(
5322 "The calling package is not allowed to select ISD-R.");
5323 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005324 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005327 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5328 null /* workSource */);
5329 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 // Append the returned status code to the end of the response payload.
5332 String s = Integer.toHexString(
5333 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5334 if (response.payload != null) {
5335 s = IccUtils.bytesToHexString(response.payload) + s;
5336 }
5337 return s;
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005340 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005341 }
5342
5343 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005344 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005345 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 if (DBG) {
5352 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5353 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5354 }
5355
5356 IccIoResult response =
5357 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5358 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5359 subId);
5360
5361 if (DBG) {
5362 log("Exchange SIM_IO [R]" + response);
5363 }
5364
5365 byte[] result = null;
5366 int length = 2;
5367 if (response.payload != null) {
5368 length = 2 + response.payload.length;
5369 result = new byte[length];
5370 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5371 } else {
5372 result = new byte[length];
5373 }
5374
5375 result[length - 1] = (byte) response.sw2;
5376 result[length - 2] = (byte) response.sw1;
5377 return result;
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005380 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005381 }
5382
Nathan Haroldb3014052017-01-25 15:57:32 -08005383 /**
5384 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5385 * on a particular subscription
5386 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005387 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5388 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005390 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005391 return null;
5392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 if (appType != TelephonyManager.APPTYPE_USIM
5397 && appType != TelephonyManager.APPTYPE_SIM) {
5398 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5399 return null;
5400 }
5401 Object response = sendRequest(
5402 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5403 if (response instanceof String[]) {
5404 return (String[]) response;
5405 }
yincheng zhao2737e882019-09-06 17:06:54 -07005406 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005408 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005411 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005412 }
5413
yincheng zhao2737e882019-09-06 17:06:54 -07005414 /**
5415 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5416 * subscription.
5417 *
5418 * @param subId the id of the subscription.
5419 * @param appType the uicc app type, must be USIM or SIM.
5420 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5421 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005422 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005423 * @return number of fplmns that is successfully written to the SIM.
5424 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005425 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5426 String callingFeatureId) {
5427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5428 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005429 if (DBG) logv("no permissions for setForbiddenplmns");
5430 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5431 }
5432 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5433 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5434 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5435 }
5436 if (fplmns == null) {
5437 throw new IllegalArgumentException("Fplmn List provided is null");
5438 }
5439 for (String fplmn : fplmns) {
5440 if (!CellIdentity.isValidPlmn(fplmn)) {
5441 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5442 }
5443 }
5444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 Object response = sendRequest(
5447 CMD_SET_FORBIDDEN_PLMNS,
5448 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5449 subId);
5450 return (int) response;
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
5454 }
5455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005456 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005457 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5459 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5464 if (response.payload == null) {
5465 return "";
5466 }
Evan Charltonc66da362014-05-16 14:06:40 -07005467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 // Append the returned status code to the end of the response payload.
5469 String s = Integer.toHexString(
5470 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5471 s = IccUtils.bytesToHexString(response.payload) + s;
5472 return s;
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
Evan Charltonc66da362014-05-16 14:06:40 -07005476 }
5477
Jake Hambye994d462014-02-03 13:10:13 -08005478 /**
5479 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5480 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5481 *
5482 * @param itemID the ID of the item to read
5483 * @return the NV item as a String, or null on error.
5484 */
5485 @Override
5486 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5489 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005494 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5496 return value;
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
Jake Hambye994d462014-02-03 13:10:13 -08005500 }
5501
5502 /**
5503 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5504 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5505 *
5506 * @param itemID the ID of the item to read
5507 * @param itemValue the value to write, as a String
5508 * @return true on success; false on any failure
5509 */
5510 @Override
5511 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005512 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5519 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005520 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5522 return success;
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Jake Hambye994d462014-02-03 13:10:13 -08005526 }
5527
5528 /**
5529 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5530 * Used for device configuration by some CDMA operators.
5531 *
5532 * @param preferredRoamingList byte array containing the new PRL
5533 * @return true on success; false on any failure
5534 */
5535 @Override
5536 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5538 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539
5540 final long identity = Binder.clearCallingIdentity();
5541 try {
5542 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5543 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5544 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5545 return success;
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Jake Hambye994d462014-02-03 13:10:13 -08005549 }
5550
5551 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005552 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005553 * Used for device configuration by some CDMA operators.
5554 *
chen xu6dac5ab2018-10-26 17:39:23 -07005555 * @param slotIndex - device slot.
5556 *
Jake Hambye994d462014-02-03 13:10:13 -08005557 * @return true on success; false on any failure
5558 */
5559 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005560 public boolean resetModemConfig(int slotIndex) {
5561 Phone phone = PhoneFactory.getPhone(slotIndex);
5562 if (phone != null) {
5563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5564 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
chen xu6dac5ab2018-10-26 17:39:23 -07005566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5569 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5570 return success;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
5573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 }
chen xu6dac5ab2018-10-26 17:39:23 -07005575 return false;
5576 }
5577
5578 /**
5579 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5580 *
5581 * @param slotIndex - device slot.
5582 *
5583 * @return true on success; false on any failure
5584 */
5585 @Override
5586 public boolean rebootModem(int slotIndex) {
5587 Phone phone = PhoneFactory.getPhone(slotIndex);
5588 if (phone != null) {
5589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5590 mApp, phone.getSubId(), "rebootModem");
5591
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5595 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5596 return success;
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005602 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005603
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005604 public String[] getPcscfAddress(String apnType, String callingPackage,
5605 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5608 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005609 return new String[0];
5610 }
5611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005614 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Wink Saville36469e72014-06-11 15:17:00 -07005618 }
5619
Brad Ebinger51f743a2017-01-23 13:50:20 -08005620 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005621 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5622 * {@link #disableIms(int)}.
5623 * @param slotIndex device slot.
5624 */
5625 public void resetIms(int slotIndex) {
5626 enforceModifyPermission();
5627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (mImsResolver == null) {
5631 // may happen if the does not support IMS.
5632 return;
5633 }
5634 mImsResolver.disableIms(slotIndex);
5635 mImsResolver.enableIms(slotIndex);
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
5639 }
5640
5641 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005642 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5643 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005644 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005645 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005650 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005651 // may happen if the device does not support IMS.
5652 return;
5653 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005654 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005658 }
5659
5660 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005661 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5662 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005663 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005664 public void disableIms(int slotId) {
5665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005669 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005670 // may happen if the device does not support IMS.
5671 return;
5672 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005673 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005677 }
5678
5679 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005680 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5681 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005682 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005683 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005684 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005689 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5691 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005692 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005693 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005697 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005698 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005699 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5700 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005701 @Override
5702 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005703 enforceModifyPermission();
5704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005708 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
5714 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005715 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005716 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005717 */
5718 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5719 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005723 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005724 // may happen if the device does not support IMS.
5725 return null;
5726 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005731 }
5732
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005733 /**
5734 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005735 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 */
5737 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005743 // may happen if the device does not support IMS.
5744 return null;
5745 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005750 }
5751
Brad Ebinger884c07b2018-02-15 16:17:40 -08005752 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005753 * Sets the ImsService Package Name that Telephony will bind to.
5754 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005755 * @param slotIndex the slot ID that the ImsService should bind for.
5756 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005757 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 * @param featureTypes An integer array of feature types associated with a packageName.
5759 * @param packageName The name of the package that the current configuration will be replaced
5760 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005761 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005762 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5764 int[] featureTypes, String packageName) {
5765 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5768 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005773 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005774 // may happen if the device does not support IMS.
5775 return false;
5776 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 Map<Integer, String> featureConfig = new HashMap<>();
5778 for (int featureType : featureTypes) {
5779 featureConfig.put(featureType, packageName);
5780 }
5781 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5782 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005786 }
5787
5788 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005789 * Clears any carrier ImsService overrides for the slot index specified that were previously
5790 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5791 *
5792 * This should only be used for testing.
5793 *
5794 * @param slotIndex the slot ID that the ImsService should bind for.
5795 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5796 */
5797 @Override
5798 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5799 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5801 "clearCarrierImsServiceOverride");
5802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5803 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5804 "clearCarrierImsServiceOverride");
5805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 if (mImsResolver == null) {
5809 // may happen if the device does not support IMS.
5810 return false;
5811 }
5812 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
5816 }
5817
5818 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005820 *
5821 * @param slotId The slot that the ImsService is associated with.
5822 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5823 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005825 * @return the package name of the ImsService configuration.
5826 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5828 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005829 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005831 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5833 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 final long identity = Binder.clearCallingIdentity();
5836 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005837 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005838 // may happen if the device does not support IMS.
5839 return "";
5840 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005841 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5843 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005847 }
5848
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005849 /**
5850 * Get the MmTelFeature state associated with the requested subscription id.
5851 * @param subId The subscription that the MmTelFeature is associated with.
5852 * @param callback A callback with an integer containing the
5853 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5854 */
5855 @Override
5856 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5857 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5858 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5859 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5860 "IMS not available on device.");
5861 }
5862 final long token = Binder.clearCallingIdentity();
5863 try {
5864 int slotId = getSlotIndex(subId);
5865 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5866 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5867 + subId + "'");
5868 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5869 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005870 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005871 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5872 try {
5873 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5874 } catch (RemoteException e) {
5875 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5876 + "Ignore");
5877 }
5878 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005879 } catch (ImsException e) {
5880 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005881 } finally {
5882 Binder.restoreCallingIdentity(token);
5883 }
5884 }
5885
Daniel Brightbb5840b2021-01-12 15:48:18 -08005886 /**
5887 * Sets the ims registration state on all valid {@link Phone}s.
5888 */
5889 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891
5892 final long identity = Binder.clearCallingIdentity();
5893 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005894 // NOTE: Before S, this method only set the default phone.
5895 for (final Phone phone : PhoneFactory.getPhones()) {
5896 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5897 phone.setImsRegistrationState(registered);
5898 }
5899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Wink Saville36469e72014-06-11 15:17:00 -07005903 }
5904
5905 /**
Stuart Scott54788802015-03-30 13:18:01 -07005906 * Set the network selection mode to automatic.
5907 *
5908 */
5909 @Override
5910 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5912 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
shilufc958392020-01-20 11:36:01 -08005916 if (!isActiveSubscription(subId)) {
5917 return;
5918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005920 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5921 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
Stuart Scott54788802015-03-30 13:18:01 -07005925 }
5926
Jack Yud10cdd42020-09-28 20:28:01 -07005927 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005928 * Ask the radio to connect to the input network and change selection mode to manual.
5929 *
5930 * @param subId the id of the subscription.
5931 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5932 * the operator to attach to.
5933 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5934 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5935 * normal network selection next time.
5936 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005937 */
5938 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005939 public boolean setNetworkSelectionModeManual(
5940 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5942 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005943
5944 if (!isActiveSubscription(subId)) {
5945 return false;
5946 }
5947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 final long identity = Binder.clearCallingIdentity();
5949 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005950 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005952 if (DBG) {
5953 log("setNetworkSelectionModeManual: subId: " + subId
5954 + " operator: " + operatorInfo);
5955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005960 }
shilu84f6e8b2019-12-19 13:58:01 -08005961 /**
5962 * Get the manual network selection
5963 *
5964 * @param subId the id of the subscription.
5965 *
5966 * @return the previously saved user selected PLMN
5967 */
5968 @Override
5969 public String getManualNetworkSelectionPlmn(int subId) {
5970 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005971 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005972 mApp, subId, "getManualNetworkSelectionPlmn");
5973
5974 final long identity = Binder.clearCallingIdentity();
5975 try {
5976 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005977 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005978 }
5979
5980 final Phone phone = getPhone(subId);
5981 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005982 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005983 }
5984 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5985 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5986 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
5990 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005991
5992 /**
5993 * Scans for available networks.
5994 */
5995 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005996 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5997 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5999 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006000 LocationAccessPolicy.LocationPermissionResult locationResult =
6001 LocationAccessPolicy.checkLocationPermission(mApp,
6002 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6003 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006004 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006005 .setCallingPid(Binder.getCallingPid())
6006 .setCallingUid(Binder.getCallingUid())
6007 .setMethod("getCellNetworkScanResults")
6008 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006009 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6010 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006011 .build());
6012 switch (locationResult) {
6013 case DENIED_HARD:
6014 throw new SecurityException("Not allowed to access scan results -- location");
6015 case DENIED_SOFT:
6016 return null;
6017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018
Pengquan Menga1bb6272018-09-06 09:59:22 -07006019 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 try {
6021 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006022 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006024 } finally {
6025 Binder.restoreCallingIdentity(identity);
6026 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006027 }
6028
6029 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006030 * Get the call forwarding info, given the call forwarding reason.
6031 */
6032 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006033 public void getCallForwarding(int subId, int callForwardingReason,
6034 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006035 enforceReadPrivilegedPermission("getCallForwarding");
6036 long identity = Binder.clearCallingIdentity();
6037 try {
6038 if (DBG) {
6039 log("getCallForwarding: subId " + subId
6040 + " callForwardingReason" + callForwardingReason);
6041 }
Hall Liu27d24262020-09-18 19:04:59 -07006042
6043 Phone phone = getPhone(subId);
6044 if (phone == null) {
6045 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006046 callback.onError(
6047 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006048 } catch (RemoteException e) {
6049 // ignore
6050 }
6051 return;
6052 }
6053
6054 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6055 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6056 @Override
6057 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6058 try {
6059 callback.onCallForwardingInfoAvailable(info);
6060 } catch (RemoteException e) {
6061 // ignore
6062 }
6063 }
6064
6065 @Override
6066 public void onError(int error) {
6067 try {
6068 callback.onError(error);
6069 } catch (RemoteException e) {
6070 // ignore
6071 }
6072 }
6073 });
6074 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
6078 }
6079
6080 /**
6081 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6082 * reason, the number to forward, and the timeout before the forwarding is attempted.
6083 */
6084 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006085 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6086 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006087 enforceModifyPermission();
6088 long identity = Binder.clearCallingIdentity();
6089 try {
6090 if (DBG) {
6091 log("setCallForwarding: subId " + subId
6092 + " callForwardingInfo" + callForwardingInfo);
6093 }
Hall Liu27d24262020-09-18 19:04:59 -07006094
6095 Phone phone = getPhone(subId);
6096 if (phone == null) {
6097 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006098 callback.accept(
6099 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006100 } catch (RemoteException e) {
6101 // ignore
6102 }
6103 return;
6104 }
6105
6106 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6107 FunctionalUtils.ignoreRemoteException(callback::accept));
6108
6109 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114
6115 /**
Hall Liu27d24262020-09-18 19:04:59 -07006116 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006117 */
6118 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006119 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006120 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006121 long identity = Binder.clearCallingIdentity();
6122 try {
Hall Liu27d24262020-09-18 19:04:59 -07006123 Phone phone = getPhone(subId);
6124 if (phone == null) {
6125 try {
6126 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6127 } catch (RemoteException e) {
6128 // ignore
6129 }
6130 return;
6131 }
SongFerngWang0e767992021-03-31 22:08:45 +08006132 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6133 PersistableBundle c = configManager.getConfigForSubId(subId);
6134 boolean requireUssd = c.getBoolean(
6135 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006136
Shuo Qian4a594052020-01-23 11:59:30 -08006137 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006138 if (requireUssd) {
6139 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6140 getSubscriptionCarrierId(subId));
6141 String newUssdCommand = "";
6142 try {
6143 newUssdCommand = carrierXmlParser.getFeature(
6144 CarrierXmlParser.FEATURE_CALL_WAITING)
6145 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6146 } catch (NullPointerException e) {
6147 loge("Failed to generate USSD number" + e);
6148 }
6149 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6150 mMainThreadHandler, callback, carrierXmlParser,
6151 CarrierXmlParser.SsEntry.SSAction.QUERY);
6152 final String ussdCommand = newUssdCommand;
6153 Executors.newSingleThreadExecutor().execute(() -> {
6154 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6155 });
6156 } else {
6157 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6158 callback::accept);
6159 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6160 }
Shuo Qian4a594052020-01-23 11:59:30 -08006161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
6164 }
6165
6166 /**
Hall Liu27d24262020-09-18 19:04:59 -07006167 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006168 */
6169 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006170 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006171 enforceModifyPermission();
6172 long identity = Binder.clearCallingIdentity();
6173 try {
Hall Liu27d24262020-09-18 19:04:59 -07006174 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6175
6176 Phone phone = getPhone(subId);
6177 if (phone == null) {
6178 try {
6179 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6180 } catch (RemoteException e) {
6181 // ignore
6182 }
6183 return;
6184 }
6185
SongFerngWang0e767992021-03-31 22:08:45 +08006186 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6187 PersistableBundle c = configManager.getConfigForSubId(subId);
6188 boolean requireUssd = c.getBoolean(
6189 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006190
SongFerngWang0e767992021-03-31 22:08:45 +08006191 if (DBG) log("getCallWaitingStatus: subId " + subId);
6192 if (requireUssd) {
6193 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6194 getSubscriptionCarrierId(subId));
6195 CarrierXmlParser.SsEntry.SSAction ssAction =
6196 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6197 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6198 String newUssdCommand = "";
6199 try {
6200 newUssdCommand = carrierXmlParser.getFeature(
6201 CarrierXmlParser.FEATURE_CALL_WAITING)
6202 .makeCommand(ssAction, null);
6203 } catch (NullPointerException e) {
6204 loge("Failed to generate USSD number" + e);
6205 }
6206 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6207 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6208 final String ussdCommand = newUssdCommand;
6209 Executors.newSingleThreadExecutor().execute(() -> {
6210 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6211 });
6212 } else {
6213 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6214 FunctionalUtils.ignoreRemoteException(callback::accept));
6215
6216 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6217 }
Shuo Qian4a594052020-01-23 11:59:30 -08006218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
6221 }
6222
6223 /**
yinxub1bed742017-04-17 11:45:04 -07006224 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006225 *
yinxub1bed742017-04-17 11:45:04 -07006226 * @param subId id of the subscription
6227 * @param request contains the radio access networks with bands/channels to scan
6228 * @param messenger callback messenger for scan results or errors
6229 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006230 * @return the id of the requested scan which can be used to stop the scan.
6231 */
6232 @Override
6233 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006234 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6236 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006237 LocationAccessPolicy.LocationPermissionResult locationResult =
6238 LocationAccessPolicy.checkLocationPermission(mApp,
6239 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6240 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006241 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006242 .setCallingPid(Binder.getCallingPid())
6243 .setCallingUid(Binder.getCallingUid())
6244 .setMethod("requestNetworkScan")
6245 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006246 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6247 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006248 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006249 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006250 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6251 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006252 if (e != null) {
6253 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6254 throw e;
6255 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006256 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006257 return TelephonyScanManager.INVALID_SCAN_ID;
6258 }
6259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 }
Hall Liu912dfd32019-04-25 14:02:26 -07006261 int callingUid = Binder.getCallingUid();
6262 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 return mNetworkScanRequestTracker.startNetworkScan(
6266 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006267 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
yinxu504e1392017-04-12 16:03:22 -07006271 }
6272
Hall Liub2ac8ef2019-02-28 15:56:23 -08006273 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006274 NetworkScanRequest request, int subId, String callingPackage) {
6275 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006276 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6277 boolean hasNetworkScanPermission =
6278 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6279 == PERMISSION_GRANTED;
6280
6281 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6282 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6283 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006284 }
6285
6286 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6287 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006288 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6289 return new SecurityException("Specific channels must not be"
6290 + " scanned without location access.");
6291 }
6292 }
6293 }
6294
Hall Liub2ac8ef2019-02-28 15:56:23 -08006295 return null;
6296 }
6297
yinxu504e1392017-04-12 16:03:22 -07006298 /**
6299 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006300 *
6301 * @param subId id of the subscription
6302 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006303 */
6304 @Override
6305 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6307 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308
Hall Liu912dfd32019-04-25 14:02:26 -07006309 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310 final long identity = Binder.clearCallingIdentity();
6311 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006312 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 } finally {
6314 Binder.restoreCallingIdentity(identity);
6315 }
yinxu504e1392017-04-12 16:03:22 -07006316 }
6317
6318 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006319 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006320 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006321 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006322 */
6323 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006324 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006325 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006326 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006327 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006331 if (DBG) log("getAllowedNetworkTypesBitmask");
6332 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6333 int networkTypesBitmask = (result != null ? result[0] : -1);
6334 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6335 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006339 }
6340
6341 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006342 * Get the allowed network types for certain reason.
6343 *
6344 * @param subId the id of the subscription.
6345 * @param reason the reason the allowed network type change is taking place
6346 * @return the allowed network types.
6347 */
6348 @Override
6349 public long getAllowedNetworkTypesForReason(int subId,
6350 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006351 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006352 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
6359 }
6360
6361 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006362 * Enable/Disable E-UTRA-NR Dual Connectivity
6363 * @param subId subscription id of the sim card
6364 * @param nrDualConnectivityState expected NR dual connectivity state
6365 * This can be passed following states
6366 * <ol>
6367 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6368 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6369 * <li>Disable NR dual connectivity and force secondary cell to be released
6370 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6371 * </ol>
6372 * @return operation result.
6373 */
6374 @Override
6375 public int setNrDualConnectivityState(int subId,
6376 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6378 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006379 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006380 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6381 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6382 }
6383
Sooraj Sasindran37444802020-08-11 10:40:43 -07006384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6388 nrDualConnectivityState, subId,
6389 workSource);
6390 if (DBG) log("enableNRDualConnectivity result: " + result);
6391 return result;
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
6395 }
6396
6397 /**
6398 * Is E-UTRA-NR Dual Connectivity enabled
6399 * @return true if dual connectivity is enabled else false
6400 */
6401 @Override
6402 public boolean isNrDualConnectivityEnabled(int subId) {
6403 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006404 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006405 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006406 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006407 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6408 return false;
6409 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6414 null, subId, workSource);
6415 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6416 return isEnabled;
6417 } finally {
6418 Binder.restoreCallingIdentity(identity);
6419 }
6420 }
6421
6422 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006423 * Set the allowed network types of the device and
6424 * provide the reason triggering the allowed network change.
6425 *
6426 * @param subId the id of the subscription.
6427 * @param reason the reason the allowed network type change is taking place
6428 * @param allowedNetworkTypes the allowed network types.
6429 * @return true on success; false on any failure.
6430 */
6431 @Override
6432 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006433 @TelephonyManager.AllowedNetworkTypesReason int reason,
6434 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6436 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006437 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006438 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6439 return false;
6440 }
6441 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6442 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006443 return false;
6444 }
6445
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006446 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6447 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6448
6449
6450 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6451 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6452 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006453 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006454
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006455 final long identity = Binder.clearCallingIdentity();
6456 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006457 Boolean success = (Boolean) sendRequest(
6458 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6459 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6460
6461 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6462 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 /**
Miaoa84611c2019-03-15 09:21:10 +08006469 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006470 *
Miaoa84611c2019-03-15 09:21:10 +08006471 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006472 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006473 * @hide
6474 */
6475 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006476 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006479 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 try {
Miaoa84611c2019-03-15 09:21:10 +08006481 if (phone != null) {
6482 return phone.hasMatchedTetherApnSetting();
6483 } else {
6484 return false;
6485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006486 } finally {
6487 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006488 }
Junda Liu475951f2014-11-07 16:45:03 -08006489 }
6490
6491 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006492 * Enable or disable always reporting signal strength changes from radio.
6493 *
6494 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6495 */
6496 @Override
6497 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6498 enforceModifyPermission();
6499 enforceSystemCaller();
6500
6501 final long identity = Binder.clearCallingIdentity();
6502 final Phone phone = getPhone(subId);
6503 try {
6504 if (phone != null) {
6505 if (DBG) {
6506 log("setAlwaysReportSignalStrength: subId=" + subId
6507 + " isEnable=" + isEnable);
6508 }
6509 phone.setAlwaysReportSignalStrength(isEnable);
6510 } else {
6511 loge("setAlwaysReportSignalStrength: no phone found for subId="
6512 + subId);
6513 }
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
6517 }
6518
6519 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006520 * Get the user enabled state of Mobile Data.
6521 *
6522 * TODO: remove and use isUserDataEnabled.
6523 * This can't be removed now because some vendor codes
6524 * calls through ITelephony directly while they should
6525 * use TelephonyManager.
6526 *
6527 * @return true on enabled
6528 */
6529 @Override
6530 public boolean getDataEnabled(int subId) {
6531 return isUserDataEnabled(subId);
6532 }
6533
6534 /**
6535 * Get whether mobile data is enabled per user setting.
6536 *
6537 * There are other factors deciding whether mobile data is actually enabled, but they are
6538 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006539 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006540 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006541 *
6542 * @return {@code true} if data is enabled else {@code false}
6543 */
6544 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006545 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006546 try {
6547 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6548 null);
6549 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6551 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006552 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553
6554 final long identity = Binder.clearCallingIdentity();
6555 try {
6556 int phoneId = mSubscriptionController.getPhoneId(subId);
6557 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6558 Phone phone = PhoneFactory.getPhone(phoneId);
6559 if (phone != null) {
6560 boolean retVal = phone.isUserDataEnabled();
6561 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6562 return retVal;
6563 } else {
6564 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6565 return false;
6566 }
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006569 }
6570 }
6571
6572 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006573 * Checks if the device is capable of mobile data by considering whether whether the
6574 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6575 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006576 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006577 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006578 */
6579 @Override
6580 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006581 try {
6582 try {
6583 mApp.enforceCallingOrSelfPermission(
6584 android.Manifest.permission.ACCESS_NETWORK_STATE,
6585 null);
6586 } catch (Exception e) {
6587 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6588 "isDataEnabled");
6589 }
6590 } catch (Exception e) {
6591 enforceReadPrivilegedPermission("isDataEnabled");
6592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 int phoneId = mSubscriptionController.getPhoneId(subId);
6597 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6598 Phone phone = PhoneFactory.getPhone(phoneId);
6599 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006600 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6602 return retVal;
6603 } else {
6604 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6605 return false;
6606 }
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006609 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006610 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006611
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006612 /**
6613 * Check if data is enabled for a specific reason
6614 * @param subId Subscription index
6615 * @param reason the reason the data enable change is taking place
6616 * @return {@code true} if the overall data is enabled; {@code false} if not.
6617 */
6618 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006619 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006620 @TelephonyManager.DataEnabledReason int reason) {
6621 try {
6622 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6623 null);
6624 } catch (Exception e) {
6625 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006626 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006627 }
6628
6629
6630 final long identity = Binder.clearCallingIdentity();
6631 try {
6632 int phoneId = mSubscriptionController.getPhoneId(subId);
6633 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 + " reason=" + reason);
6636 }
6637 Phone phone = PhoneFactory.getPhone(phoneId);
6638 if (phone != null) {
6639 boolean retVal;
6640 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6641 retVal = phone.isUserDataEnabled();
6642 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006643 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006644 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006645 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006646 return retVal;
6647 } else {
6648 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006649 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006650 + subId + " retVal=false");
6651 }
6652 return false;
6653 }
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
6657 }
6658
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006659 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006660 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006661 if (uid == Process.PHONE_UID) {
6662 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6663 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006664 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6665 }
6666
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006667 //load access rules from carrier configs, and check those as well: b/139133814
6668 SubscriptionController subController = SubscriptionController.getInstance();
6669 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6670 || subController == null) return privilegeFromSim;
6671
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006672 PackageManager pkgMgr = phone.getContext().getPackageManager();
6673 String[] packages = pkgMgr.getPackagesForUid(uid);
6674
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006677 int subId = phone.getSubId();
6678 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6679 // A test override is in place for the privileges for this subId, so don't try to
6680 // read the subscription privileges.
6681 return privilegeFromSim;
6682 }
6683 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006684 SubscriptionManager subManager = (SubscriptionManager)
6685 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6686 for (String pkg : packages) {
6687 if (subManager.canManageSubscription(subInfo, pkg)) {
6688 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6689 }
6690 }
6691 return privilegeFromSim;
6692 } finally {
6693 Binder.restoreCallingIdentity(identity);
6694 }
6695 }
6696
6697 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6698 String pkgName) {
6699 //load access rules from carrier configs, and check those as well: b/139133814
6700 SubscriptionController subController = SubscriptionController.getInstance();
6701 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6702 || subController == null) return privilegeFromSim;
6703
6704 final long identity = Binder.clearCallingIdentity();
6705 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006706 int subId = phone.getSubId();
6707 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6708 // A test override is in place for the privileges for this subId, so don't try to
6709 // read the subscription privileges.
6710 return privilegeFromSim;
6711 }
6712 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006713 SubscriptionManager subManager = (SubscriptionManager)
6714 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6715 return subManager.canManageSubscription(subInfo, pkgName)
6716 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
6719 }
6720 }
6721
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006722 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006723 public int getCarrierPrivilegeStatus(int subId) {
6724 final Phone phone = getPhone(subId);
6725 if (phone == null) {
6726 loge("getCarrierPrivilegeStatus: Invalid subId");
6727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6728 }
6729 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006730 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006731 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006732 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6733 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006734
6735 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6736 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006737 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006738 }
Junda Liu29340342014-07-10 15:23:27 -07006739
6740 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006742 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 final Phone phone = getPhone(subId);
6744 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006745 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6747 }
6748 UiccProfile profile =
6749 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6750 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006751 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6753 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006755 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006756 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 }
6758
6759 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006760 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006761 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006762 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006764 }
6765
6766 int phoneId = SubscriptionManager.getPhoneId(subId);
6767 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006768 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006769 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6771 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6773 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6774 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006775 }
6776
6777 @Override
6778 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006779 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006780 if (TextUtils.isEmpty(pkgName))
6781 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006782 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6783 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6784 UiccCard card = UiccController.getInstance().getUiccCard(i);
6785 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006786 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006787 continue;
6788 }
6789
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006790 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6791 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6792 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006793 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6794 break;
6795 }
6796 }
6797
6798 return result;
Junda Liu29340342014-07-10 15:23:27 -07006799 }
Derek Tan89e89d42014-07-08 17:00:10 -07006800
6801 @Override
Junda Liue64de782015-04-16 17:19:16 -07006802 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006803 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006804 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6805 loge("phoneId " + phoneId + " is not valid.");
6806 return null;
6807 }
6808 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006809 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006810 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006811 return null ;
6812 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006814 }
6815
Amith Yamasani6e118872016-02-19 12:53:51 -08006816 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006817 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006818 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006819 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006820 List<String> privilegedPackages = new ArrayList<>();
6821 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006822 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6823 // has UICC in that slot.
6824 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006825 if (card.hasCarrierPrivilegeRules()) {
6826 if (packages == null) {
6827 // Only check packages in user 0 for now
6828 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006829 PackageManager.MATCH_DISABLED_COMPONENTS
6830 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006831 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006832 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006833 }
6834 for (int p = packages.size() - 1; p >= 0; p--) {
6835 PackageInfo pkgInfo = packages.get(p);
6836 if (pkgInfo != null && pkgInfo.packageName != null
6837 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006838 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006839 privilegedPackages.add(pkgInfo.packageName);
6840 }
6841 }
6842 }
6843 }
6844 return privilegedPackages;
6845 }
6846
chen xuf7e9fe82019-05-09 19:31:02 -07006847 @Override
6848 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006849 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6850
6851 final long identity = Binder.clearCallingIdentity();
6852
chen xuf7e9fe82019-05-09 19:31:02 -07006853 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006854 try {
6855 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6856 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6857 }
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006860 }
6861 return privilegedPackages;
6862 }
6863
Wink Savilleb564aae2014-10-23 10:18:09 -07006864 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006865 final Phone phone = getPhone(subId);
6866 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006867 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006868 return null;
6869 }
6870 String iccId = card.getIccId();
6871 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006872 return null;
6873 }
6874 return iccId;
6875 }
6876
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006877 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006878 public void setCallComposerStatus(int subId, int status) {
6879 enforceModifyPermission();
6880
6881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 Phone phone = getPhone(subId);
6884 if (phone != null) {
6885 Phone defaultPhone = phone.getImsPhone();
6886 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6887 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6888 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006889 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6890 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006891 }
6892 }
Shuo Qian284ae752020-12-22 19:10:14 -08006893 } catch (ImsException e) {
6894 throw new ServiceSpecificException(e.getCode());
6895 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
6900 @Override
6901 public int getCallComposerStatus(int subId) {
6902 enforceReadPrivilegedPermission("getCallComposerStatus");
6903
6904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = getPhone(subId);
6907 if (phone != null) {
6908 Phone defaultPhone = phone.getImsPhone();
6909 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6910 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6911 return imsPhone.getCallComposerStatus();
6912 }
6913 }
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
6917 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6918 }
6919
6920 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006921 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6922 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006923 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006924 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 final String iccId = getIccId(subId);
6929 final Phone phone = getPhone(subId);
6930 if (phone == null) {
6931 return false;
6932 }
6933 final String subscriberId = phone.getSubscriberId();
6934
6935 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006936 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 + subscriberId + " to " + number);
6938 }
6939
6940 if (TextUtils.isEmpty(iccId)) {
6941 return false;
6942 }
6943
6944 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6945
6946 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6947 if (alphaTag == null) {
6948 editor.remove(alphaTagPrefKey);
6949 } else {
6950 editor.putString(alphaTagPrefKey, alphaTag);
6951 }
6952
6953 // Record both the line number and IMSI for this ICCID, since we need to
6954 // track all merged IMSIs based on line number
6955 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6956 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6957 if (number == null) {
6958 editor.remove(numberPrefKey);
6959 editor.remove(subscriberPrefKey);
6960 } else {
6961 editor.putString(numberPrefKey, number);
6962 editor.putString(subscriberPrefKey, subscriberId);
6963 }
6964
6965 editor.commit();
6966 return true;
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006969 }
Derek Tan7226c842014-07-02 17:42:23 -07006970 }
6971
6972 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006973 public String getLine1NumberForDisplay(int subId, String callingPackage,
6974 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006975 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006977 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006978 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006979 return null;
6980 }
Derek Tan97ebb422014-09-05 16:55:38 -07006981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 String iccId = getIccId(subId);
6985 if (iccId != null) {
6986 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6987 if (DBG_MERGE) {
6988 log("getLine1NumberForDisplay returning "
6989 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6990 }
6991 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6994 return null;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006997 }
Derek Tan7226c842014-07-02 17:42:23 -07006998 }
6999
7000 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007001 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7002 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007004 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007005 return null;
7006 }
Derek Tan97ebb422014-09-05 16:55:38 -07007007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
7010 String iccId = getIccId(subId);
7011 if (iccId != null) {
7012 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7013 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7014 }
7015 return null;
7016 } finally {
7017 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007018 }
Derek Tan7226c842014-07-02 17:42:23 -07007019 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007020
7021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007022 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7023 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007024 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7025 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007027 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007028 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007029 return null;
7030 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007031
Jordan Liub49b04b2019-05-06 14:45:15 -07007032 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7033 // the process, where TelephonyManager was instantiated.
7034 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007035 final long identity = Binder.clearCallingIdentity();
7036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007037 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 final TelephonyManager tele = TelephonyManager.from(context);
7039 final SubscriptionManager sub = SubscriptionManager.from(context);
7040
7041 // Figure out what subscribers are currently active
7042 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043
Jordan Liub49b04b2019-05-06 14:45:15 -07007044 // Only consider subs which match the current subId
7045 // This logic can be simplified. See b/131189269 for progress.
7046 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007047 activeSubscriberIds.add(tele.getSubscriberId(subId));
7048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049
7050 // First pass, find a number override for an active subscriber
7051 String mergeNumber = null;
7052 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7053 for (String key : prefs.keySet()) {
7054 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7055 final String subscriberId = (String) prefs.get(key);
7056 if (activeSubscriberIds.contains(subscriberId)) {
7057 final String iccId = key.substring(
7058 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7059 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7060 mergeNumber = (String) prefs.get(numberKey);
7061 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007062 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 + " for active subscriber " + subscriberId);
7064 }
7065 if (!TextUtils.isEmpty(mergeNumber)) {
7066 break;
7067 }
7068 }
7069 }
7070 }
7071
7072 // Shortcut when no active merged subscribers
7073 if (TextUtils.isEmpty(mergeNumber)) {
7074 return null;
7075 }
7076
7077 // Second pass, find all subscribers under that line override
7078 final ArraySet<String> result = new ArraySet<>();
7079 for (String key : prefs.keySet()) {
7080 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7081 final String number = (String) prefs.get(key);
7082 if (mergeNumber.equals(number)) {
7083 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7084 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7085 final String subscriberId = (String) prefs.get(subscriberKey);
7086 if (!TextUtils.isEmpty(subscriberId)) {
7087 result.add(subscriberId);
7088 }
7089 }
7090 }
7091 }
7092
7093 final String[] resultArray = result.toArray(new String[result.size()]);
7094 Arrays.sort(resultArray);
7095 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007096 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7098 }
7099 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007100 } finally {
7101 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007102 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007103 }
7104
7105 @Override
zoey chen38003472019-12-13 17:16:31 +08007106 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7107 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 final TelephonyManager telephonyManager = mApp.getSystemService(
7112 TelephonyManager.class);
7113 String subscriberId = telephonyManager.getSubscriberId(subId);
7114 if (subscriberId == null) {
7115 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007116 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007117 + subId);
7118 }
7119 return null;
7120 }
7121
7122 final SubscriptionInfo info = SubscriptionController.getInstance()
7123 .getSubscriptionInfo(subId);
7124 final ParcelUuid groupUuid = info.getGroupUuid();
7125 // If it doesn't belong to any group, return just subscriberId of itself.
7126 if (groupUuid == null) {
7127 return new String[]{subscriberId};
7128 }
7129
7130 // Get all subscriberIds from the group.
7131 final List<String> mergedSubscriberIds = new ArrayList<>();
7132 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007133 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007134 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007135 for (SubscriptionInfo subInfo : groupInfos) {
7136 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7137 if (subscriberId != null) {
7138 mergedSubscriberIds.add(subscriberId);
7139 }
7140 }
7141
7142 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145
7146 }
7147 }
7148
7149 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007150 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007151 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007152 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 final Phone phone = getPhone(subId);
7157 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
7160 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007161 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007162
7163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007164 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007165 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7166 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007167 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7168 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 final Phone phone = getPhone(subId);
7173 if (phone == null) {
7174 return false;
7175 }
7176 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7177 cdmaNonRoamingList);
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007180 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007181 }
7182
7183 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007184 @Deprecated
7185 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7186 enforceModifyPermission();
7187
7188 int returnValue = 0;
7189 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007190 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007191 if(result.exception == null) {
7192 if (result.result != null) {
7193 byte[] responseData = (byte[])(result.result);
7194 if(responseData.length > oemResp.length) {
7195 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7196 responseData.length + "bytes. Buffer Size is " +
7197 oemResp.length + "bytes.");
7198 }
7199 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7200 returnValue = responseData.length;
7201 }
7202 } else {
7203 CommandException ex = (CommandException) result.exception;
7204 returnValue = ex.getCommandError().ordinal();
7205 if(returnValue > 0) returnValue *= -1;
7206 }
7207 } catch (RuntimeException e) {
7208 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7209 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7210 if(returnValue > 0) returnValue *= -1;
7211 }
7212
7213 return returnValue;
7214 }
7215
7216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007217 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007218 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007219 try {
7220 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007221 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007222 mApp, phone.getSubId(), "getRadioAccessFamily");
7223 } catch (SecurityException e) {
7224 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7225 throw e;
7226 }
chen xub97461a2018-10-26 14:17:57 -07007227 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007229 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 final long identity = Binder.clearCallingIdentity();
7232 try {
chen xub97461a2018-10-26 14:17:57 -07007233 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007234 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007235 mApp, phone.getSubId(), "getRadioAccessFamily");
7236 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239 }
chen xub97461a2018-10-26 14:17:57 -07007240 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007241 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007242
7243 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007244 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007245 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007246 try {
7247 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7248 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007249 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007250 }
7251 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007252 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007253 }
7254 RoleManager rm = mApp.getSystemService(RoleManager.class);
7255 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7256 if (!dialerRoleHolders.contains(callingPackage)) {
7257 throw new SecurityException("App must be the dialer role holder to"
7258 + " upload a call composer pic");
7259 }
7260
7261 Executors.newSingleThreadExecutor().execute(() -> {
7262 ByteArrayOutputStream output = new ByteArrayOutputStream(
7263 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7264 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7265 boolean readUntilEnd = false;
7266 int totalBytesRead = 0;
7267 byte[] buffer = new byte[16 * 1024];
7268 while (true) {
7269 int numRead;
7270 try {
7271 numRead = input.read(buffer);
7272 } catch (IOException e) {
7273 try {
7274 fd.checkError();
7275 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7276 null);
7277 } catch (IOException e1) {
7278 // This means that the other side closed explicitly with an error. If this
7279 // happens, log and ignore.
7280 loge("Remote end of call composer picture pipe closed: " + e1);
7281 }
7282 break;
7283 }
7284 if (numRead == -1) {
7285 readUntilEnd = true;
7286 break;
7287 }
7288 totalBytesRead += numRead;
7289 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7290 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7291 try {
7292 input.close();
7293 } catch (IOException e) {
7294 // ignore
7295 }
7296 break;
7297 }
7298 output.write(buffer, 0, numRead);
7299 }
7300 // Generally, the remote end will close the file descriptors. The only case where we
7301 // close is above, where the picture size is too big.
7302
7303 try {
7304 fd.checkError();
7305 } catch (IOException e) {
7306 loge("Remote end for call composer closed with an error: " + e);
7307 return;
7308 }
7309
Hall Liuaa4211e2021-01-20 15:43:39 -08007310 if (!readUntilEnd) {
7311 loge("Did not finish reading entire image; aborting");
7312 return;
7313 }
Hall Liu82694d52020-12-11 18:22:04 -08007314
Hall Liuaa4211e2021-01-20 15:43:39 -08007315 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7316 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7317 new CallComposerPictureTransfer.Factory() {},
7318 imageData,
7319 (result) -> {
7320 if (result.first != null) {
7321 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7322 Bundle outputResult = new Bundle();
7323 outputResult.putParcelable(
7324 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7325 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7326 outputResult);
7327 } else {
7328 callback.send(result.second, null);
7329 }
7330 }
7331 );
Hall Liu82694d52020-12-11 18:22:04 -08007332 });
7333 }
7334
7335 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007336 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007338 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 ImsManager.getInstance(defaultPhone.getContext(),
7343 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007347 }
7348
7349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7353 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007354 return false;
7355 }
Svet Ganovb320e182015-04-16 12:30:10 -07007356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 final long identity = Binder.clearCallingIdentity();
7358 try {
7359 // Check the user preference and the system-level IMS setting. Even if the user has
7360 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7361 // In the long run, we may instead need to check if there exists a connection service
7362 // which can support video calling.
7363 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 return imsManager.isVtEnabledByPlatform()
7366 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7367 && imsManager.isVtEnabledByUser();
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007371 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007372
Andrew Leea1239f22015-03-02 17:44:07 -08007373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7375 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007377 mApp, subId, callingPackage, callingFeatureId,
7378 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 return false;
7380 }
7381
7382 final long identity = Binder.clearCallingIdentity();
7383 try {
7384 CarrierConfigManager configManager =
7385 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
Andrew Leea1239f22015-03-02 17:44:07 -08007391 }
7392
7393 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007394 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 return false;
7398 }
7399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 CarrierConfigManager configManager =
7403 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007404 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
7408 }
Andrew Leea1239f22015-03-02 17:44:07 -08007409 }
7410
Andrew Lee9431b832015-03-09 18:46:45 -07007411 @Override
7412 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007413 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007414 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007415 }
7416
7417 @Override
7418 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
Andrew Lee9431b832015-03-09 18:46:45 -07007425 }
7426
Hall Liuf6668912018-10-31 17:05:23 -07007427 /**
7428 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7429 * support for the feature and device firmware support.
7430 *
7431 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7432 */
7433 @Override
7434 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 final Phone phone = getPhone(subscriptionId);
7437 if (phone == null) {
7438 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7439 return false;
7440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7444 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 return isCarrierSupported && isDeviceSupported;
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Hall Liu98187582018-01-22 19:15:32 -08007450 }
7451
Hall Liuf6668912018-10-31 17:05:23 -07007452 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007453 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7454 * RTT setting, will return true if the device and carrier both support RTT.
7455 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007456 */
7457 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 final long identity = Binder.clearCallingIdentity();
7459 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007460 boolean isRttSupported = isRttSupported(subscriptionId);
7461 boolean isUserRttSettingOn = Settings.Secure.getInt(
7462 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7463 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7464 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7465 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007469 }
7470
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 @Deprecated
7472 @Override
7473 public String getDeviceId(String callingPackage) {
7474 return getDeviceIdWithFeature(callingPackage, null);
7475 }
7476
Sanket Padawe7310cc72015-01-14 09:53:20 -08007477 /**
7478 * Returns the unique device ID of phone, for example, the IMEI for
7479 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7480 *
7481 * <p>Requires Permission:
7482 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7483 */
7484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007486 try {
7487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7488 } catch (SecurityException se) {
7489 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7490 throw new SecurityException("Package " + callingPackage + " does not belong to "
7491 + Binder.getCallingUid());
7492 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007493 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007494 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 return null;
7496 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007497 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007498 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007500 return null;
7501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 return phone.getDeviceId();
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007509 }
7510
Ping Sunc67b7c22016-03-02 19:16:45 +08007511 /**
7512 * {@hide}
7513 * Returns the IMS Registration Status on a particular subid
7514 *
7515 * @param subId
7516 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007517 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007518 Phone phone = getPhone(subId);
7519 if (phone != null) {
7520 return phone.isImsRegistered();
7521 } else {
7522 return false;
7523 }
7524 }
7525
Santos Cordon7a1885b2015-02-03 11:15:19 -08007526 @Override
7527 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007534 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007535
Tyler Gunnf70ed162019-04-03 15:28:53 -07007536 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007537 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007541 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7542 }
7543 final long identity = Binder.clearCallingIdentity();
7544 try {
7545 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
7549 }
7550
7551 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007552 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007553 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007554 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007555 mApp,
7556 subscriptionId,
7557 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 Phone phone = getPhone(subscriptionId);
7561 if (phone == null) {
7562 return null;
7563 }
7564 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
7568 }
7569
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007570 /**
7571 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007572 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007573 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = getPhone(subId);
7577 if (phone != null) {
7578 return phone.isWifiCallingEnabled();
7579 } else {
7580 return false;
7581 }
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007584 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007585 }
7586
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007587 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007588 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007589 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007590 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 Phone phone = getPhone(subId);
7594 if (phone != null) {
7595 return phone.isVideoEnabled();
7596 } else {
7597 return false;
7598 }
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007601 }
7602 }
7603
7604 /**
7605 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7606 * defined in {@link ImsRegistrationImplBase}.
7607 */
7608 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = getPhone(subId);
7612 if (phone != null) {
7613 return phone.getImsRegistrationTech();
7614 } else {
7615 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7616 }
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007619 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007620 }
7621
Stuart Scott8eef64f2015-04-08 15:13:54 -07007622 @Override
7623 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007624 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007625 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7626 return;
7627 }
Kai Shif70f46f2021-03-03 13:59:46 -08007628 Phone defaultPhone = getDefaultPhone();
7629 if (defaultPhone != null) {
7630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7631 mApp, getDefaultPhone().getSubId(), "factoryReset");
7632 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007633 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007634
Svet Ganovcc087f82015-05-12 20:35:54 -07007635 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007636 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7637 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007638 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007639 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007640 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007641 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007642 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007644 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007645 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007646 // There has been issues when Sms raw table somehow stores orphan
7647 // fragments. They lead to garbled message when new fragments come
7648 // in and combined with those stale ones. In case this happens again,
7649 // user can reset all network settings which will clean up this table.
7650 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007651 // Clean up IMS settings as well here.
7652 int slotId = getSlotIndex(subId);
7653 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7654 ImsManager.getInstance(mApp, slotId).factoryReset();
7655 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007656
Kai Shif70f46f2021-03-03 13:59:46 -08007657 if (defaultPhone == null) {
7658 return;
7659 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007660 // Erase modem config if erase modem on network setting is enabled.
7661 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7662 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7663 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007664 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007665 }
Kai Shif70f46f2021-03-03 13:59:46 -08007666
7667 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007668 } finally {
7669 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007670 }
7671 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007672
SongFerngWangfd89b102021-05-27 22:44:54 +08007673 @VisibleForTesting
7674 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7675 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7676 return;
7677 }
7678 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7679 RILConstants.PREFERRED_NETWORK_MODE);
7680 SubscriptionManager.setSubscriptionProperty(subId,
7681 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7682 "user=" + defaultNetworkType);
7683 phone.loadAllowedNetworksFromSubscriptionDatabase();
7684 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7685 defaultNetworkType, null);
7686 }
7687
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007688 private void cleanUpSmsRawTable(Context context) {
7689 ContentResolver resolver = context.getContentResolver();
7690 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7691 resolver.delete(uri, null, null);
7692 }
7693
Narayan Kamath1c496c22015-04-16 14:40:19 +01007694 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007695 public String getSimLocaleForSubscriber(int subId) {
7696 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7697 final Phone phone = getPhone(subId);
7698 if (phone == null) {
7699 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007700 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 final long identity = Binder.clearCallingIdentity();
7703 try {
chen xu5d3637b2019-01-21 23:31:38 -08007704 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007705 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007706 if (info == null) {
7707 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7708 return null;
7709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 // Try and fetch the locale from the carrier properties or from the SIM language
7711 // preferences (EF-PL and EF-LI)...
7712 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007714 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7715 if (localeFromDefaultSim != null) {
7716 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7717 if (DBG) log("Using locale from subId: " + subId + " locale: "
7718 + localeFromDefaultSim);
7719 return localeFromDefaultSim.toLanguageTag();
7720 } else {
7721 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 }
7723 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 // The SIM language preferences only store a language (e.g. fr = French), not an
7726 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7727 // the SIM and carrier preferences does not include a country we add the country
7728 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007729 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007731 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 return mccLocale.toLanguageTag();
7733 }
7734
7735 if (DBG) log("No locale found - returning null");
7736 return null;
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
7739 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007740 }
7741
7742 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007743 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007744 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007745 }
7746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 /**
7748 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7749 */
7750 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007751 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007752 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007753 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007754
Chenjie Yu1ba97252018-01-11 18:16:20 -08007755 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007756 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007757
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007758 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007759 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7760 * representing the state of the modem.
7761 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007762 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7763 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007764 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007765 */
7766 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007767 public void requestModemActivityInfo(ResultReceiver result) {
7768 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007769 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770
7771 final long identity = Binder.clearCallingIdentity();
7772 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007773 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 } finally {
7775 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007776 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007777 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007778
Siddharth Rayb8114062018-06-17 15:02:38 -07007779 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7780 // less than total activity duration.
7781 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7782 if (info == null) {
7783 return false;
7784 }
7785 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007786 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7787 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7788
Siddharth Rayb8114062018-06-17 15:02:38 -07007789 return (info.isValid()
7790 && (info.getSleepTimeMillis() <= activityDurationMs)
7791 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007792 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007793 && (totalTxTimeMs <= activityDurationMs));
7794 }
7795
Jack Yu85bd38a2015-11-09 11:34:32 -08007796 /**
7797 * {@hide}
7798 * Returns the service state information on specified subscription.
7799 */
7800 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007801 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7802 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007804 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007805 return null;
7806 }
7807
Hall Liuf19c44f2018-11-27 14:38:17 -08007808 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
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 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007818 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7819 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007820 .build());
7821
7822 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7823 LocationAccessPolicy.checkLocationPermission(mApp,
7824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7825 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007827 .setCallingPid(Binder.getCallingPid())
7828 .setCallingUid(Binder.getCallingUid())
7829 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007830 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007831 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007832 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7833 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007834 .build());
7835 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7836 boolean hasFinePermission =
7837 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7838 boolean hasCoarsePermission =
7839 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7840
Jack Yu479f40e2020-10-27 21:29:25 -07007841 final Phone phone = getPhone(subId);
7842 if (phone == null) {
7843 return null;
7844 }
7845
Jordan Liu0f2bc442020-11-18 16:47:37 -08007846 final long identity = Binder.clearCallingIdentity();
7847
Jack Yu479f40e2020-10-27 21:29:25 -07007848 boolean isCallingPackageDataService = phone.getDataServicePackages()
7849 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007851 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7852 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7853 Rlog.d(LOG_TAG,
7854 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7855 return null;
7856 }
7857
Hall Liuf19c44f2018-11-27 14:38:17 -08007858 ServiceState ss = phone.getServiceState();
7859
7860 // Scrub out the location info in ServiceState depending on what level of access
7861 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007862 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007863 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7864 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007868 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007869
7870 /**
7871 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7872 *
7873 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7874 * voicemail ringtone.
7875 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7876 * PhoneAccount.
7877 */
7878 @Override
7879 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
7882 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7883 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007884 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7888 } finally {
7889 Binder.restoreCallingIdentity(identity);
7890 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007891 }
7892
7893 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007894 * Sets the per-account voicemail ringtone.
7895 *
7896 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7897 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7898 *
7899 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7900 * voicemail ringtone.
7901 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7902 * PhoneAccount.
7903 */
7904 @Override
7905 public void setVoicemailRingtoneUri(String callingPackage,
7906 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007907 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007909 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7910 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7912 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7913 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915
7916 final long identity = Binder.clearCallingIdentity();
7917 try {
7918 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7919 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007920 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 }
7922 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007925 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007926 }
7927
7928 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007929 * Returns whether vibration is set for voicemail notification in Phone settings.
7930 *
7931 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7932 * voicemail vibration setting.
7933 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7934 */
7935 @Override
7936 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final long identity = Binder.clearCallingIdentity();
7938 try {
7939 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7940 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007941 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7945 } finally {
7946 Binder.restoreCallingIdentity(identity);
7947 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007948 }
7949
Youhan Wange64578a2016-05-02 15:32:42 -07007950 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007951 * Sets the per-account voicemail vibration.
7952 *
7953 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7954 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7955 *
7956 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7957 * voicemail vibration setting.
7958 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7959 * specific PhoneAccount.
7960 */
7961 @Override
7962 public void setVoicemailVibrationEnabled(String callingPackage,
7963 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007964 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007965 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007966 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7967 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7969 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7970 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007971 }
7972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
7979 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007982 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007983 }
7984
7985 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007986 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7987 *
7988 * @throws SecurityException if the caller does not have the required permission
7989 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007990 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007991 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007992 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007993 }
7994
7995 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007996 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7997 * permission.
7998 *
7999 * @throws SecurityException if the caller does not have the required permission
8000 */
8001 private void enforceSendSmsPermission() {
8002 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8003 }
8004
8005 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008006 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008007 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008008 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008009 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008010 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008014 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 if (componentName == null) {
8016 throw new SecurityException(
8017 "Caller not current active visual voicemail package[null]");
8018 }
8019 String vvmPackage = componentName.getPackageName();
8020 if (!callingPackage.equals(vvmPackage)) {
8021 throw new SecurityException("Caller not current active visual voicemail package["
8022 + vvmPackage + "]");
8023 }
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008026 }
8027 }
8028
8029 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008030 * Return the application ID for the app type.
8031 *
8032 * @param subId the subscription ID that this request applies to.
8033 * @param appType the uicc app type.
8034 * @return Application ID for specificied app type, or null if no uicc.
8035 */
8036 @Override
8037 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008038 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008039 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040
8041 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008042 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 if (phone == null) {
8044 return null;
8045 }
8046 String aid = null;
8047 try {
8048 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8049 .getApplicationByType(appType).getAid();
8050 } catch (Exception e) {
8051 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8052 }
8053 return aid;
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008056 }
Youhan Wange64578a2016-05-02 15:32:42 -07008057 }
8058
Youhan Wang4001d252016-05-11 10:29:41 -07008059 /**
8060 * Return the Electronic Serial Number.
8061 *
8062 * @param subId the subscription ID that this request applies to.
8063 * @return ESN or null if error.
8064 */
8065 @Override
8066 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008067 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008068 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069
8070 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008071 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 if (phone == null) {
8073 return null;
8074 }
8075 String esn = null;
8076 try {
8077 esn = phone.getEsn();
8078 } catch (Exception e) {
8079 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8080 }
8081 return esn;
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008084 }
Youhan Wang4001d252016-05-11 10:29:41 -07008085 }
8086
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008087 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008088 * Return the Preferred Roaming List Version.
8089 *
8090 * @param subId the subscription ID that this request applies to.
8091 * @return PRLVersion or null if error.
8092 */
8093 @Override
8094 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008095 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008096 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097
8098 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008099 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 if (phone == null) {
8101 return null;
8102 }
8103 String cdmaPrlVersion = null;
8104 try {
8105 cdmaPrlVersion = phone.getCdmaPrlVersion();
8106 } catch (Exception e) {
8107 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8108 }
8109 return cdmaPrlVersion;
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008112 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008113 }
8114
8115 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008116 * Get snapshot of Telephony histograms
8117 * @return List of Telephony histograms
8118 * @hide
8119 */
8120 @Override
8121 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8123 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 return RIL.getTelephonyRILTimingHistograms();
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008131 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008132
8133 /**
8134 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008135 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8136 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008137 * Require system privileges. In the future we may add this to carrier APIs.
8138 *
Michele Berionne482f8202018-11-27 18:57:59 -08008139 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008140 */
8141 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008142 @TelephonyManager.SetCarrierRestrictionResult
8143 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008144 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008145 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008146
Michele Berionne482f8202018-11-27 18:57:59 -08008147 if (carrierRestrictionRules == null) {
8148 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008149 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 final long identity = Binder.clearCallingIdentity();
8152 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008153 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008154 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008158 }
8159
8160 /**
8161 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008162 * Get the allowed carrier list and the excluded carrier list, including the priority between
8163 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008164 * Require system privileges. In the future we may add this to carrier APIs.
8165 *
Michele Berionne482f8202018-11-27 18:57:59 -08008166 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008167 */
8168 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008169 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008170 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008172
8173 final long identity = Binder.clearCallingIdentity();
8174 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008175 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8176 if (response instanceof CarrierRestrictionRules) {
8177 return (CarrierRestrictionRules) response;
8178 }
8179 // Response is an Exception of some kind,
8180 // which is signalled to the user as a NULL retval
8181 return null;
8182 } catch (Exception e) {
8183 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8184 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008188 }
8189
fionaxu59545b42016-05-25 15:53:37 -07008190 /**
fionaxu59545b42016-05-25 15:53:37 -07008191 * Action set from carrier signalling broadcast receivers to enable/disable radio
8192 * @param subId the subscription ID that this action applies to.
8193 * @param enabled control enable or disable radio.
8194 * {@hide}
8195 */
8196 @Override
8197 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8198 enforceModifyPermission();
8199 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008200
8201 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008202 if (phone == null) {
8203 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8204 return;
8205 }
8206 try {
8207 phone.carrierActionSetRadioEnabled(enabled);
8208 } catch (Exception e) {
8209 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 } finally {
8211 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008212 }
8213 }
8214
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008215 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008216 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8217 * network status based on which carrier apps could apply actions accordingly,
8218 * enable/disable default url handler for example.
8219 *
8220 * @param subId the subscription ID that this action applies to.
8221 * @param report control start/stop reporting the default network status.
8222 * {@hide}
8223 */
8224 @Override
8225 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8226 enforceModifyPermission();
8227 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228
8229 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008230 if (phone == null) {
8231 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8232 return;
8233 }
8234 try {
8235 phone.carrierActionReportDefaultNetworkStatus(report);
8236 } catch (Exception e) {
8237 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 } finally {
8239 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008240 }
8241 }
8242
8243 /**
fionaxud9622282017-07-17 17:51:30 -07008244 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8245 * @param subId the subscription ID that this action applies to.
8246 * {@hide}
8247 */
8248 @Override
8249 public void carrierActionResetAll(int subId) {
8250 enforceModifyPermission();
8251 final Phone phone = getPhone(subId);
8252 if (phone == null) {
8253 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8254 return;
8255 }
8256 try {
8257 phone.carrierActionResetAll();
8258 } catch (Exception e) {
8259 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8260 }
8261 }
8262
8263 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008264 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8265 * bug report is being generated.
8266 */
8267 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008268 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008269 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8270 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008271 writer.println("Permission Denial: can't dump Phone from pid="
8272 + Binder.getCallingPid()
8273 + ", uid=" + Binder.getCallingUid()
8274 + "without permission "
8275 + android.Manifest.permission.DUMP);
8276 return;
8277 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008278 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008279 }
Jack Yueb89b242016-06-22 13:27:47 -07008280
Brad Ebingerdac2f002018-04-03 15:17:52 -07008281 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008282 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8283 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8284 @NonNull String[] args) {
8285 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8286 this, in.getFileDescriptor(), out.getFileDescriptor(),
8287 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008288 }
8289
Jack Yueb89b242016-06-22 13:27:47 -07008290 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008291 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008292 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008293 * @param reason the reason the data enable change is taking place
8294 * @param enabled True if enabling the data, otherwise disabling.
8295 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008296 */
8297 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008298 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008299 boolean enabled) {
8300 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8301 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8302 try {
8303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008304 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008305 } catch (SecurityException se) {
8306 enforceModifyPermission();
8307 }
8308 } else {
8309 enforceModifyPermission();
8310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311
8312 final long identity = Binder.clearCallingIdentity();
8313 try {
8314 Phone phone = getPhone(subId);
8315 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008316 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8317 phone.carrierActionSetMeteredApnsEnabled(enabled);
8318 } else {
8319 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 }
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008324 }
8325 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008326
8327 /**
8328 * Get Client request stats
8329 * @return List of Client Request Stats
8330 * @hide
8331 */
8332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008333 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8334 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008336 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008337 return null;
8338 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008339 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 final long identity = Binder.clearCallingIdentity();
8342 try {
8343 if (phone != null) {
8344 return phone.getClientRequestStats();
8345 }
8346
8347 return null;
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008351 }
8352
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008353 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008354 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008355 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008356 }
Jack Yueb4124c2017-02-16 15:32:43 -08008357
8358 /**
Grace Chen70990072017-03-24 17:21:30 -07008359 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008360 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008361 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008362 * @param state State of SIM (power down, power up, pass through)
8363 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8364 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8365 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008366 *
8367 **/
8368 @Override
Grace Chen70990072017-03-24 17:21:30 -07008369 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008370 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008371 Phone phone = PhoneFactory.getPhone(slotIndex);
8372
vagdeviaf9a5b92018-08-15 16:01:53 -07008373 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008378 phone.setSimPowerState(state, null, workSource);
8379 }
8380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
8383 }
8384
8385 /**
8386 * Set SIM card power state.
8387 *
8388 * @param slotIndex SIM slot id.
8389 * @param state State of SIM (power down, power up, pass through)
8390 * @param callback callback to trigger after success or failure
8391 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8392 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8393 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8394 *
8395 **/
8396 @Override
8397 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8398 IIntegerConsumer callback) {
8399 enforceModifyPermission();
8400 Phone phone = PhoneFactory.getPhone(slotIndex);
8401
8402 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8403
8404 final long identity = Binder.clearCallingIdentity();
8405 try {
8406 if (phone != null) {
8407 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8408 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008409 }
8410 } finally {
8411 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008412 }
8413 }
Shuo Qiandd210312017-04-12 22:11:33 +00008414
Tyler Gunn65d45c22017-06-05 11:22:26 -07008415 private boolean isUssdApiAllowed(int subId) {
8416 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008417 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008418 if (configManager == null) {
8419 return false;
8420 }
8421 PersistableBundle pb = configManager.getConfigForSubId(subId);
8422 if (pb == null) {
8423 return false;
8424 }
8425 return pb.getBoolean(
8426 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8427 }
8428
Shuo Qiandd210312017-04-12 22:11:33 +00008429 /**
8430 * Check if phone is in emergency callback mode
8431 * @return true if phone is in emergency callback mode
8432 * @param subId sub id
8433 */
goneil9c5f4872017-12-05 14:07:56 -08008434 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008435 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008436 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 if (phone != null) {
8442 return phone.isInEcm();
8443 } else {
8444 return false;
8445 }
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008448 }
8449 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008450
8451 /**
8452 * Get the current signal strength information for the given subscription.
8453 * Because this information is not updated when the device is in a low power state
8454 * it should not be relied-upon to be current.
8455 * @param subId Subscription index
8456 * @return the most recent cached signal strength info from the modem
8457 */
8458 @Override
8459 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008460 final long identity = Binder.clearCallingIdentity();
8461 try {
8462 Phone p = getPhone(subId);
8463 if (p == null) {
8464 return null;
8465 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008467 return p.getSignalStrength();
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008471 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008472
Pengquan Meng77b7f132018-08-22 14:49:57 -07008473 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008474 * Get the current modem radio state for the given slot.
8475 * @param slotIndex slot index.
8476 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008477 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008478 * @return the current radio power state from the modem
8479 */
8480 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008481 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008482 Phone phone = PhoneFactory.getPhone(slotIndex);
8483 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8485 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008486 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8487 }
8488
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 return phone.getRadioPowerState();
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
8495 }
8496 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8497 }
8498
8499 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008500 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8501 *
8502 * <p>Requires one of the following permissions:
8503 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8504 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8505 * privileges.
8506 *
8507 * @param subId subscription id
8508 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8509 * {@code false}.
8510 */
8511 @Override
8512 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008513 try {
8514 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8515 null);
8516 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008517 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008518 mApp, subId, "isDataRoamingEnabled");
8519 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008520
Pengquan Menga1bb6272018-09-06 09:59:22 -07008521 boolean isEnabled = false;
8522 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008523 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008524 Phone phone = getPhone(subId);
8525 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008526 } finally {
8527 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008529 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008530 }
8531
8532
8533 /**
8534 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8535 *
8536 * <p> Requires permission:
8537 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8538 * privileges.
8539 *
8540 * @param subId subscription id
8541 * @param isEnabled {@code true} means enable, {@code false} means disable.
8542 */
8543 @Override
8544 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8546 mApp, subId, "setDataRoamingEnabled");
8547
Pengquan Menga1bb6272018-09-06 09:59:22 -07008548 final long identity = Binder.clearCallingIdentity();
8549 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008550 Phone phone = getPhone(subId);
8551 if (phone != null) {
8552 phone.setDataRoamingEnabled(isEnabled);
8553 }
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008556 }
8557 }
8558
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008559 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008560 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008561 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008562 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008563 mApp, subId, "isManualNetworkSelectionAllowed");
8564
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008565 boolean isAllowed = true;
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008568 Phone phone = getPhone(subId);
8569 if (phone != null) {
8570 isAllowed = phone.isCspPlmnEnabled();
8571 }
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 return isAllowed;
8576 }
8577
8578 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008579 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008580 // Verify that tha callingPackage belongs to the calling UID
8581 mApp.getSystemService(AppOpsManager.class)
8582 .checkPackage(Binder.getCallingUid(), callingPackage);
8583
Jordan Liu1e142fc2019-04-22 15:10:43 -07008584 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008585 try {
8586 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008587 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008588 } catch (SecurityException e) {
8589 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8590 // has carrier privileges on an active UICC
8591 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8592 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008593 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008594 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008595 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008596
8597 final long identity = Binder.clearCallingIdentity();
8598 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008599 UiccController uiccController = UiccController.getInstance();
8600 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008601 if (hasReadPermission) {
8602 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008603 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008604
8605 // Remove private info if the caller doesn't have access
8606 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8607 for (UiccCardInfo cardInfo : cardInfos) {
8608 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8609 // is available
8610 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8611 if (card == null || card.getUiccProfile() == null) {
8612 // assume no access if the card or profile is unavailable
8613 filteredInfos.add(cardInfo.getUnprivileged());
8614 continue;
8615 }
8616 UiccProfile profile = card.getUiccProfile();
8617 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8618 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8619 filteredInfos.add(cardInfo);
8620 } else {
8621 filteredInfos.add(cardInfo.getUnprivileged());
8622 }
8623 }
8624 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008625 } finally {
8626 Binder.restoreCallingIdentity(identity);
8627 }
8628 }
8629
8630 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008631 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008632 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8637 if (slots == null) {
8638 Rlog.i(LOG_TAG, "slots is null.");
8639 return null;
8640 }
8641
8642 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8643 for (int i = 0; i < slots.length; i++) {
8644 UiccSlot slot = slots[i];
8645 if (slot == null) {
8646 continue;
8647 }
8648
Jordan Liu7be7e652019-05-06 18:55:02 +00008649 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650 UiccCard card = slot.getUiccCard();
8651 if (card != null) {
8652 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008653 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008654 cardId = slot.getEid();
8655 if (TextUtils.isEmpty(cardId)) {
8656 cardId = slot.getIccId();
8657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 }
8659
Jordan Liu857451f2019-05-09 16:35:35 -07008660 if (cardId != null) {
8661 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8662 // if cardId is an EID, it's all digits so this is fine
8663 cardId = IccUtils.stripTrailingFs(cardId);
8664 }
8665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666 int cardState = 0;
8667 switch (slot.getCardState()) {
8668 case CARDSTATE_ABSENT:
8669 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8670 break;
8671 case CARDSTATE_PRESENT:
8672 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8673 break;
8674 case CARDSTATE_ERROR:
8675 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8676 break;
8677 case CARDSTATE_RESTRICTED:
8678 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8679 break;
8680 default:
8681 break;
8682
8683 }
8684
8685 infos[i] = new UiccSlotInfo(
8686 slot.isActive(),
8687 slot.isEuicc(),
8688 cardId,
8689 cardState,
8690 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008691 slot.isExtendedApduSupported(),
8692 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008693 }
8694 return infos;
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008697 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008698 }
8699
8700 @Override
8701 public boolean switchSlots(int[] physicalSlots) {
8702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008703
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8707 } finally {
8708 Binder.restoreCallingIdentity(identity);
8709 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008710 }
Jack Yu4c988042018-02-27 15:30:01 -08008711
8712 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008713 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 return UiccController.getInstance().getCardIdForDefaultEuicc();
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
Pengquan Meng85728fb2018-03-12 16:31:21 -07008722 /**
goneil47ffb6e2018-04-06 15:40:58 -07008723 * A test API to reload the UICC profile.
8724 *
8725 * <p>Requires that the calling app has permission
8726 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8727 * @hide
8728 */
8729 @Override
8730 public void refreshUiccProfile(int subId) {
8731 enforceModifyPermission();
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 Phone phone = getPhone(subId);
8736 if (phone == null) {
8737 return;
8738 }
8739 UiccCard uiccCard = phone.getUiccCard();
8740 if (uiccCard == null) {
8741 return;
8742 }
8743 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8744 if (uiccProfile == null) {
8745 return;
8746 }
8747 uiccProfile.refresh();
8748 } finally {
8749 Binder.restoreCallingIdentity(identity);
8750 }
8751 }
8752
8753 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008754 * Returns false if the mobile data is disabled by default, otherwise return true.
8755 */
8756 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008757 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008758 }
8759
8760 /**
8761 * Returns true if the data roaming is enabled by default, i.e the system property
8762 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8763 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8764 */
8765 private boolean getDefaultDataRoamingEnabled(int subId) {
8766 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008767 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008768 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008769 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8770 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8771 return isDataRoamingEnabled;
8772 }
8773
8774 /**
8775 * Returns the default network type for the given {@code subId}, if the default network type is
8776 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8777 */
8778 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008779 List<Integer> list = TelephonyProperties.default_network();
8780 int phoneId = mSubscriptionController.getPhoneId(subId);
8781 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8782 return list.get(phoneId);
8783 }
8784 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008785 }
fionaxua13278b2018-03-21 00:08:13 -07008786
8787 @Override
8788 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008789 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791
8792 final long identity = Binder.clearCallingIdentity();
8793 try {
8794 final Phone phone = getPhone(subId);
8795 if (phone == null) {
8796 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8797 return;
8798 }
chen xueaba88a2019-03-15 13:15:10 -07008799 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8800 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008801 if (carrierPrivilegeRules == null) {
8802 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8803 } else {
8804 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 } finally {
8807 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008808 }
fionaxua13278b2018-03-21 00:08:13 -07008809 }
8810
8811 @Override
8812 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008813 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008814
8815 final long identity = Binder.clearCallingIdentity();
8816 try {
8817 final Phone phone = getPhone(subId);
8818 if (phone == null) {
8819 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8820 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8821 }
8822 return phone.getCarrierIdListVersion();
8823 } finally {
8824 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008825 }
fionaxua13278b2018-03-21 00:08:13 -07008826 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008827
8828 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008829 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8830 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008832 mApp, subId, callingPackage, callingFeatureId,
8833 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008834 return -1;
8835 }
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
8842 }
8843 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008844
8845 @Override
8846 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008847 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008848 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008849 mApp, subId, "getCdmaRoamingMode");
8850
8851 final long identity = Binder.clearCallingIdentity();
8852 try {
8853 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
8857 }
8858
8859 @Override
8860 public boolean setCdmaRoamingMode(int subId, int mode) {
8861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8862 mApp, subId, "setCdmaRoamingMode");
8863
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
8866 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
8869 }
8870 }
8871
8872 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008873 public int getCdmaSubscriptionMode(int subId) {
8874 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008875 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008876 mApp, subId, "getCdmaSubscriptionMode");
8877
8878 final long identity = Binder.clearCallingIdentity();
8879 try {
8880 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8881 } finally {
8882 Binder.restoreCallingIdentity(identity);
8883 }
8884 }
8885
8886 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008887 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8889 mApp, subId, "setCdmaSubscriptionMode");
8890
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8894 } finally {
8895 Binder.restoreCallingIdentity(identity);
8896 }
8897 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008898
sqianc5eccab2018-10-19 18:46:41 -07008899 @Override
sqian8c685422019-02-22 15:55:18 -08008900 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008901 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008903 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8904 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008905 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8906 }
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
sqian854d44b2018-12-12 16:48:18 -08008909 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8910 for (Phone phone: PhoneFactory.getPhones()) {
8911 if (phone.getEmergencyNumberTracker() != null
8912 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8913 emergencyNumberListInternal.put(
8914 phone.getSubId(),
8915 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8916 }
sqian11b7a0e2018-12-05 18:48:28 -08008917 }
sqian854d44b2018-12-12 16:48:18 -08008918 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008919 } finally {
8920 Binder.restoreCallingIdentity(identity);
8921 }
sqianc5eccab2018-10-19 18:46:41 -07008922 }
8923
8924 @Override
sqian8c685422019-02-22 15:55:18 -08008925 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008926 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008927 if (!exactMatch) {
8928 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008929 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008930 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008931 }
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
sqian854d44b2018-12-12 16:48:18 -08008934 for (Phone phone: PhoneFactory.getPhones()) {
8935 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008936 && phone.getEmergencyNumberTracker()
8937 .isEmergencyNumber(number, exactMatch)) {
8938 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008939 }
sqian11b7a0e2018-12-05 18:48:28 -08008940 }
8941 return false;
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
sqianf4ca7ed2019-01-15 18:32:07 -08008947 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008948 * Start emergency callback mode for GsmCdmaPhone for testing.
8949 */
8950 @Override
8951 public void startEmergencyCallbackMode() {
8952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8953 "startEmergencyCallbackMode");
8954 enforceModifyPermission();
8955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 for (Phone phone : PhoneFactory.getPhones()) {
8958 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8959 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8960 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8961 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8962 gsmCdmaPhone.obtainMessage(
8963 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8964 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8965 }
8966 }
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
8970 }
8971
8972 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008973 * Update emergency number list for test mode.
8974 */
8975 @Override
8976 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8977 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8978 "updateEmergencyNumberListTestMode");
8979
8980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 for (Phone phone: PhoneFactory.getPhones()) {
8983 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8984 if (tracker != null) {
8985 tracker.executeEmergencyNumberTestModeCommand(action, num);
8986 }
8987 }
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
8990 }
8991 }
8992
8993 /**
8994 * Get the full emergency number list for test mode.
8995 */
8996 @Override
8997 public List<String> getEmergencyNumberListTestMode() {
8998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8999 "getEmergencyNumberListTestMode");
9000
9001 final long identity = Binder.clearCallingIdentity();
9002 try {
9003 Set<String> emergencyNumbers = new HashSet<>();
9004 for (Phone phone: PhoneFactory.getPhones()) {
9005 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9006 if (tracker != null) {
9007 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9008 emergencyNumbers.add(num.getNumber());
9009 }
9010 }
9011 }
9012 return new ArrayList<>(emergencyNumbers);
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
chen xud6b45bd2018-10-30 22:27:10 -07009018 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009019 public int getEmergencyNumberDbVersion(int subId) {
9020 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9021
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 final Phone phone = getPhone(subId);
9025 if (phone == null) {
9026 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9027 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9028 }
9029 return phone.getEmergencyNumberDbVersion();
9030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
9034
9035 @Override
9036 public void notifyOtaEmergencyNumberDbInstalled() {
9037 enforceModifyPermission();
9038
9039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 for (Phone phone: PhoneFactory.getPhones()) {
9042 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9043 if (tracker != null) {
9044 tracker.updateOtaEmergencyNumberDatabase();
9045 }
9046 }
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
9051
9052 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009053 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009054 enforceActiveEmergencySessionPermission();
9055
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 for (Phone phone: PhoneFactory.getPhones()) {
9059 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9060 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009061 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9062 }
9063 }
9064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
9067 }
9068
9069 @Override
9070 public void resetOtaEmergencyNumberDbFilePath() {
9071 enforceActiveEmergencySessionPermission();
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 for (Phone phone: PhoneFactory.getPhones()) {
9076 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9077 if (tracker != null) {
9078 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009079 }
9080 }
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
9086 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009087 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9088 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9089 Phone phone = getPhone(subId);
9090 if (phone == null) {
9091 return null;
9092 }
9093 final long identity = Binder.clearCallingIdentity();
9094 try {
9095 UiccProfile profile = UiccController.getInstance()
9096 .getUiccProfileForPhone(phone.getPhoneId());
9097 if (profile != null) {
9098 return profile.getCertsFromCarrierPrivilegeAccessRules();
9099 }
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 return null;
9104 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009105
9106 /**
9107 * Enable or disable a modem stack.
9108 */
9109 @Override
9110 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9111 enforceModifyPermission();
9112
9113 final long identity = Binder.clearCallingIdentity();
9114 try {
9115 Phone phone = PhoneFactory.getPhone(slotIndex);
9116 if (phone == null) {
9117 return false;
9118 } else {
9119 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9120 }
9121 } finally {
9122 Binder.restoreCallingIdentity(identity);
9123 }
9124 }
Michelecea4cf22018-12-21 15:00:11 -08009125
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009126 /**
9127 * Whether a modem stack is enabled or not.
9128 */
9129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009130 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9131 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009132 Phone phone = PhoneFactory.getPhone(slotIndex);
9133 if (phone == null) return false;
9134
9135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009136 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9137 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009138 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9139 }
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009143 try {
9144 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9145 } catch (NoSuchElementException ex) {
9146 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9147 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
Michelecea4cf22018-12-21 15:00:11 -08009153 @Override
Michele0ea7d782019-03-19 14:58:42 -07009154 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009155 enforceModifyPermission();
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
9159 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009160 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009161 .commit();
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
9166
9167 @Override
Michele0ea7d782019-03-19 14:58:42 -07009168 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009169 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009171 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9172 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009173 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009174 }
Michelecea4cf22018-12-21 15:00:11 -08009175
9176 final long identity = Binder.clearCallingIdentity();
9177 try {
Michele0ea7d782019-03-19 14:58:42 -07009178 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009179 } finally {
9180 Binder.restoreCallingIdentity(identity);
9181 }
9182 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009183
Michele0ea7d782019-03-19 14:58:42 -07009184 @TelephonyManager.IsMultiSimSupportedResult
9185 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009186 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9187 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9188 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009189 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9190 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009191 }
9192 // Check if the hardware supports multisim functionality. If usage of multisim is not
9193 // supported by the modem, indicate that it is restricted.
9194 PhoneCapability staticCapability =
9195 mPhoneConfigurationManager.getStaticPhoneCapability();
9196 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009197 loge("isMultiSimSupportedInternal: no static configuration available");
9198 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009199 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009200 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009201 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9202 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009203 }
9204 // Check if support of multiple SIMs is restricted by carrier
9205 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009206 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009207 }
9208
Michele0ea7d782019-03-19 14:58:42 -07009209 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009210 }
9211
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009212 /**
9213 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009214 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9215 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9216 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009217 * @param numOfSims number of active sims we want to switch to
9218 */
9219 @Override
9220 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009221 if (numOfSims == 1) {
9222 enforceModifyPermission();
9223 } else {
9224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9225 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9226 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009227 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009228
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009229 try {
Michele30b57b22019-03-01 12:01:14 -08009230 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009231 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009232 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9233 return;
9234 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009235 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
9239 }
9240
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009241 @Override
9242 public boolean isApplicationOnUicc(int subId, int appType) {
9243 enforceReadPrivilegedPermission("isApplicationOnUicc");
9244 Phone phone = getPhone(subId);
9245 if (phone == null) {
9246 return false;
9247 }
9248 final long identity = Binder.clearCallingIdentity();
9249 try {
9250 UiccCard uiccCard = phone.getUiccCard();
9251 if (uiccCard == null) {
9252 return false;
9253 }
9254 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9255 if (uiccProfile == null) {
9256 return false;
9257 }
9258 if (TelephonyManager.APPTYPE_SIM <= appType
9259 && appType <= TelephonyManager.APPTYPE_ISIM) {
9260 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9261 }
9262 return false;
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
9267
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009268 /**
chen xub4baa772019-04-03 10:23:41 -07009269 * Get whether making changes to modem configurations will trigger reboot.
9270 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009271 */
9272 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009273 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9274 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009276 mApp, subId, callingPackage, callingFeatureId,
9277 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009278 return false;
9279 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009280 final long identity = Binder.clearCallingIdentity();
9281 try {
9282 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9283 } finally {
9284 Binder.restoreCallingIdentity(identity);
9285 }
9286 }
9287
Nathan Harold29f5f052019-02-15 13:41:57 -08009288 private void updateModemStateMetrics() {
9289 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9290 // TODO: check the state for each modem if the api is ready.
9291 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9292 }
9293
Pengquan Meng3889a572019-01-23 11:16:29 -08009294 @Override
9295 public int[] getSlotsMapping() {
9296 enforceReadPrivilegedPermission("getSlotsMapping");
9297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9301 // All logical slots should have a mapping to a physical slot.
9302 int[] logicalSlotsMapping = new int[phoneCount];
9303 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9304 for (int i = 0; i < slotInfos.length; i++) {
9305 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9306 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9307 }
9308 }
9309 return logicalSlotsMapping;
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009314
9315 /**
9316 * Get the IRadio HAL Version
9317 */
9318 @Override
9319 public int getRadioHalVersion() {
9320 Phone phone = getDefaultPhone();
9321 if (phone == null) return -1;
9322 HalVersion hv = phone.getHalVersion();
9323 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9324 return hv.major * 100 + hv.minor;
9325 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009326
9327 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009328 * Get the current calling package name.
9329 * @return the current calling package name
9330 */
9331 @Override
9332 public String getCurrentPackageName() {
9333 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9334 }
9335
9336 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009337 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9338 * corresponding network requests on a subId.
9339 *
9340 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009341 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009342 * 2) APN is un-metered for this subscription, or
9343 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009344 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009345 *
9346 * @return whether data is allowed for a apn type.
9347 *
9348 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009349 */
9350 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009351 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009352 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9353 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009354
9355 // Now that all security checks passes, perform the operation as ourselves.
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
9358 Phone phone = getPhone(subId);
9359 if (phone == null) return false;
9360
Jack Yu41407ee2019-05-13 16:54:09 -07009361 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009362 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
9367
9368 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009369 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009370 enforceReadPrivilegedPermission("isApnMetered");
9371
9372 // Now that all security checks passes, perform the operation as ourselves.
9373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 Phone phone = getPhone(subId);
9376 if (phone == null) return true; // By default return true.
9377
Jack Yu41407ee2019-05-13 16:54:09 -07009378 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
9382 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009383
9384 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009385 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9386 int subscriptionId, IBooleanConsumer resultCallback) {
9387 enforceModifyPermission();
9388 long token = Binder.clearCallingIdentity();
9389 try {
9390 Phone phone = getPhone(subscriptionId);
9391 if (phone == null) {
9392 try {
9393 if (resultCallback != null) {
9394 resultCallback.accept(false);
9395 }
9396 } catch (RemoteException e) {
9397 // ignore
9398 }
9399 return;
9400 }
9401 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9402 Pair.create(specifiers, (x) -> {
9403 try {
9404 if (resultCallback != null) {
9405 resultCallback.accept(x);
9406 }
9407 } catch (RemoteException e) {
9408 // ignore
9409 }
9410 });
9411 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9412 } finally {
9413 Binder.restoreCallingIdentity(token);
9414 }
9415 }
9416
9417 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009418 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9419 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009420 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009421 mApp, subId, "getSystemSelectionChannels");
9422 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9423 final long identity = Binder.clearCallingIdentity();
9424 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009425 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9426 if (result instanceof IllegalStateException) {
9427 throw (IllegalStateException) result;
9428 }
9429 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009430 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9431 return specifiers;
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
9436
9437 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009438 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009439 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009440 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9441 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9442 if (iccRecords == null) {
9443 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9444 return false;
9445 }
9446 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9447 }
9448
9449 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009450 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9451 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009452 if (callingPackage == null) {
9453 callingPackage = getCurrentPackageName();
9454 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009455 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9456 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009457 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9458 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009459 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9460 }
9461 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9462 Intent intent = new Intent();
9463 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9464 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9465 // Bring up choose default SMS subscription dialog right now
9466 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9467 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9468 mApp.startActivity(intent);
9469 }
chen xud5ca2d52019-05-28 15:20:57 -07009470
9471 @Override
9472 public String getMmsUAProfUrl(int subId) {
9473 //TODO investigate if this API should require proper permission check in R b/133791609
9474 final long identity = Binder.clearCallingIdentity();
9475 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009476 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9477 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9478 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9479 return carrierUAProfUrl;
9480 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009481 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9482 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
9488 @Override
9489 public String getMmsUserAgent(int subId) {
9490 //TODO investigate if this API should require proper permission check in R b/133791609
9491 final long identity = Binder.clearCallingIdentity();
9492 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009493 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9494 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9495 if (!TextUtils.isEmpty(carrierUserAgent)) {
9496 return carrierUserAgent;
9497 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009498 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9499 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
Jack Yub07d4972019-05-28 16:12:25 -07009504
9505 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009506 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9507 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009508
Jack Yub07d4972019-05-28 16:12:25 -07009509 final long identity = Binder.clearCallingIdentity();
9510 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009511 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009512 if (phone == null) return false;
9513
Hall Liua62f5da2020-09-25 10:42:19 -07009514 switch (policy) {
9515 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9516 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9517 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9518 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9519 default:
9520 throw new IllegalArgumentException(policy + " is not a valid policy");
9521 }
Jack Yub07d4972019-05-28 16:12:25 -07009522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
9527 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009528 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009529 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009530 enforceModifyPermission();
9531
changbettyd5c246e2019-12-24 15:40:37 +08009532 final long identity = Binder.clearCallingIdentity();
9533 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009534 Phone phone = getPhone(subscriptionId);
9535 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009536
Hall Liua62f5da2020-09-25 10:42:19 -07009537 switch (policy) {
9538 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9539 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9540 break;
9541 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9542 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9543 break;
9544 default:
9545 throw new IllegalArgumentException(policy + " is not a valid policy");
9546 }
changbettyd5c246e2019-12-24 15:40:37 +08009547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
9551
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009552 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009553 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009554 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9555 * otherwise.
9556 */
9557 @Override
9558 public void setCepEnabled(boolean isCepEnabled) {
9559 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
9563 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9564 for (Phone phone : PhoneFactory.getPhones()) {
9565 Phone defaultPhone = phone.getImsPhone();
9566 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9567 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9568 ImsPhoneCallTracker imsPhoneCallTracker =
9569 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9570 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9571 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9572 + imsPhone.getMsisdn());
9573 }
9574 }
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
allenwtsu46dcc572020-01-08 18:24:03 +08009579
9580 /**
9581 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9582 *
9583 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9584 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9585 * before being read.
9586 */
9587 @Override
9588 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9589 isCompressed) {
9590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9591 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9593 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9594 }
9595 if (!isImsAvailableOnDevice()) {
9596 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9597 "IMS not available on device.");
9598 }
9599
9600 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009601 try {
Hui Wang761a6682020-10-31 05:12:53 +00009602 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9603 } finally {
9604 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009605 }
9606 }
zoey chene02881a2019-12-30 16:11:23 +08009607
9608 @Override
9609 public boolean isIccLockEnabled(int subId) {
9610 enforceReadPrivilegedPermission("isIccLockEnabled");
9611
9612 // Now that all security checks passes, perform the operation as ourselves.
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
9615 Phone phone = getPhone(subId);
9616 if (phone != null && phone.getIccCard() != null) {
9617 return phone.getIccCard().getIccLockEnabled();
9618 } else {
9619 return false;
9620 }
9621 } finally {
9622 Binder.restoreCallingIdentity(identity);
9623 }
9624 }
9625
9626 /**
9627 * Set the ICC pin lock enabled or disabled.
9628 *
9629 * @return an integer representing the status of IccLock enabled or disabled in the following
9630 * three cases:
9631 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9632 * successfully.
9633 * - Positive number and zero for remaining password attempts.
9634 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9635 *
9636 */
9637 @Override
9638 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9639 enforceModifyPermission();
9640
9641 Phone phone = getPhone(subId);
9642 if (phone == null) {
9643 return 0;
9644 }
9645 // Now that all security checks passes, perform the operation as ourselves.
9646 final long identity = Binder.clearCallingIdentity();
9647 try {
9648 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9649 new Pair<Boolean, String>(enabled, password), phone, null);
9650 return attemptsRemaining;
9651
9652 } catch (Exception e) {
9653 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9654 } finally {
9655 Binder.restoreCallingIdentity(identity);
9656 }
9657 return 0;
9658 }
9659
9660 /**
9661 * Change the ICC password used in ICC pin lock.
9662 *
9663 * @return an integer representing the status of IccLock changed in the following three cases:
9664 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9665 * - Positive number and zero for remaining password attempts.
9666 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9667 *
9668 */
9669 @Override
9670 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9671 enforceModifyPermission();
9672
9673 Phone phone = getPhone(subId);
9674 if (phone == null) {
9675 return 0;
9676 }
9677 // Now that all security checks passes, perform the operation as ourselves.
9678 final long identity = Binder.clearCallingIdentity();
9679 try {
9680 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9681 new Pair<String, String>(oldPassword, newPassword), phone, null);
9682 return attemptsRemaining;
9683
9684 } catch (Exception e) {
9685 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689 return 0;
9690 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009691
9692 /**
9693 * Request for receiving user activity notification
9694 */
9695 @Override
9696 public void requestUserActivityNotification() {
9697 if (!mNotifyUserActivity.get()
9698 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9699 mNotifyUserActivity.set(true);
9700 }
9701 }
9702
9703 /**
9704 * Called when userActivity is signalled in the power manager.
9705 * This is safe to call from any thread, with any window manager locks held or not.
9706 */
9707 @Override
9708 public void userActivity() {
9709 // ***************************************
9710 // * Inherited from PhoneWindowManager *
9711 // ***************************************
9712 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9713 // WITH ITS LOCKS HELD.
9714 //
9715 // This code must be VERY careful about the locks
9716 // it acquires.
9717 // In fact, the current code acquires way too many,
9718 // and probably has lurking deadlocks.
9719
9720 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9721 throw new SecurityException("Only the OS may call notifyUserActivity()");
9722 }
9723
9724 if (mNotifyUserActivity.getAndSet(false)) {
9725 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9726 USER_ACTIVITY_NOTIFICATION_DELAY);
9727 }
9728 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009729
9730 @Override
9731 public boolean canConnectTo5GInDsdsMode() {
9732 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9733 }
Jack Yud10cdd42020-09-28 20:28:01 -07009734
9735 @Override
9736 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9737 String callingFeatureId) {
9738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9739 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9740 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9741 }
9742
9743 Phone phone = getPhone(subId);
9744 if (phone == null) {
9745 throw new RuntimeException("phone is not available");
9746 }
9747 // Now that all security checks passes, perform the operation as ourselves.
9748 final long identity = Binder.clearCallingIdentity();
9749 try {
9750 return phone.getEquivalentHomePlmns();
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 }
Daniel Bright59e67312020-11-13 11:49:37 -08009755
9756 @Override
9757 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009758 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9759 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009760 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009761 if (radioInterfaceCapabilities == null) {
9762 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009763 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009764 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009765 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009766
Hui Wang641e81c2020-10-12 12:14:23 -07009767 @Override
9768 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9769 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009770 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9771 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9772 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9773 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9774 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009775 if (DBG) {
9776 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9777 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9778 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9779 }
9780
9781 if (!SubscriptionManager.isValidSubscriptionId(subId)
9782 || appType < TelephonyManager.APPTYPE_UNKNOWN
9783 || appType > TelephonyManager.APPTYPE_ISIM
9784 || nafUrl == null || securityProtocol == null || callback == null) {
9785 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9786 if (callback != null) {
9787 try {
9788 callback.onAuthenticationFailure(
9789 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9790 } catch (RemoteException exception) {
9791 log("Fail to notify onAuthenticationFailure due to " + exception);
9792 }
9793 return;
9794 }
9795 }
9796
9797 final long token = Binder.clearCallingIdentity();
9798 try {
9799 getGbaManager(subId).bootstrapAuthenticationRequest(
9800 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9801 forceBootStrapping, callback));
9802 } finally {
9803 Binder.restoreCallingIdentity(token);
9804 }
9805 }
9806
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009807 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009808 * Attempts to set the radio power state for all phones for thermal reason.
9809 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009810 * requested radio power state will actually be set. See {@link
9811 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9812 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009813 * @param enable {@code true} if trying to turn radio on.
9814 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9815 * false}.
9816 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009817 private boolean setRadioPowerForThermal(boolean enable) {
9818 boolean isPhoneAvailable = false;
9819 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9820 Phone phone = PhoneFactory.getPhone(i);
9821 if (phone != null) {
9822 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9823 isPhoneAvailable = true;
9824 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009825 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009826
9827 // return true if successfully informed the phone object about the thermal radio power
9828 // request.
9829 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009830 }
9831
9832 private int handleDataThrottlingRequest(int subId,
9833 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009834 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9835 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9836 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9837 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9838 throw new IllegalArgumentException("modem does not support data throttling");
9839 }
9840
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009841 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9842 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009843 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009844 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9845 }
9846
9847 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9848
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009849 if (isDataThrottlingSupported) {
9850 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009851 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009852 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9853 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9854 } else if (thermalMitigationResult
9855 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009856 log("Modem likely does not support data throttling on secondary carrier. Data " +
9857 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9858 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009859 }
9860 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009861 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009862
9863 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009864 }
9865
Jack Nudelman644b91a2021-03-12 14:09:48 -08009866 private static List<String> getThermalMitigationAllowlist(Context context) {
9867 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9868 for (String pckg : context.getResources()
9869 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9870 sThermalMitigationAllowlistedPackages.add(pckg);
9871 }
9872 }
9873
9874 return sThermalMitigationAllowlistedPackages;
9875 }
9876
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009877 private boolean isAnyPhoneInEmergencyState() {
9878 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9879 if (tm.isInEmergencyCall()) {
9880 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9881 return true;
9882 }
9883 for (Phone phone : PhoneFactory.getPhones()) {
9884 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9885 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9886 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9887 + phone.isInEcm());
9888 return true;
9889 }
9890 }
9891
9892 return false;
9893 }
9894
Jack Nudelman644b91a2021-03-12 14:09:48 -08009895 /**
9896 * Used by shell commands to add an authorized package name for thermal mitigation.
9897 * @param packageName name of package to be allowlisted
9898 * @param context
9899 */
9900 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9901 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9902 sThermalMitigationAllowlistedPackages.add(packageName);
9903 }
9904
9905 /**
9906 * Used by shell commands to remove an authorized package name for thermal mitigation.
9907 * @param packageName name of package to remove from allowlist
9908 * @param context
9909 */
9910 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9911 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9912 sThermalMitigationAllowlistedPackages.remove(packageName);
9913 }
9914
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009915 /**
9916 * Thermal mitigation request to control functionalities at modem.
9917 *
9918 * @param subId the id of the subscription.
9919 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009920 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009921 *
9922 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9923 */
9924 @Override
9925 @ThermalMitigationResult
9926 public int sendThermalMitigationRequest(
9927 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009928 ThermalMitigationRequest thermalMitigationRequest,
9929 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009930 enforceModifyPermission();
9931
Jack Nudelman644b91a2021-03-12 14:09:48 -08009932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9933 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9934 .contains(callingPackage)) {
9935 throw new SecurityException("Calling package must be configured in the device config. "
9936 + "calling package: " + callingPackage);
9937 }
9938
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009939 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9940 final long identity = Binder.clearCallingIdentity();
9941
9942 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9943 try {
9944 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9945 switch (thermalMitigationAction) {
9946 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9947 thermalMitigationResult =
9948 handleDataThrottlingRequest(subId,
9949 thermalMitigationRequest.getDataThrottlingRequest());
9950 break;
9951 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9952 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9953 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9954 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9955 }
9956
9957 // Ensure that radio is on. If not able to power on due to phone being
9958 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009959 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009960 thermalMitigationResult =
9961 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9962 break;
9963 }
9964
9965 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9966 false);
9967 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9968 break;
9969 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9970 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9971 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9972 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9973 }
9974
9975 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9976 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009977 Phone phone = getPhone(subId);
9978 if (phone == null) {
9979 thermalMitigationResult =
9980 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9981 break;
9982 }
9983
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009984 TelephonyConnectionService service =
9985 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009986 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009987 Log.e(LOG_TAG, "An emergency call is pending");
9988 thermalMitigationResult =
9989 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9990 break;
9991 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009992 thermalMitigationResult =
9993 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9994 break;
9995 }
9996 } else {
9997 thermalMitigationResult =
9998 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9999 break;
10000 }
10001
10002 // Turn radio off. If not able to power off due to phone being unavailable,
10003 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010004 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010005 thermalMitigationResult =
10006 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10007 break;
10008 }
10009 thermalMitigationResult =
10010 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10011 break;
10012 default:
10013 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10014 + "not exist. Requested action: " + thermalMitigationAction);
10015 }
10016 } catch (IllegalArgumentException e) {
10017 throw e;
10018 } catch (Exception e) {
10019 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10020 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024
10025 if (DBG) {
10026 log("thermalMitigationRequest returning with thermalMitigationResult: "
10027 + thermalMitigationResult);
10028 }
10029
10030 return thermalMitigationResult;
10031 }
Hui Wang641e81c2020-10-12 12:14:23 -070010032
10033 /**
10034 * Set the GbaService Package Name that Telephony will bind to.
10035 *
10036 * @param subId The sim that the GbaService is associated with.
10037 * @param packageName The name of the package to be replaced with.
10038 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10039 */
10040 @Override
10041 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10042 enforceModifyPermission();
10043
10044 final long identity = Binder.clearCallingIdentity();
10045 try {
10046 return getGbaManager(subId).overrideServicePackage(packageName);
10047 } finally {
10048 Binder.restoreCallingIdentity(identity);
10049 }
10050 }
10051
10052 /**
10053 * Return the package name of the currently bound GbaService.
10054 *
10055 * @param subId The sim that the GbaService is associated with.
10056 * @return the package name of the GbaService configuration, null if GBA is not supported.
10057 */
10058 @Override
10059 public String getBoundGbaService(int subId) {
10060 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10061
10062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 return getGbaManager(subId).getServicePackage();
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
10070 /**
10071 * Set the release time for telephony to unbind GbaService.
10072 *
10073 * @param subId The sim that the GbaService is associated with.
10074 * @param interval The release time to unbind GbaService by millisecond.
10075 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10076 */
10077 @Override
10078 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10079 enforceModifyPermission();
10080
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
10083 return getGbaManager(subId).overrideReleaseTime(interval);
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
10088
10089 /**
10090 * Return the release time for telephony to unbind GbaService.
10091 *
10092 * @param subId The sim that the GbaService is associated with.
10093 * @return The release time to unbind GbaService by millisecond.
10094 */
10095 @Override
10096 public int getGbaReleaseTime(int subId) {
10097 enforceReadPrivilegedPermission("getGbaReleaseTime");
10098
10099 final long identity = Binder.clearCallingIdentity();
10100 try {
10101 return getGbaManager(subId).getReleaseTime();
10102 } finally {
10103 Binder.restoreCallingIdentity(identity);
10104 }
10105 }
10106
10107 private GbaManager getGbaManager(int subId) {
10108 GbaManager instance = GbaManager.getInstance(subId);
10109 if (instance == null) {
10110 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10111 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10112 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10113 }
10114 return instance;
10115 }
Hui Wang761a6682020-10-31 05:12:53 +000010116
10117 /**
10118 * indicate whether the device and the carrier can support
10119 * RCS VoLTE single registration.
10120 */
10121 @Override
10122 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010123 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10124 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10125 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10126 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010127
10128 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10129 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10130 }
10131
10132 final long identity = Binder.clearCallingIdentity();
10133 try {
10134 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10135 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010136 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10137 if (isCapable != null) {
10138 return isCapable;
10139 }
Hui Wang761a6682020-10-31 05:12:53 +000010140 }
Hui Wang67af90e2021-06-04 16:57:15 -070010141 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10142 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010143 } finally {
10144 Binder.restoreCallingIdentity(identity);
10145 }
10146 }
10147
10148 /**
10149 * Register RCS provisioning callback.
10150 */
10151 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010152 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010153 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010154 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010155 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010156 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10157 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010158
10159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10160 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10161 }
10162 if (!isImsAvailableOnDevice()) {
10163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10164 "IMS not available on device.");
10165 }
10166
10167 final long identity = Binder.clearCallingIdentity();
10168 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010169 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010170 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010171 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10172 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010173 }
Hui Wang761a6682020-10-31 05:12:53 +000010174 } finally {
10175 Binder.restoreCallingIdentity(identity);
10176 }
10177 }
10178
10179 /**
10180 * Unregister RCS provisioning callback.
10181 */
10182 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010183 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010184 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010185 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010186 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010187 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10188 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010189
10190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10191 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10192 }
10193 if (!isImsAvailableOnDevice()) {
10194 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10195 "IMS not available on device.");
10196 }
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010200 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010201 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010202 } finally {
10203 Binder.restoreCallingIdentity(identity);
10204 }
10205 }
10206
10207 /**
10208 * trigger RCS reconfiguration.
10209 */
10210 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010211 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10212 "triggerRcsReconfiguration",
10213 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010214
10215 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10216 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10217 }
10218 if (!isImsAvailableOnDevice()) {
10219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10220 "IMS not available on device.");
10221 }
10222
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
10225 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
10231 /**
10232 * Provide the client configuration parameters of the RCS application.
10233 */
10234 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010235 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10236 "setRcsClientConfiguration",
10237 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010238
10239 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10240 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10241 }
10242 if (!isImsAvailableOnDevice()) {
10243 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10244 "IMS not available on device.");
10245 }
10246
10247 final long identity = Binder.clearCallingIdentity();
10248
10249 try {
10250 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10251 if (configBinder == null) {
10252 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010253 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10254 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010255 } else {
10256 configBinder.setRcsClientConfiguration(rcc);
10257 }
10258 } catch (RemoteException e) {
10259 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010260 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10261 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010262 } finally {
10263 Binder.restoreCallingIdentity(identity);
10264 }
10265 }
10266
10267 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010268 * Enables or disables the test mode for RCS VoLTE single registration.
10269 */
10270 @Override
10271 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10273 "setRcsSingleRegistrationTestModeEnabled");
10274
10275 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10276 }
10277
10278 /**
10279 * Gets the test mode for RCS VoLTE single registration.
10280 */
10281 @Override
10282 public boolean getRcsSingleRegistrationTestModeEnabled() {
10283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10284 "getRcsSingleRegistrationTestModeEnabled");
10285
10286 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10287 }
10288
10289 /**
Hui Wang761a6682020-10-31 05:12:53 +000010290 * Overrides the config of RCS VoLTE single registration enabled for the device.
10291 */
10292 @Override
10293 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10294 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10295 "setDeviceSingleRegistrationEnabledOverride");
10296 enforceModifyPermission();
10297
10298 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10299 : Boolean.parseBoolean(enabledStr);
10300 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010301 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010302 }
10303
10304 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010305 * Sends a device to device communication message. Only usable via shell.
10306 * @param message message to send.
10307 * @param value message value.
10308 */
10309 @Override
10310 public void sendDeviceToDeviceMessage(int message, int value) {
10311 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010312 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010313 enforceModifyPermission();
10314
10315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 TelephonyConnectionService service =
10318 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10319 if (service == null) {
10320 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10321 return;
10322 }
10323 service.sendTestDeviceToDeviceMessage(message, value);
10324 } finally {
10325 Binder.restoreCallingIdentity(identity);
10326 }
10327 }
10328
Tyler Gunnbabbda02021-02-10 11:05:02 -080010329 /**
10330 * Sets the specified device to device transport active.
10331 * @param transport The transport to set active.
10332 */
10333 @Override
10334 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10335 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10336 "setActiveDeviceToDeviceTransport");
10337 enforceModifyPermission();
10338
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 TelephonyConnectionService service =
10342 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10343 if (service == null) {
10344 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10345 return;
10346 }
10347 service.setActiveDeviceToDeviceTransport(transport);
10348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
Tyler Gunn92479152021-01-20 16:30:10 -080010352
Tyler Gunnd4575212021-05-03 14:46:49 -070010353 @Override
10354 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10355 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10356 "setDeviceToDeviceForceEnabled");
10357
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 Arrays.stream(PhoneFactory.getPhones()).forEach(
10361 p -> {
10362 Phone thePhone = p.getImsPhone();
10363 if (thePhone != null && thePhone instanceof ImsPhone) {
10364 ImsPhone imsPhone = (ImsPhone) thePhone;
10365 CallTracker tracker = imsPhone.getCallTracker();
10366 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10367 ImsPhoneCallTracker imsPhoneCallTracker =
10368 (ImsPhoneCallTracker) tracker;
10369 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10370 }
10371 }
10372 }
10373 );
10374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
10377 }
10378
Tyler Gunn92479152021-01-20 16:30:10 -080010379 /**
Hui Wang761a6682020-10-31 05:12:53 +000010380 * Gets the config of RCS VoLTE single registration enabled for the device.
10381 */
10382 @Override
10383 public boolean getDeviceSingleRegistrationEnabled() {
10384 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10385 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10386 }
10387
10388 /**
10389 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10390 */
10391 @Override
10392 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10394 "setCarrierSingleRegistrationEnabledOverride");
10395 enforceModifyPermission();
10396
10397 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10398 : Boolean.parseBoolean(enabledStr);
10399 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10400 subId, enabled);
10401 }
10402
10403 /**
10404 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10405 */
10406 @Override
10407 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10408 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10409 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10410 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010411
10412 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010413 * Overrides the ims feature validation result
10414 */
10415 @Override
10416 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "setImsFeatureValidationOverride");
10419
10420 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10421 : Boolean.parseBoolean(enabledStr);
10422 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10423 subId, enabled);
10424 }
10425
10426 /**
10427 * Gets the ims feature validation override value
10428 */
10429 @Override
10430 public boolean getImsFeatureValidationOverride(int subId) {
10431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10432 "getImsFeatureValidationOverride");
10433 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10434 }
10435
10436 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010437 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10438 * their mobile plan.
10439 */
10440 @Override
10441 public String getMobileProvisioningUrl() {
10442 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10443 final long identity = Binder.clearCallingIdentity();
10444 try {
10445 return getDefaultPhone().getMobileProvisioningUrl();
10446 } finally {
10447 Binder.restoreCallingIdentity(identity);
10448 }
10449 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010450
James.cf Linbcdf8b32021-01-14 16:44:13 +080010451 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010452 * Get the EAB contact from the EAB database.
10453 */
10454 @Override
10455 public String getContactFromEab(String contact) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10457 enforceModifyPermission();
10458 final long identity = Binder.clearCallingIdentity();
10459 try {
10460 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10461 } finally {
10462 Binder.restoreCallingIdentity(identity);
10463 }
10464 }
10465
10466 /**
Calvin Pana1434322021-07-01 19:27:01 +080010467 * Get the EAB capability from the EAB database.
10468 */
10469 @Override
10470 public String getCapabilityFromEab(String contact) {
10471 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10472 enforceModifyPermission();
10473 final long identity = Binder.clearCallingIdentity();
10474 try {
10475 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10476 } finally {
10477 Binder.restoreCallingIdentity(identity);
10478 }
10479 }
10480
10481 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010482 * Remove the EAB contacts from the EAB database.
10483 */
10484 @Override
10485 public int removeContactFromEab(int subId, String contacts) {
10486 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10487 enforceModifyPermission();
10488 final long identity = Binder.clearCallingIdentity();
10489 try {
10490 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010496 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010497 public boolean getDeviceUceEnabled() {
10498 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10499 final long identity = Binder.clearCallingIdentity();
10500 try {
10501 return mApp.getDeviceUceEnabled();
10502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
10506
10507 @Override
10508 public void setDeviceUceEnabled(boolean isEnabled) {
10509 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10510 final long identity = Binder.clearCallingIdentity();
10511 try {
10512 mApp.setDeviceUceEnabled(isEnabled);
10513 } finally {
10514 Binder.restoreCallingIdentity(identity);
10515 }
10516 }
10517
Brad Ebinger14d467f2021-02-12 06:18:28 +000010518 /**
10519 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10520 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10521 */
10522 // Used for SHELL command only right now.
10523 @Override
10524 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10525 List<String> featureTags) {
10526 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10527 "addUceRegistrationOverrideShell");
10528 final long identity = Binder.clearCallingIdentity();
10529 try {
10530 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10531 new ArraySet<>(featureTags));
10532 } catch (ImsException e) {
10533 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10534 } finally {
10535 Binder.restoreCallingIdentity(identity);
10536 }
10537 }
10538
10539 /**
10540 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10541 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10542 */
10543 // Used for SHELL command only right now.
10544 @Override
10545 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10546 List<String> featureTags) {
10547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10548 "removeUceRegistrationOverrideShell");
10549 final long identity = Binder.clearCallingIdentity();
10550 try {
10551 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10552 new ArraySet<>(featureTags));
10553 } catch (ImsException e) {
10554 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 /**
10561 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10562 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10563 */
10564 // Used for SHELL command only right now.
10565 @Override
10566 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "clearUceRegistrationOverrideShell");
10569 final long identity = Binder.clearCallingIdentity();
10570 try {
10571 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10572 } catch (ImsException e) {
10573 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
10579 /**
10580 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10581 */
10582 // Used for SHELL command only right now.
10583 @Override
10584 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10586 "getLatestRcsContactUceCapabilityShell");
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10590 } catch (ImsException e) {
10591 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 /**
10598 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10599 * device does not have an active PUBLISH.
10600 */
10601 // Used for SHELL command only right now.
10602 @Override
10603 public String getLastUcePidfXmlShell(int subId) {
10604 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10605 final long identity = Binder.clearCallingIdentity();
10606 try {
10607 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10608 } catch (ImsException e) {
10609 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10610 } finally {
10611 Binder.restoreCallingIdentity(identity);
10612 }
10613 }
10614
James.cf Line8713a42021-04-29 16:04:26 +080010615 /**
10616 * Remove UCE requests cannot be sent to the network status.
10617 */
10618 // Used for SHELL command only right now.
10619 @Override
10620 public boolean removeUceRequestDisallowedStatus(int subId) {
10621 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10622 final long identity = Binder.clearCallingIdentity();
10623 try {
10624 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10625 } catch (ImsException e) {
10626 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
James.cf Lin0fc71b02021-05-25 01:37:38 +080010632 /**
10633 * Remove UCE requests cannot be sent to the network status.
10634 */
10635 // Used for SHELL command only.
10636 @Override
10637 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10642 } catch (ImsException e) {
10643 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10644 } finally {
10645 Binder.restoreCallingIdentity(identity);
10646 }
10647 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010648
James.cf Lin4b784aa2021-01-31 03:25:15 +080010649 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010650 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10651 String callingPackage) {
10652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10653 mApp, subId, "setSignalStrengthUpdateRequest");
10654
10655 final int callingUid = Binder.getCallingUid();
10656 // Verify that tha callingPackage belongs to the calling UID
10657 mApp.getSystemService(AppOpsManager.class)
10658 .checkPackage(callingUid, callingPackage);
10659
10660 validateSignalStrengthUpdateRequest(request, callingUid);
10661
10662 final long identity = Binder.clearCallingIdentity();
10663 try {
10664 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10665 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10666
10667 if (result instanceof IllegalStateException) {
10668 throw (IllegalStateException) result;
10669 }
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
10675 @Override
10676 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10677 String callingPackage) {
10678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10679 mApp, subId, "clearSignalStrengthUpdateRequest");
10680
10681 final int callingUid = Binder.getCallingUid();
10682 // Verify that tha callingPackage belongs to the calling UID
10683 mApp.getSystemService(AppOpsManager.class)
10684 .checkPackage(callingUid, callingPackage);
10685
10686 final long identity = Binder.clearCallingIdentity();
10687 try {
10688 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10689 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10690
10691 if (result instanceof IllegalStateException) {
10692 throw (IllegalStateException) result;
10693 }
10694 } finally {
10695 Binder.restoreCallingIdentity(identity);
10696 }
10697 }
10698
10699 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10700 int callingUid) {
10701 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10702 // phone/system process do not have further restriction on request
10703 return;
10704 }
10705
10706 // Applications has restrictions on how to use the request:
10707 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10708 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10709 // This is not system caller which has been checked above
10710 throw new IllegalArgumentException(
10711 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10712 }
10713
10714 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10715 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10716 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10717 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10718 || info.isEnabled()) {
10719 throw new IllegalArgumentException(
10720 "Only system can set hide fields in SignalThresholdInfo");
10721 }
10722
10723 // Thresholds length for each RAN need in range. This has been validated in
10724 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10725 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10726 final int[] thresholds = info.getThresholds();
10727 Objects.requireNonNull(thresholds);
10728 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10729 || thresholds.length
10730 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10731 throw new IllegalArgumentException(
10732 "thresholds length is out of range: " + thresholds.length);
10733 }
10734 }
10735 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010736
10737 /**
10738 * Gets the current phone capability.
10739 *
10740 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10741 * @return the PhoneCapability which describes the data connection capability of modem.
10742 * It's used to evaluate possible phone config change, for example from single
10743 * SIM device to multi-SIM device.
10744 */
10745 @Override
10746 public PhoneCapability getPhoneCapability() {
10747 enforceReadPrivilegedPermission("getPhoneCapability");
10748 final long identity = Binder.clearCallingIdentity();
10749 try {
10750 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10751 } finally {
10752 Binder.restoreCallingIdentity(identity);
10753 }
10754 }
Michele Berionne5e411512020-11-13 02:36:59 +000010755
10756 /**
10757 * Prepare TelephonyManager for an unattended reboot. The reboot is
10758 * required to be done shortly after the API is invoked.
10759 */
10760 @Override
10761 @TelephonyManager.PrepareUnattendedRebootResult
10762 public int prepareForUnattendedReboot() {
10763 enforceRebootPermission();
10764
10765 final long identity = Binder.clearCallingIdentity();
10766 try {
10767 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10768 } finally {
10769 Binder.restoreCallingIdentity(identity);
10770 }
10771 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010772
10773 /**
10774 * Request to get the current slicing configuration including URSP rules and
10775 * NSSAIs (configured, allowed and rejected).
10776 *
10777 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10778 */
10779 @Override
10780 public void getSlicingConfig(ResultReceiver callback) {
10781 enforceReadPrivilegedPermission("getSlicingConfig");
10782
10783 final long identity = Binder.clearCallingIdentity();
10784 try {
10785 Phone phone = getDefaultPhone();
10786 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10787 } finally {
10788 Binder.restoreCallingIdentity(identity);
10789 }
10790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010791}