blob: cfd33642f2d1281c7b2110b8d68f80c2da86ef3d [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 Zeng156aa4a2021-02-08 21:50:28 +0800111import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800140import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700142import com.android.internal.telephony.CallStateException;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700187import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800190import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800192import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700193import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800195import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800196import com.android.phone.callcomposer.CallComposerPictureManager;
197import com.android.phone.callcomposer.CallComposerPictureTransfer;
198import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800201import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700203import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800204import com.android.services.telephony.TelecomAccountRegistry;
205import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800206import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800207
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700209import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.IOException;
211import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800215import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800217import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100218import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700220import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800224import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800225import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
227/**
228 * Implementation of the ITelephony interface.
229 */
Santos Cordon117fee72014-05-16 17:56:12 -0700230public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 private static final String LOG_TAG = "PhoneInterfaceManager";
232 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
233 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
236 // Message codes used with mMainThreadHandler
237 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700238 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
239 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240 private static final int CMD_OPEN_CHANNEL = 9;
241 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
242 private static final int CMD_CLOSE_CHANNEL = 11;
243 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800244 private static final int CMD_NV_READ_ITEM = 13;
245 private static final int EVENT_NV_READ_ITEM_DONE = 14;
246 private static final int CMD_NV_WRITE_ITEM = 15;
247 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
248 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
249 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_RESET_MODEM_CONFIG = 19;
251 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800252 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
253 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800254 private static final int CMD_SEND_ENVELOPE = 25;
255 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000256 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
257 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700258 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
259 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
260 private static final int CMD_EXCHANGE_SIM_IO = 31;
261 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
263 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700264 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700266 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
267 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700268 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
269 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
270 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
271 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700272 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
273 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
274 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
275 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700276 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800277 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
278 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000279 private static final int CMD_SWITCH_SLOTS = 50;
280 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700281 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
282 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
283 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
284 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
285 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
286 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
287 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
288 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700289 private static final int CMD_GET_ALL_CELL_INFO = 60;
290 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
291 private static final int CMD_GET_CELL_LOCATION = 62;
292 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_MODEM_REBOOT = 64;
294 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700295 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
296 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800297 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
298 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700299 private static final int CMD_GET_MODEM_STATUS = 70;
300 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700301 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
302 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700303 private static final int CMD_ERASE_MODEM_CONFIG = 74;
304 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800305 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
306 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
307 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
308 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800309 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
310 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800312 private static final int CMD_GET_CALL_FORWARDING = 83;
313 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
314 private static final int CMD_SET_CALL_FORWARDING = 85;
315 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
316 private static final int CMD_GET_CALL_WAITING = 87;
317 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
318 private static final int CMD_SET_CALL_WAITING = 89;
319 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700320 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
321 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
322 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
323 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700324 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
325 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800326 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
327 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800328 private static final int CMD_SET_DATA_THROTTLING = 99;
329 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800330 private static final int CMD_SET_SIM_POWER = 101;
331 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800332 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
333 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
334 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
335 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800336 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
337 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000338 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800339 private static final int CMD_GET_SLICING_CONFIG = 110;
340 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800341 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800343 // Parameters of select command.
344 private static final int SELECT_COMMAND = 0xA4;
345 private static final int SELECT_P1 = 0x04;
346 private static final int SELECT_P2 = 0;
347 private static final int SELECT_P3 = 0x10;
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 /** The singleton instance. */
350 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800351 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800355 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700356 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800357 private AppOpsManager mAppOps;
358 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800359 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700361 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800362 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363
Peter Wangdafb9ac2020-01-15 14:13:38 -0800364 /** User Activity */
365 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800366 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
367
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700368 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
369
Derek Tan97ebb422014-09-05 16:55:38 -0700370 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
371 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800372 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800373 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700374
Michelecea4cf22018-12-21 15:00:11 -0800375 // String to store multi SIM allowed
376 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
377
Derek Tan740e1672017-06-27 14:56:27 -0700378 // The AID of ISD-R.
379 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
380
yinxub1bed742017-04-17 11:45:04 -0700381 private NetworkScanRequestTracker mNetworkScanRequestTracker;
382
David Kelly5e06a7f2018-03-12 14:10:59 +0000383 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
384 private static final int MANUFACTURER_CODE_LENGTH = 8;
385
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800386 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800387 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800388
Derek Tan89e89d42014-07-08 17:00:10 -0700389 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700390 * Experiment flag to enable erase modem config on reset network, default value is false
391 */
392 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
393 "reset_network_erase_modem_config_enabled";
394
Rambo Wang0f050d82021-02-12 11:43:36 -0800395 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
396
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700398 * A request object to use for transmitting data to an ICC.
399 */
400 private static final class IccAPDUArgument {
401 public int channel, cla, command, p1, p2, p3;
402 public String data;
403
404 public IccAPDUArgument(int channel, int cla, int command,
405 int p1, int p2, int p3, String data) {
406 this.channel = channel;
407 this.cla = cla;
408 this.command = command;
409 this.p1 = p1;
410 this.p2 = p2;
411 this.p3 = p3;
412 this.data = data;
413 }
414 }
415
416 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700417 * A request object to use for transmitting data to an ICC.
418 */
419 private static final class ManualNetworkSelectionArgument {
420 public OperatorInfo operatorInfo;
421 public boolean persistSelection;
422
423 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
424 this.operatorInfo = operatorInfo;
425 this.persistSelection = persistSelection;
426 }
427 }
428
429 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
431 * request after sending. The main thread will notify the request when it is complete.
432 */
433 private static final class MainThreadRequest {
434 /** The argument to use for the request */
435 public Object argument;
436 /** The result of the request that is run on the main thread */
437 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800438 // The subscriber id that this request applies to. Defaults to
439 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
440 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Nathan Harold92bed182018-10-12 18:16:49 -0700442 // In cases where subId is unavailable, the caller needs to specify the phone.
443 public Phone phone;
444
vagdeviaf9a5b92018-08-15 16:01:53 -0700445 public WorkSource workSource;
446
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 public MainThreadRequest(Object argument) {
448 this.argument = argument;
449 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
452 this.argument = argument;
453 if (phone != null) {
454 this.phone = phone;
455 }
456 this.workSource = workSource;
457 }
458
vagdeviaf9a5b92018-08-15 16:01:53 -0700459 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800460 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800461 if (subId != null) {
462 this.subId = subId;
463 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700464 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 }
467
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800468 private static final class IncomingThirdPartyCallArgs {
469 public final ComponentName component;
470 public final String callId;
471 public final String callerDisplayName;
472
473 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
474 String callerDisplayName) {
475 this.component = component;
476 this.callId = callId;
477 this.callerDisplayName = callerDisplayName;
478 }
479 }
480
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 /**
482 * A handler that processes messages on the main thread in the phone process. Since many
483 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
484 * inbound binder threads to the main thread in the phone process. The Binder thread
485 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
486 * on, which will be notified when the operation completes and will contain the result of the
487 * request.
488 *
489 * <p>If a MainThreadRequest object is provided in the msg.obj field,
490 * note that request.result must be set to something non-null for the calling thread to
491 * unblock.
492 */
493 private final class MainThreadHandler extends Handler {
494 @Override
495 public void handleMessage(Message msg) {
496 MainThreadRequest request;
497 Message onCompleted;
498 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800501 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502
503 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 case CMD_HANDLE_USSD_REQUEST: {
505 request = (MainThreadRequest) msg.obj;
506 final Phone phone = getPhoneFromRequest(request);
507 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
508 String ussdRequest = ussdObject.first;
509 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700510
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 if (!isUssdApiAllowed(request.subId)) {
512 // Carrier does not support use of this API, return failure.
513 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
514 UssdResponse response = new UssdResponse(ussdRequest, null);
515 Bundle returnData = new Bundle();
516 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
517 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 request.result = true;
520 notifyRequester(request);
521 return;
522 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700523
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 try {
525 request.result = phone != null
526 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
527 } catch (CallStateException cse) {
528 request.result = false;
529 }
530 // Wake up the requesting thread
531 notifyRequester(request);
532 break;
pkanwar32d516d2016-10-14 19:37:38 -0700533 }
534
Yorke Lee716f67e2015-06-17 15:39:16 -0700535 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 final Phone phone = getPhoneFromRequest(request);
538 request.result = phone != null ?
539 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
540 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("iccTransmitApduLogicalChannel: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
556 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 iccArgument.channel, iccArgument.cla, iccArgument.command,
559 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 ar = (AsyncResult) msg.obj;
566 request = (MainThreadRequest) ar.userObj;
567 if (ar.exception == null && ar.result != null) {
568 request.result = ar.result;
569 } else {
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
571 if (ar.result == null) {
572 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800573 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800575 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 } else {
577 loge("iccTransmitApduLogicalChannel: Unknown exception");
578 }
579 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 break;
582
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
584 request = (MainThreadRequest) msg.obj;
585 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800586 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (uiccCard == null) {
588 loge("iccTransmitApduBasicChannel: No UICC");
589 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
593 request);
594 uiccCard.iccTransmitApduBasicChannel(
595 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
596 iccArgument.p3, iccArgument.data, onCompleted);
597 }
598 break;
599
600 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
605 } else {
606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("iccTransmitApduBasicChannel: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("iccTransmitApduBasicChannel: CommandException: " +
611 ar.exception);
612 } else {
613 loge("iccTransmitApduBasicChannel: Unknown exception");
614 }
615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 break;
618
619 case CMD_EXCHANGE_SIM_IO:
620 request = (MainThreadRequest) msg.obj;
621 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 if (uiccCard == null) {
624 loge("iccExchangeSimIO: No UICC");
625 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 } else {
628 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
629 request);
630 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
631 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
632 iccArgument.data, onCompleted);
633 }
634 break;
635
636 case EVENT_EXCHANGE_SIM_IO_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
641 } else {
642 request.result = new IccIoResult(0x6f, 0, (byte[])null);
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 case CMD_SEND_ENVELOPE:
648 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800649 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 if (uiccCard == null) {
651 loge("sendEnvelopeWithStatus: No UICC");
652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
656 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
657 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 break;
659
660 case EVENT_SEND_ENVELOPE_DONE:
661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 request.result = new IccIoResult(0x6F, 0, (byte[])null);
667 if (ar.result == null) {
668 loge("sendEnvelopeWithStatus: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("sendEnvelopeWithStatus: CommandException: " +
671 ar.exception);
672 } else {
673 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
674 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 break;
678
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 case CMD_OPEN_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800682 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 if (uiccCard == null) {
684 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800685 request.result = new IccOpenLogicalChannelResponse(-1,
686 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
691 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
695 case EVENT_OPEN_CHANNEL_DONE:
696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 int[] result = (int[]) ar.result;
701 int channelId = result[0];
702 byte[] selectResponse = null;
703 if (result.length > 1) {
704 selectResponse = new byte[result.length - 1];
705 for (int i = 1; i < result.length; ++i) {
706 selectResponse[i - 1] = (byte) result[i];
707 }
708 }
709 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 if (ar.result == null) {
713 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 if (ar.exception != null) {
716 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
717 }
718
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700720 if (ar.exception instanceof CommandException) {
721 CommandException.Error error =
722 ((CommandException) (ar.exception)).getCommandError();
723 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700724 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700725 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 }
728 }
729 openChannelResp = new IccOpenLogicalChannelResponse(
730 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700732 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case CMD_CLOSE_CHANNEL:
737 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800738 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700739 if (uiccCard == null) {
740 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900741 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
745 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 break;
748
749 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800750 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
751 break;
752
753 case CMD_NV_READ_ITEM:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800756 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
757 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800758 break;
759
760 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800766 request.result = "";
767 if (ar.result == null) {
768 loge("nvReadItem: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("nvReadItem: CommandException: " +
771 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 break;
778
Jake Hambye994d462014-02-03 13:10:13 -0800779 case CMD_NV_WRITE_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
782 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700784 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_WRITE_ITEM_DONE:
788 handleNullReturnEvent(msg, "nvWriteItem");
789 break;
790
791 case CMD_NV_WRITE_CDMA_PRL:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
797 case EVENT_NV_WRITE_CDMA_PRL_DONE:
798 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
799 break;
800
chen xu6dac5ab2018-10-26 17:39:23 -0700801 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800802 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700803 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800804 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800805 break;
806
chen xu6dac5ab2018-10-26 17:39:23 -0700807 case EVENT_RESET_MODEM_CONFIG_DONE:
808 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800809 break;
810
Sooraj Sasindran37444802020-08-11 10:40:43 -0700811 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
812 request = (MainThreadRequest) msg.obj;
813 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
814 request);
815 Phone phone = getPhoneFromRequest(request);
816 if (phone != null) {
817 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
818 } else {
819 loge("isNRDualConnectivityEnabled: No phone object");
820 request.result = false;
821 notifyRequester(request);
822 }
823 break;
824 }
825
826 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null && ar.result != null) {
830 request.result = ar.result;
831 } else {
832 // request.result must be set to something non-null
833 // for the calling thread to unblock
834 if (request.result != null) {
835 request.result = ar.result;
836 } else {
837 request.result = false;
838 }
839 if (ar.result == null) {
840 loge("isNRDualConnectivityEnabled: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("isNRDualConnectivityEnabled: CommandException: "
843 + ar.exception);
844 } else {
845 loge("isNRDualConnectivityEnabled: Unknown exception");
846 }
847 }
848 notifyRequester(request);
849 break;
850
851 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
852 request = (MainThreadRequest) msg.obj;
853 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
854 Phone phone = getPhoneFromRequest(request);
855 if (phone != null) {
856 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
857 request.workSource);
858 } else {
859 loge("enableNrDualConnectivity: No phone object");
860 request.result =
861 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
862 notifyRequester(request);
863 }
864 break;
865 }
866
867 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null) {
871 request.result =
872 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
873 } else {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
877 if (ar.exception instanceof CommandException) {
878 CommandException.Error error =
879 ((CommandException) (ar.exception)).getCommandError();
880 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
881 request.result =
882 TelephonyManager
883 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000884 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
885 request.result =
886 TelephonyManager
887 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700888 }
889 loge("enableNrDualConnectivity" + ": CommandException: "
890 + ar.exception);
891 } else {
892 loge("enableNrDualConnectivity" + ": Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897 }
898
SongFerngWang3ef3e072020-12-21 16:41:52 +0800899 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
902 request);
903 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 break;
905
SongFerngWang3ef3e072020-12-21 16:41:52 +0800906 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result; // Integer
911 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530912 // request.result must be set to something non-null
913 // for the calling thread to unblock
914 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 loge("getAllowedNetworkTypesBitmask: CommandException: "
919 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 }
923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 break;
926
SongFerngWang3ef3e072020-12-21 16:41:52 +0800927 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800929 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
930 request);
931 Pair<Integer, Long> reasonWithNetworkTypes =
932 (Pair<Integer, Long>) request.argument;
933 getPhoneFromRequest(request).setAllowedNetworkTypes(
934 reasonWithNetworkTypes.first,
935 reasonWithNetworkTypes.second,
936 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800937 break;
938
SongFerngWang3ef3e072020-12-21 16:41:52 +0800939 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
940 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800941 break;
942
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000943 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
944 request = (MainThreadRequest)msg.obj;
945 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000947 break;
948
949 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
950 ar = (AsyncResult)msg.obj;
951 request = (MainThreadRequest)ar.userObj;
952 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000954 break;
955
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800956 case CMD_SET_VOICEMAIL_NUMBER:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
959 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800960 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
961 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800962 break;
963
964 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
965 handleNullReturnEvent(msg, "setVoicemailNumber");
966 break;
967
Stuart Scott54788802015-03-30 13:18:01 -0700968 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
971 request);
972 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
973 break;
974
975 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
976 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
977 break;
978
Shishir Agrawal302c8692015-06-19 13:49:39 -0700979 case CMD_PERFORM_NETWORK_SCAN:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
982 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
983 break;
984
Hall Liu27d24262020-09-18 19:04:59 -0700985 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700988 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
989 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
990 request.argument;
991 int callForwardingReason = args.first;
992 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800993 break;
Hall Liu27d24262020-09-18 19:04:59 -0700994 }
995 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700998 TelephonyManager.CallForwardingInfoCallback callback =
999 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1000 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001001 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001002 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1004 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1005 // Service Class is a bit mask per 3gpp 27.007. Search for
1006 // any service for voice call.
1007 if ((callForwardInfo.serviceClass
1008 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001009 callForwardingInfo = new CallForwardingInfo(true,
1010 callForwardInfo.reason,
1011 callForwardInfo.number,
1012 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001013 break;
1014 }
1015 }
1016 // Didn't find a call forward info for voice call.
1017 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001018 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1019 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001020 }
Hall Liu27d24262020-09-18 19:04:59 -07001021 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001022 } else {
1023 if (ar.result == null) {
1024 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1025 }
1026 if (ar.exception != null) {
1027 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1028 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001029 int errorCode = TelephonyManager
1030 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001031 if (ar.exception instanceof CommandException) {
1032 CommandException.Error error =
1033 ((CommandException) (ar.exception)).getCommandError();
1034 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001035 errorCode = TelephonyManager
1036 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001037 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager
1039 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 }
1041 }
Hall Liu27d24262020-09-18 19:04:59 -07001042 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001043 }
Shuo Qian4a594052020-01-23 11:59:30 -08001044 break;
Hall Liu27d24262020-09-18 19:04:59 -07001045 }
Shuo Qian4a594052020-01-23 11:59:30 -08001046
Hall Liu27d24262020-09-18 19:04:59 -07001047 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001050 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001051 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001052 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1053 request.argument).first;
1054 request.phone.setCallForwardingOption(
1055 callForwardingInfoToSet.isEnabled()
1056 ? CommandsInterface.CF_ACTION_ENABLE
1057 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001058 callForwardingInfoToSet.getReason(),
1059 callForwardingInfoToSet.getNumber(),
1060 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1061 break;
Hall Liu27d24262020-09-18 19:04:59 -07001062 }
Shuo Qian4a594052020-01-23 11:59:30 -08001063
Hall Liu27d24262020-09-18 19:04:59 -07001064 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001067 Consumer<Integer> callback =
1068 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1069 request.argument).second;
1070 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001071 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001072 int errorCode = TelephonyManager.CallForwardingInfoCallback
1073 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001074 if (ar.exception instanceof CommandException) {
1075 CommandException.Error error =
1076 ((CommandException) (ar.exception)).getCommandError();
1077 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001078 errorCode = TelephonyManager.CallForwardingInfoCallback
1079 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001080 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 errorCode = TelephonyManager.CallForwardingInfoCallback
1082 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001083 }
1084 }
1085 callback.accept(errorCode);
1086 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001087 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001088 }
Shuo Qian4a594052020-01-23 11:59:30 -08001089 break;
Hall Liu27d24262020-09-18 19:04:59 -07001090 }
Shuo Qian4a594052020-01-23 11:59:30 -08001091
Hall Liu27d24262020-09-18 19:04:59 -07001092 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1095 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1096 break;
Hall Liu27d24262020-09-18 19:04:59 -07001097 }
Shuo Qian4a594052020-01-23 11:59:30 -08001098
Hall Liu27d24262020-09-18 19:04:59 -07001099 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001102 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001103 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1104 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001105 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001106 // Service Class is a bit mask per 3gpp 27.007.
1107 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 if (callForwardResults.length > 1
1109 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001110 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001111 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001112 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1113 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001115 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001116 }
1117 } else {
1118 if (ar.result == null) {
1119 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1120 }
1121 if (ar.exception != null) {
1122 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1123 }
1124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1128 callForwardingStatus =
1129 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1130 }
1131 }
1132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1141 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001142 break;
Hall Liu27d24262020-09-18 19:04:59 -07001143 }
Shuo Qian4a594052020-01-23 11:59:30 -08001144
Hall Liu27d24262020-09-18 19:04:59 -07001145 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001148 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1149 Consumer<Integer> callback =
1150 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1151 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001152 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001153 if (ar.exception instanceof CommandException) {
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
1156 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1157 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1158 } else {
1159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1160 }
1161 } else {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1163 }
1164 } else {
1165 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1166 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001167 }
Shuo Qian4a594052020-01-23 11:59:30 -08001168 break;
Hall Liu27d24262020-09-18 19:04:59 -07001169 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 CellNetworkScanResult cellScanResult;
1174 if (ar.exception == null && ar.result != null) {
1175 cellScanResult = new CellNetworkScanResult(
1176 CellNetworkScanResult.STATUS_SUCCESS,
1177 (List<OperatorInfo>) ar.result);
1178 } else {
1179 if (ar.result == null) {
1180 loge("getCellNetworkScanResults: Empty response");
1181 }
1182 if (ar.exception != null) {
1183 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1184 }
1185 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1190 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1191 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1192 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1193 }
1194 }
1195 cellScanResult = new CellNetworkScanResult(errorCode, null);
1196 }
1197 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1202 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001203 ManualNetworkSelectionArgument selArg =
1204 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1206 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001207 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1208 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 break;
1210
1211 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 if (ar.exception == null) {
1215 request.result = true;
1216 } else {
1217 request.result = false;
1218 loge("setNetworkSelectionModeManual " + ar.exception);
1219 }
1220 notifyRequester(request);
1221 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001222 break;
1223
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 case CMD_GET_MODEM_ACTIVITY_INFO:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001227 if (defaultPhone != null) {
1228 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 } else {
1230 ResultReceiver result = (ResultReceiver) request.argument;
1231 Bundle bundle = new Bundle();
1232 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001233 new ModemActivityInfo(0, 0, 0,
1234 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001236 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 break;
1238
Hall Liud0f208c2020-10-14 16:54:44 -07001239 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001242 ResultReceiver result = (ResultReceiver) request.argument;
1243
Hall Liud0f208c2020-10-14 16:54:44 -07001244 ModemActivityInfo ret = null;
1245 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 // Update the last modem activity info and the result of the request.
1248 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1249 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001250 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001251 int[] txTimeMs = info.getTransmitTimeMillis();
1252 int[] lastModemTxTimeMs = mLastModemActivityInfo
1253 .getTransmitTimeMillis();
1254 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1255 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1256 }
Hall Liu49656c02020-10-09 19:00:11 -07001257 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001258 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1259 + mLastModemActivityInfo.getSleepTimeMillis());
1260 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1261 + mLastModemActivityInfo.getIdleTimeMillis());
1262 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1263 mLastModemActivityInfo.setReceiveTimeMillis(
1264 info.getReceiveTimeMillis()
1265 + mLastModemActivityInfo.getReceiveTimeMillis());
1266 }
Hall Liu49656c02020-10-09 19:00:11 -07001267 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001268 mLastModemActivityInfo.getSleepTimeMillis(),
1269 mLastModemActivityInfo.getIdleTimeMillis(),
1270 mLastModemActivityInfo.getTransmitTimeMillis(),
1271 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else {
1273 if (ar.result == null) {
1274 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001275 error = TelephonyManager.ModemActivityInfoException
1276 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else if (ar.exception instanceof CommandException) {
1278 loge("queryModemActivityInfo: CommandException: " +
1279 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 } else {
1283 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001284 error = TelephonyManager.ModemActivityInfoException
1285 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 }
1287 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001288 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001289 if (ret != null) {
1290 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1291 } else {
1292 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1293 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001294 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001296 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001297 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001298
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 case CMD_SET_ALLOWED_CARRIERS:
1300 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001301 CarrierRestrictionRules argument =
1302 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001304 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 break;
1306
1307 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 if (ar.exception == null && ar.result != null) {
1311 request.result = ar.result;
1312 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001313 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1314 if (ar.exception instanceof CommandException) {
1315 loge("setAllowedCarriers: CommandException: " + ar.exception);
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 request.result =
1320 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1321 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001322 } else {
1323 loge("setAllowedCarriers: Unknown exception");
1324 }
1325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 break;
1328
1329 case CMD_GET_ALLOWED_CARRIERS:
1330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001332 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 break;
1334
1335 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 if (ar.exception == null && ar.result != null) {
1339 request.result = ar.result;
1340 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001341 request.result = new IllegalStateException(
1342 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001343 if (ar.result == null) {
1344 loge("getAllowedCarriers: Empty response");
1345 } else if (ar.exception instanceof CommandException) {
1346 loge("getAllowedCarriers: CommandException: " +
1347 ar.exception);
1348 } else {
1349 loge("getAllowedCarriers: Unknown exception");
1350 }
1351 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001353 break;
1354
Nathan Haroldb3014052017-01-25 15:57:32 -08001355 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
1358 if (ar.exception == null && ar.result != null) {
1359 request.result = ar.result;
1360 } else {
1361 request.result = new IllegalArgumentException(
1362 "Failed to retrieve Forbidden Plmns");
1363 if (ar.result == null) {
1364 loge("getForbiddenPlmns: Empty response");
1365 } else {
1366 loge("getForbiddenPlmns: Unknown exception");
1367 }
1368 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371
1372 case CMD_GET_FORBIDDEN_PLMNS:
1373 request = (MainThreadRequest) msg.obj;
1374 uiccCard = getUiccCardFromRequest(request);
1375 if (uiccCard == null) {
1376 loge("getForbiddenPlmns() UiccCard is null");
1377 request.result = new IllegalArgumentException(
1378 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001379 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001380 break;
1381 }
1382 Integer appType = (Integer) request.argument;
1383 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1384 if (uiccApp == null) {
1385 loge("getForbiddenPlmns() no app with specified type -- "
1386 + appType);
1387 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001389 break;
1390 } else {
1391 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1392 + " specified type -- " + appType);
1393 }
1394 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1395 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1396 onCompleted);
1397 break;
1398
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001399 case CMD_SWITCH_SLOTS:
1400 request = (MainThreadRequest) msg.obj;
1401 int[] physicalSlots = (int[]) request.argument;
1402 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1403 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1404 break;
1405
1406 case EVENT_SWITCH_SLOTS_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001410 notifyRequester(request);
1411 break;
1412 case CMD_GET_NETWORK_SELECTION_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1415 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1416 break;
1417
1418 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception != null) {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1423 } else {
1424 int mode = ((int[]) ar.result)[0];
1425 if (mode == 0) {
1426 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1427 } else {
1428 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1429 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001430 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 notifyRequester(request);
1432 break;
1433 case CMD_GET_CDMA_ROAMING_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1436 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1437 break;
1438 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception != null) {
1442 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1443 } else {
1444 request.result = ((int[]) ar.result)[0];
1445 }
1446 notifyRequester(request);
1447 break;
1448 case CMD_SET_CDMA_ROAMING_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1451 int mode = (int) request.argument;
1452 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1453 break;
1454 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 request.result = ar.exception == null;
1458 notifyRequester(request);
1459 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001460 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1463 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1464 break;
1465 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
1468 if (ar.exception != null) {
1469 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1470 } else {
1471 request.result = ((int[]) ar.result)[0];
1472 }
1473 notifyRequester(request);
1474 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1476 request = (MainThreadRequest) msg.obj;
1477 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1478 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001479 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1480 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 break;
1482 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
1485 request.result = ar.exception == null;
1486 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001487 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 case CMD_GET_ALL_CELL_INFO:
1489 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001491 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 case EVENT_GET_ALL_CELL_INFO_DONE:
1494 ar = (AsyncResult) msg.obj;
1495 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001496 // If a timeout occurs, the response will be null
1497 request.result = (ar.exception == null && ar.result != null)
1498 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 synchronized (request) {
1500 request.notifyAll();
1501 }
1502 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001503 case CMD_REQUEST_CELL_INFO_UPDATE:
1504 request = (MainThreadRequest) msg.obj;
1505 request.phone.requestCellInfoUpdate(request.workSource,
1506 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1507 break;
1508 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1512 try {
1513 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001515 cb.onError(
1516 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1517 ar.exception.getClass().getName(),
1518 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001521 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else {
1523 // use the result as returned
1524 cb.onCellInfo((List<CellInfo>) ar.result);
1525 }
1526 } catch (RemoteException re) {
1527 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1528 }
1529 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001530 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 request = (MainThreadRequest) msg.obj;
1532 WorkSource ws = (WorkSource) request.argument;
1533 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001534 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001535 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001536 }
1537 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 if (ar.exception == null) {
1541 request.result = ar.result;
1542 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001543 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001544 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001545 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001546 }
1547
1548 synchronized (request) {
1549 request.notifyAll();
1550 }
1551 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001552 }
chen xu6dac5ab2018-10-26 17:39:23 -07001553 case CMD_MODEM_REBOOT:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001556 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001557 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001558 case EVENT_CMD_MODEM_REBOOT_DONE:
1559 handleNullReturnEvent(msg, "rebootModem");
1560 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001561 case CMD_REQUEST_ENABLE_MODEM:
1562 request = (MainThreadRequest) msg.obj;
1563 boolean enable = (boolean) request.argument;
1564 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001565 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 PhoneConfigurationManager.getInstance()
1567 .enablePhone(request.phone, enable, onCompleted);
1568 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001569 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001573 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001574 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 if ((boolean) request.result) {
1576 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1577 updateModemStateMetrics();
1578 } else {
1579 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1580 + ar.exception);
1581 }
1582 notifyRequester(request);
1583 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001584 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001585 case CMD_GET_MODEM_STATUS:
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1588 PhoneConfigurationManager.getInstance()
1589 .getPhoneStatusFromModem(request.phone, onCompleted);
1590 break;
1591 case EVENT_GET_MODEM_STATUS_DONE:
1592 ar = (AsyncResult) msg.obj;
1593 request = (MainThreadRequest) ar.userObj;
1594 int id = request.phone.getPhoneId();
1595 if (ar.exception == null && ar.result != null) {
1596 request.result = ar.result;
1597 //update the cache as modem status has changed
1598 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1599 (boolean) request.result);
1600 } else {
1601 // Return true if modem status cannot be retrieved. For most cases,
1602 // modem status is on. And for older version modems, GET_MODEM_STATUS
1603 // and disable modem are not supported. Modem is always on.
1604 // TODO: this should be fixed in R to support a third
1605 // status UNKNOWN b/131631629
1606 request.result = true;
1607 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1608 + ar.exception);
1609 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001610 notifyRequester(request);
1611 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001612 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1615 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1616 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1617 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1618 break;
1619 }
1620 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1624 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1625 args.second.accept(ar.exception == null);
1626 notifyRequester(request);
1627 break;
1628 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001629 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1630 request = (MainThreadRequest) msg.obj;
1631 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1632 Phone phone = getPhoneFromRequest(request);
1633 if (phone != null) {
1634 phone.getSystemSelectionChannels(onCompleted);
1635 } else {
1636 loge("getSystemSelectionChannels: No phone object");
1637 request.result = new ArrayList<RadioAccessSpecifier>();
1638 notifyRequester(request);
1639 }
1640 break;
1641 }
1642 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception == null && ar.result != null) {
1646 request.result = ar.result;
1647 } else {
1648 request.result = new IllegalArgumentException(
1649 "Failed to retrieve system selection channels");
1650 if (ar.result == null) {
1651 loge("getSystemSelectionChannels: Empty response");
1652 } else {
1653 loge("getSystemSelectionChannels: Unknown exception");
1654 }
1655 }
1656 notifyRequester(request);
1657 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001658 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 if (ar.exception == null && ar.result != null) {
1662 request.result = ar.result;
1663 } else {
1664 request.result = -1;
1665 loge("Failed to set Forbidden Plmns");
1666 if (ar.result == null) {
1667 loge("setForbidenPlmns: Empty response");
1668 } else if (ar.exception != null) {
1669 loge("setForbiddenPlmns: Exception: " + ar.exception);
1670 request.result = -1;
1671 } else {
1672 loge("setForbiddenPlmns: Unknown exception");
1673 }
1674 }
1675 notifyRequester(request);
1676 break;
1677 case CMD_SET_FORBIDDEN_PLMNS:
1678 request = (MainThreadRequest) msg.obj;
1679 uiccCard = getUiccCardFromRequest(request);
1680 if (uiccCard == null) {
1681 loge("setForbiddenPlmns: UiccCard is null");
1682 request.result = -1;
1683 notifyRequester(request);
1684 break;
1685 }
1686 Pair<Integer, List<String>> setFplmnsArgs =
1687 (Pair<Integer, List<String>>) request.argument;
1688 appType = setFplmnsArgs.first;
1689 List<String> fplmns = setFplmnsArgs.second;
1690 uiccApp = uiccCard.getApplicationByType(appType);
1691 if (uiccApp == null) {
1692 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1693 request.result = -1;
1694 loge("Failed to get UICC App");
1695 notifyRequester(request);
1696 } else {
1697 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1698 ((SIMRecords) uiccApp.getIccRecords())
1699 .setForbiddenPlmns(onCompleted, fplmns);
1700 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001701 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001702 case CMD_ERASE_MODEM_CONFIG:
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1705 defaultPhone.eraseModemConfig(onCompleted);
1706 break;
1707 case EVENT_ERASE_MODEM_CONFIG_DONE:
1708 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001709 break;
zoey chene02881a2019-12-30 16:11:23 +08001710
Kai Shif70f46f2021-03-03 13:59:46 -08001711 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1712 request = (MainThreadRequest) msg.obj;
1713 request.result = defaultPhone.eraseDataInSharedPreferences();
1714 notifyRequester(request);
1715 break;
1716
zoey chene02881a2019-12-30 16:11:23 +08001717 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1718 request = (MainThreadRequest) msg.obj;
1719 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1720 Pair<String, String> changed = (Pair<String, String>) request.argument;
1721 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1722 changed.first, changed.second, onCompleted);
1723 break;
1724 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception == null) {
1728 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001729 // If the operation is successful, update the PIN storage
1730 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1731 int phoneId = getPhoneFromRequest(request).getPhoneId();
1732 UiccController.getInstance().getPinStorage()
1733 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001734 } else {
1735 request.result = msg.arg1;
1736 }
1737 notifyRequester(request);
1738 break;
1739
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1743 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1744 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1745 enabled.first, enabled.second, onCompleted);
1746 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001747 }
zoey chene02881a2019-12-30 16:11:23 +08001748 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null) {
1752 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001753 // If the operation is successful, update the PIN storage
1754 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1755 int phoneId = getPhoneFromRequest(request).getPhoneId();
1756 if (enabled.first) {
1757 UiccController.getInstance().getPinStorage()
1758 .storePin(enabled.second, phoneId);
1759 } else {
1760 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1761 }
zoey chene02881a2019-12-30 16:11:23 +08001762 } else {
1763 request.result = msg.arg1;
1764 }
Michele Berionne5e411512020-11-13 02:36:59 +00001765
1766
zoey chene02881a2019-12-30 16:11:23 +08001767 notifyRequester(request);
1768 break;
1769
Peter Wangdafb9ac2020-01-15 14:13:38 -08001770 case MSG_NOTIFY_USER_ACTIVITY:
1771 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001772 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001773 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1774 getDefaultPhone().getContext().sendBroadcastAsUser(
1775 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1776 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001777
1778 case CMD_SET_DATA_THROTTLING: {
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1781 DataThrottlingRequest dataThrottlingRequest =
1782 (DataThrottlingRequest) request.argument;
1783 Phone phone = getPhoneFromRequest(request);
1784 if (phone != null) {
1785 phone.setDataThrottling(onCompleted,
1786 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1787 dataThrottlingRequest.getCompletionDurationMillis());
1788 } else {
1789 loge("setDataThrottling: No phone object");
1790 request.result =
1791 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1792 notifyRequester(request);
1793 }
1794
1795 break;
1796 }
1797 case EVENT_SET_DATA_THROTTLING_DONE:
1798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800
1801 if (ar.exception == null) {
1802 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1803 } else if (ar.exception instanceof CommandException) {
1804 loge("setDataThrottling: CommandException: " + ar.exception);
1805 CommandException.Error error =
1806 ((CommandException) (ar.exception)).getCommandError();
1807
1808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1809 request.result = TelephonyManager
1810 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1811 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1812 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001813 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1814 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001815 } else {
1816 request.result =
1817 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1818 }
1819 } else {
1820 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1821 }
1822 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1823 notifyRequester(request);
1824 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001825
1826 case CMD_SET_SIM_POWER: {
1827 request = (MainThreadRequest) msg.obj;
1828 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1829 request = (MainThreadRequest) msg.obj;
1830 int stateToSet =
1831 ((Pair<Integer, IIntegerConsumer>)
1832 request.argument).first;
1833 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1834 break;
1835 }
1836 case EVENT_SET_SIM_POWER_DONE: {
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 IIntegerConsumer callback =
1840 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1841 if (ar.exception != null) {
1842 loge("setSimPower exception: " + ar.exception);
1843 int errorCode = TelephonyManager.CallForwardingInfoCallback
1844 .RESULT_ERROR_UNKNOWN;
1845 if (ar.exception instanceof CommandException) {
1846 CommandException.Error error =
1847 ((CommandException) (ar.exception)).getCommandError();
1848 if (error == CommandException.Error.SIM_ERR) {
1849 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1850 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1851 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1852 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1853 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1854 } else {
1855 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1856 }
1857 }
1858 try {
1859 callback.accept(errorCode);
1860 } catch (RemoteException e) {
1861 // Ignore if the remote process is no longer available to call back.
1862 Log.w(LOG_TAG, "setSimPower: callback not available.");
1863 }
1864 } else {
1865 try {
1866 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1867 } catch (RemoteException e) {
1868 // Ignore if the remote process is no longer available to call back.
1869 Log.w(LOG_TAG, "setSimPower: callback not available.");
1870 }
1871 }
1872 break;
1873 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001874 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1875 request = (MainThreadRequest) msg.obj;
1876
1877 final Phone phone = getPhoneFromRequest(request);
1878 if (phone == null || phone.getServiceStateTracker() == null) {
1879 request.result = new IllegalStateException("Phone or SST is null");
1880 notifyRequester(request);
1881 break;
1882 }
1883
1884 Pair<Integer, SignalStrengthUpdateRequest> pair =
1885 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1886 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1887 request);
1888 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1889 request.subId, pair.first /*callingUid*/,
1890 pair.second /*request*/, onCompleted);
1891 break;
1892 }
1893 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896 // request.result will be the exception of ar if present, true otherwise.
1897 // Be cautious not to leave result null which will wait() forever
1898 request.result = ar.exception != null ? ar.exception : true;
1899 notifyRequester(request);
1900 break;
1901 }
1902 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1903 request = (MainThreadRequest) msg.obj;
1904
1905 Phone phone = getPhoneFromRequest(request);
1906 if (phone == null || phone.getServiceStateTracker() == null) {
1907 request.result = new IllegalStateException("Phone or SST is null");
1908 notifyRequester(request);
1909 break;
1910 }
1911
1912 Pair<Integer, SignalStrengthUpdateRequest> pair =
1913 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1914 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1915 request);
1916 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1917 request.subId, pair.first /*callingUid*/,
1918 pair.second /*request*/, onCompleted);
1919 break;
1920 }
1921 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1922 ar = (AsyncResult) msg.obj;
1923 request = (MainThreadRequest) ar.userObj;
1924 request.result = ar.exception != null ? ar.exception : true;
1925 notifyRequester(request);
1926 break;
1927 }
Jordan Liu109698e2020-11-24 14:50:34 -08001928
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001929 case CMD_GET_SLICING_CONFIG: {
1930 request = (MainThreadRequest) msg.obj;
1931 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1932 request.phone.getSlicingConfig(onCompleted);
1933 break;
1934 }
1935 case EVENT_GET_SLICING_CONFIG_DONE: {
1936 ar = (AsyncResult) msg.obj;
1937 request = (MainThreadRequest) ar.userObj;
1938 ResultReceiver result = (ResultReceiver) request.argument;
1939
1940 SlicingConfig slicingConfig = null;
1941 Bundle bundle = new Bundle();
1942 int resultCode = 0;
1943 if (ar.exception != null) {
1944 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1945 + ar.exception);
1946 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1947 } else if (ar.result == null) {
1948 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1949 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1950 } else {
1951 // use the result as returned
1952 resultCode = TelephonyManager.SlicingException.SUCCESS;
1953 slicingConfig = (SlicingConfig) ar.result;
1954 }
1955
1956 if (slicingConfig == null) {
1957 slicingConfig = new SlicingConfig();
1958 }
1959 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1960 result.send(resultCode, bundle);
1961 notifyRequester(request);
1962 break;
1963 }
1964
Michele Berionne5e411512020-11-13 02:36:59 +00001965 case CMD_PREPARE_UNATTENDED_REBOOT:
1966 request = (MainThreadRequest) msg.obj;
1967 request.result =
1968 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1969 notifyRequester(request);
1970 break;
1971
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 default:
1973 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1974 break;
1975 }
1976 }
Jake Hambye994d462014-02-03 13:10:13 -08001977
Pengquan Menga1bb6272018-09-06 09:59:22 -07001978 private void notifyRequester(MainThreadRequest request) {
1979 synchronized (request) {
1980 request.notifyAll();
1981 }
1982 }
1983
Jake Hambye994d462014-02-03 13:10:13 -08001984 private void handleNullReturnEvent(Message msg, String command) {
1985 AsyncResult ar = (AsyncResult) msg.obj;
1986 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1987 if (ar.exception == null) {
1988 request.result = true;
1989 } else {
1990 request.result = false;
1991 if (ar.exception instanceof CommandException) {
1992 loge(command + ": CommandException: " + ar.exception);
1993 } else {
1994 loge(command + ": Unknown exception");
1995 }
1996 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001997 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
2001 /**
2002 * Posts the specified command to be executed on the main thread,
2003 * waits for the request to complete, and returns the result.
2004 * @see #sendRequestAsync
2005 */
2006 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2008 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002009 }
2010
2011 /**
2012 * Posts the specified command to be executed on the main thread,
2013 * waits for the request to complete, and returns the result.
2014 * @see #sendRequestAsync
2015 */
2016 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2017 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002018 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002019 }
2020
2021 /**
2022 * Posts the specified command to be executed on the main thread,
2023 * waits for the request to complete, and returns the result.
2024 * @see #sendRequestAsync
2025 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002026 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002027 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2028 }
2029
2030 /**
2031 * Posts the specified command to be executed on the main thread,
2032 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2033 * if not timeout or null otherwise.
2034 * @see #sendRequestAsync
2035 */
2036 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2037 long timeoutInMs) {
2038 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002039 }
2040
2041 /**
2042 * Posts the specified command to be executed on the main thread,
2043 * waits for the request to complete, and returns the result.
2044 * @see #sendRequestAsync
2045 */
Nathan Harold92bed182018-10-12 18:16:49 -07002046 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002047 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002048 }
2049
2050 /**
2051 * Posts the specified command to be executed on the main thread,
2052 * waits for the request to complete, and returns the result.
2053 * @see #sendRequestAsync
2054 */
2055 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002056 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2057 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002058 }
2059
2060 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002061 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2062 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2063 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002064 * @see #sendRequestAsync
2065 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002066 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2067 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2069 throw new RuntimeException("This method will deadlock if called from the main thread.");
2070 }
2071
Nathan Harold92bed182018-10-12 18:16:49 -07002072 MainThreadRequest request = null;
2073 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2074 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2075 } else if (phone != null) {
2076 request = new MainThreadRequest(argument, phone, workSource);
2077 } else {
2078 request = new MainThreadRequest(argument, subId, workSource);
2079 }
2080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 Message msg = mMainThreadHandler.obtainMessage(command, request);
2082 msg.sendToTarget();
2083
Rambo Wang0f050d82021-02-12 11:43:36 -08002084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002086 if (timeoutInMs >= 0) {
2087 // Wait for at least timeoutInMs before returning null request result
2088 long now = SystemClock.elapsedRealtime();
2089 long deadline = now + timeoutInMs;
2090 while (request == null && now < deadline) {
2091 try {
2092 request.wait(deadline - now);
2093 } catch (InterruptedException e) {
2094 // Do nothing, go back and check if request is completed or timeout
2095 } finally {
2096 now = SystemClock.elapsedRealtime();
2097 }
2098 }
2099 } else {
2100 // Wait for the request to complete
2101 while (request.result == null) {
2102 try {
2103 request.wait();
2104 } catch (InterruptedException e) {
2105 // Do nothing, go back and wait until the request is complete
2106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108 }
2109 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002110 if (request.result == null) {
2111 Log.wtf(LOG_TAG,
2112 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 return request.result;
2115 }
2116
2117 /**
2118 * Asynchronous ("fire and forget") version of sendRequest():
2119 * Posts the specified command to be executed on the main thread, and
2120 * returns immediately.
2121 * @see #sendRequest
2122 */
2123 private void sendRequestAsync(int command) {
2124 mMainThreadHandler.sendEmptyMessage(command);
2125 }
2126
2127 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002128 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002129 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002130 */
2131 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 sendRequestAsync(command, argument, null, null);
2133 }
2134
2135 /**
2136 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2137 * @see {@link #sendRequest(int,Object)}
2138 */
2139 private void sendRequestAsync(
2140 int command, Object argument, Phone phone, WorkSource workSource) {
2141 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002142 Message msg = mMainThreadHandler.obtainMessage(command, request);
2143 msg.sendToTarget();
2144 }
2145
2146 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 * Initialize the singleton PhoneInterfaceManager instance.
2148 * This is only done once, at startup, from PhoneApp.onCreate().
2149 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002150 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 synchronized (PhoneInterfaceManager.class) {
2152 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002153 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 } else {
2155 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2156 }
2157 return sInstance;
2158 }
2159 }
2160
2161 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002162 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002165 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002166 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2168 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002169 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002170 mTelephonySharedPreferences =
2171 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002172 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002173 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002174 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002175 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 publish();
2178 }
2179
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002180 private Phone getDefaultPhone() {
2181 Phone thePhone = getPhone(getDefaultSubscription());
2182 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 private void publish() {
2186 if (DBG) log("publish: " + this);
2187
Peter Wangc035ce42020-01-08 21:00:22 -08002188 TelephonyFrameworkInitializer
2189 .getTelephonyServiceManager()
2190 .getTelephonyServiceRegisterer()
2191 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Stuart Scott584921c2015-01-15 17:10:34 -08002194 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002195 if (request.phone != null) {
2196 return request.phone;
2197 } else {
2198 return getPhoneFromSubId(request.subId);
2199 }
2200 }
2201
2202 private Phone getPhoneFromSubId(int subId) {
2203 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2204 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002205 }
2206
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002207 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2208 Phone phone = getPhoneFromRequest(request);
2209 return phone == null ? null :
2210 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2211 }
2212
Wink Saville36469e72014-06-11 15:17:00 -07002213 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002214 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002215 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217
Kai Shif70f46f2021-03-03 13:59:46 -08002218 private void sendEraseModemConfig(@NonNull Phone phone) {
2219 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2220 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2221 }
2222
2223 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2224 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2225 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002226 }
2227
Peter Wang44b186e2020-01-13 23:33:09 -08002228 private boolean isImsAvailableOnDevice() {
2229 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2230 if (pm == null) {
2231 // For some reason package manger is not available.. This will fail internally anyway,
2232 // so do not throw error and allow.
2233 return true;
2234 }
2235 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2236 }
2237
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002239 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002240 }
2241
Wink Savilleb564aae2014-10-23 10:18:09 -07002242 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 if (DBG) log("dial: " + number);
2244 // No permission check needed here: This is just a wrapper around the
2245 // ACTION_DIAL intent, which is available to any app since it puts up
2246 // the UI before it does anything.
2247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 String url = createTelUrl(number);
2251 if (url == null) {
2252 return;
2253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 // PENDING: should we just silently fail if phone is offhook or ringing?
2256 PhoneConstants.State state = mCM.getState(subId);
2257 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2258 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2260 mApp.startActivity(intent);
2261 }
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265 }
2266
2267 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002268 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 if (DBG) log("call: " + number);
2273
2274 // This is just a wrapper around the ACTION_CALL intent, but we still
2275 // need to do a permission check since we're calling startActivity()
2276 // from the context of the phone app.
2277 enforceCallPermission();
2278
Jordan Liu1617b712019-07-10 15:06:26 -07002279 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 != AppOpsManager.MODE_ALLOWED) {
2281 return;
2282 }
2283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 final long identity = Binder.clearCallingIdentity();
2285 try {
2286 String url = createTelUrl(number);
2287 if (url == null) {
2288 return;
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291 boolean isValid = false;
2292 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2293 if (slist != null) {
2294 for (SubscriptionInfo subInfoRecord : slist) {
2295 if (subInfoRecord.getSubscriptionId() == subId) {
2296 isValid = true;
2297 break;
2298 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002299 }
Wink Saville08874612014-08-31 19:19:58 -07002300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 if (!isValid) {
2302 return;
2303 }
Wink Saville08874612014-08-31 19:19:58 -07002304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2306 intent.putExtra(SUBSCRIPTION_KEY, subId);
2307 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2308 mApp.startActivity(intent);
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002316 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2317 }
2318
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002320 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2322 }
2323
Wink Savilleb564aae2014-10-23 10:18:09 -07002324 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002329 Phone phone = getPhone(subId);
2330 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331 checkSimPin.start();
2332 return checkSimPin.unlockSim(null, pin);
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002343 Phone phone = getPhone(subId);
2344 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 checkSimPuk.start();
2346 return checkSimPuk.unlockSim(puk, pin);
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351
2352 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002353 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 * a synchronous one.
2355 */
2356 private static class UnlockSim extends Thread {
2357
2358 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002359 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360
2361 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002362 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2363 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 // For replies from SimCard interface
2366 private Handler mHandler;
2367
2368 // For async handler to identify request type
2369 private static final int SUPPLY_PIN_COMPLETE = 100;
2370
Michele Berionne5e411512020-11-13 02:36:59 +00002371 UnlockSim(int phoneId, IccCard simCard) {
2372 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 mSimCard = simCard;
2374 }
2375
2376 @Override
2377 public void run() {
2378 Looper.prepare();
2379 synchronized (UnlockSim.this) {
2380 mHandler = new Handler() {
2381 @Override
2382 public void handleMessage(Message msg) {
2383 AsyncResult ar = (AsyncResult) msg.obj;
2384 switch (msg.what) {
2385 case SUPPLY_PIN_COMPLETE:
2386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002388 mRetryCount = msg.arg1;
2389 if (ar.exception != null) {
2390 if (ar.exception instanceof CommandException &&
2391 ((CommandException)(ar.exception)).getCommandError()
2392 == CommandException.Error.PASSWORD_INCORRECT) {
2393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002394 } //When UiccCardApp dispose,handle message and return exception
2395 else if (ar.exception instanceof CommandException &&
2396 ((CommandException) (ar.exception)).getCommandError()
2397 == CommandException.Error.ABORTED) {
2398 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002399 } else {
2400 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2401 }
2402 } else {
2403 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 mDone = true;
2406 UnlockSim.this.notifyAll();
2407 }
2408 break;
2409 }
2410 }
2411 };
2412 UnlockSim.this.notifyAll();
2413 }
2414 Looper.loop();
2415 }
2416
2417 /*
2418 * Use PIN or PUK to unlock SIM card
2419 *
2420 * If PUK is null, unlock SIM card with PIN
2421 *
2422 * If PUK is not null, unlock SIM card with PUK and set PIN code
2423 */
Wink Saville9de0f752013-10-22 19:04:03 -07002424 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425
2426 while (mHandler == null) {
2427 try {
2428 wait();
2429 } catch (InterruptedException e) {
2430 Thread.currentThread().interrupt();
2431 }
2432 }
2433 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2434
2435 if (puk == null) {
2436 mSimCard.supplyPin(pin, callback);
2437 } else {
2438 mSimCard.supplyPuk(puk, pin, callback);
2439 }
2440
2441 while (!mDone) {
2442 try {
2443 Log.d(LOG_TAG, "wait for done");
2444 wait();
2445 } catch (InterruptedException e) {
2446 // Restore the interrupted status
2447 Thread.currentThread().interrupt();
2448 }
2449 }
2450 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002451 int[] resultArray = new int[2];
2452 resultArray[0] = mResult;
2453 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002454
2455 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2456 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2457 }
2458
Wink Saville9de0f752013-10-22 19:04:03 -07002459 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461 }
2462
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002463 /**
2464 * This method has been removed due to privacy and stability concerns.
2465 */
2466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002468 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2469 return;
Wink Saville36469e72014-06-11 15:17:00 -07002470 }
2471
Nathan Harold1f889d82020-06-04 17:05:26 -07002472 @Override
2473 public void updateServiceLocationWithPackageName(String callingPackage) {
2474 mApp.getSystemService(AppOpsManager.class)
2475 .checkPackage(Binder.getCallingUid(), callingPackage);
2476
Nathan Haroldf096d982020-11-18 17:18:06 -08002477 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002478 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2479 // Callers targeting S have no business invoking this method.
2480 return;
2481 }
2482
2483 LocationAccessPolicy.LocationPermissionResult locationResult =
2484 LocationAccessPolicy.checkLocationPermission(mApp,
2485 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2486 .setCallingPackage(callingPackage)
2487 .setCallingFeatureId(null)
2488 .setCallingPid(Binder.getCallingPid())
2489 .setCallingUid(Binder.getCallingUid())
2490 .setMethod("updateServiceLocation")
2491 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2493 .build());
2494 // Apps that lack location permission have no business calling this method;
2495 // however, because no permission was declared in the public API, denials must
2496 // all be "soft".
2497 switch (locationResult) {
2498 case DENIED_HARD: /* fall through */
2499 case DENIED_SOFT:
2500 return;
2501 }
2502
2503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 final long identity = Binder.clearCallingIdentity();
2505 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002506 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002508 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 }
2514
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
2517 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002518 return isRadioOnWithFeature(callingPackage, null);
2519 }
2520
2521
2522 @Override
2523 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2524 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
2526 }
2527
2528 @Deprecated
2529 @Override
2530 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2531 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002535 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2536 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return false;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 return isRadioOnForSubscriber(subId);
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002548 }
2549
2550 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 final Phone phone = getPhone(subId);
2554 if (phone != null) {
2555 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2556 } else {
2557 return false;
2558 }
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 }
2563
2564 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002565 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
Wink Saville36469e72014-06-11 15:17:00 -07002567
Wink Savilleb564aae2014-10-23 10:18:09 -07002568 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 }
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
2582 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002583 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Wink Savilleb564aae2014-10-23 10:18:09 -07002586 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 final Phone phone = getPhone(subId);
2592 if (phone == null) {
2593 return false;
2594 }
2595 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2596 toggleRadioOnOffForSubscriber(subId);
2597 }
2598 return true;
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
Wink Saville36469e72014-06-11 15:17:00 -07002603
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002604 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002605 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002606 /*
2607 * If any of the Radios are available, it will need to be
2608 * shutdown. So return true if any Radio is available.
2609 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2613 Phone phone = PhoneFactory.getPhone(i);
2614 if (phone != null && phone.isRadioAvailable()) return true;
2615 }
2616 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2617 return false;
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002620 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002621 }
2622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 enforceModifyPermission();
2626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2630 logv("Shutting down Phone " + i);
2631 shutdownRadioUsingPhoneId(i);
2632 }
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002635 }
2636 }
2637
2638 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002639 Phone phone = PhoneFactory.getPhone(phoneId);
2640 if (phone != null && phone.isRadioAvailable()) {
2641 phone.shutdownRadio();
2642 }
2643 }
2644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2651 if (defaultPhone != null) {
2652 defaultPhone.setRadioPower(turnOn);
2653 return true;
2654 } else {
2655 loge("There's no default phone.");
2656 return false;
2657 }
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002660 }
Wink Saville36469e72014-06-11 15:17:00 -07002661 }
2662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 phone.setRadioPower(turnOn);
2671 return true;
2672 } else {
2673 return false;
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Wink Saville36469e72014-06-11 15:17:00 -07002680 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 public boolean enableDataConnectivity() {
2683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 int subId = mSubscriptionController.getDefaultDataSubId();
2688 final Phone phone = getPhone(subId);
2689 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002690 phone.getDataEnabledSettings().setDataEnabled(
2691 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 return true;
2693 } else {
2694 return false;
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Wink Saville36469e72014-06-11 15:17:00 -07002701 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 public boolean disableDataConnectivity() {
2704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 int subId = mSubscriptionController.getDefaultDataSubId();
2709 final Phone phone = getPhone(subId);
2710 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002711 phone.getDataEnabledSettings().setDataEnabled(
2712 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 return true;
2714 } else {
2715 return false;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002723 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 final Phone phone = getPhone(subId);
2727 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002728 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } else {
2730 return false;
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
2737 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002738 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
pkanwarae03a6b2016-11-06 20:37:09 -08002741 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 enforceCallPermission();
2743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2747 return;
2748 }
2749 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2750 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
2753 }
pkanwar32d516d2016-10-14 19:37:38 -07002754 };
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2762 return false;
2763 }
2764 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002770 /**
2771 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2772 * tag on getCallState Binder call.
2773 */
2774 @Deprecated
2775 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002777 if (CompatChanges.isChangeEnabled(
2778 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2779 Binder.getCallingUid())) {
2780 // Do not allow this API to be called on API version 31+, it should only be
2781 // called on old apps using this Binder call directly.
2782 throw new SecurityException("This method can only be used for applications "
2783 + "targeting API version 30 or less.");
2784 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 final long identity = Binder.clearCallingIdentity();
2786 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002787 Phone phone = getPhone(getDefaultSubscription());
2788 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2789 PhoneConstantConversions.convertCallState(phone.getState());
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
2793 }
2794
2795 @Override
2796 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2797 if (CompatChanges.isChangeEnabled(
2798 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2799 Binder.getCallingUid())) {
2800 // Check READ_PHONE_STATE for API version 31+
2801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2802 featureId, "getCallStateForSubscription")) {
2803 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2804 + "targeting API level 31+.");
2805 }
2806 }
2807 final long identity = Binder.clearCallingIdentity();
2808 try {
2809 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2811 PhoneConstantConversions.convertCallState(phone.getState());
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
2814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002818 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002819 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2820 }
2821
2822 @Override
2823 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 final long identity = Binder.clearCallingIdentity();
2825 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002826 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 if (phone != null) {
2828 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2829 } else {
2830 return PhoneConstantConversions.convertDataState(
2831 PhoneConstants.DataState.DISCONNECTED);
2832 }
2833 } finally {
2834 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002839 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002840 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2841 }
2842
2843 @Override
2844 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002847 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 if (phone != null) {
2849 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2850 } else {
2851 return TelephonyManager.DATA_ACTIVITY_NONE;
2852 }
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002855 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 }
2857
2858 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002859 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002860 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002861 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002862
2863 LocationAccessPolicy.LocationPermissionResult locationResult =
2864 LocationAccessPolicy.checkLocationPermission(mApp,
2865 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2866 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002867 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002868 .setCallingPid(Binder.getCallingPid())
2869 .setCallingUid(Binder.getCallingUid())
2870 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002871 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002872 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2873 .build());
2874 switch (locationResult) {
2875 case DENIED_HARD:
2876 throw new SecurityException("Not allowed to access cell location");
2877 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002878 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2879 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002886 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002887 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 } finally {
2889 Binder.restoreCallingIdentity(identity);
2890 }
Svetoslav64fad262015-04-14 14:35:21 -07002891 }
2892
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002894 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002895 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2896 // registered cell info, so return a NULL country instead.
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002899 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2900 // Get default phone in this case.
2901 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2902 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002903 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002905 if (phone == null) return "";
2906 ServiceStateTracker sst = phone.getServiceStateTracker();
2907 if (sst == null) return "";
2908 LocaleTracker lt = sst.getLocaleTracker();
2909 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002910 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002914 }
2915
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002916 /**
2917 * This method was removed due to potential issues caused by performing partial
2918 * updates of service state, and lack of a credible use case.
2919 *
2920 * This has the ability to break the telephony implementation by disabling notification of
2921 * changes in device connectivity. DO NOT USE THIS!
2922 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002923 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924 public void enableLocationUpdates() {
2925 mApp.enforceCallingOrSelfPermission(
2926 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002929 /**
2930 * This method was removed due to potential issues caused by performing partial
2931 * updates of service state, and lack of a credible use case.
2932 *
2933 * This has the ability to break the telephony implementation by disabling notification of
2934 * changes in device connectivity. DO NOT USE THIS!
2935 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 @Override
2937 public void disableLocationUpdates() {
2938 mApp.enforceCallingOrSelfPermission(
2939 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 }
2941
2942 @Override
2943 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002944 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2945 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002946 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002947 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2948 throw new SecurityException(
2949 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2950 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002951
Jordan Liu1617b712019-07-10 15:06:26 -07002952 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002953 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2954 return null;
2955 }
Svetoslav64fad262015-04-14 14:35:21 -07002956
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002957 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002958
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002959 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002960 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961
Nathan Haroldf180aac2018-06-01 18:43:55 -07002962 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2963 for (CellInfo ci : info) {
2964 if (ci instanceof CellInfoGsm) {
2965 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2966 } else if (ci instanceof CellInfoWcdma) {
2967 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002970 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002973 private List<CellInfo> getCachedCellInfo() {
2974 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2975 for (Phone phone : PhoneFactory.getPhones()) {
2976 List<CellInfo> info = phone.getAllCellInfo();
2977 if (info != null) cellInfos.addAll(info);
2978 }
2979 return cellInfos;
2980 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002981
2982 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002983 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002985 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002986
2987 LocationAccessPolicy.LocationPermissionResult locationResult =
2988 LocationAccessPolicy.checkLocationPermission(mApp,
2989 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2990 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002991 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002992 .setCallingPid(Binder.getCallingPid())
2993 .setCallingUid(Binder.getCallingUid())
2994 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002995 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002996 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2997 .build());
2998 switch (locationResult) {
2999 case DENIED_HARD:
3000 throw new SecurityException("Not allowed to access cell info");
3001 case DENIED_SOFT:
3002 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Nathan Haroldf096d982020-11-18 17:18:06 -08003005 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003006 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3007 return getCachedCellInfo();
3008 }
3009
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003010 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003011 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3015 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003016 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003017 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 if (info != null) cellInfos.addAll(info);
3019 }
3020 return cellInfos;
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 }
3024 }
3025
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003026 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003027 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3028 String callingFeatureId) {
3029 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3030 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003031 }
3032
3033 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003034 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3035 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003036 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003038 }
3039
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3041 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003043 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003044
3045 LocationAccessPolicy.LocationPermissionResult locationResult =
3046 LocationAccessPolicy.checkLocationPermission(mApp,
3047 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3048 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003049 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003050 .setCallingPid(Binder.getCallingPid())
3051 .setCallingUid(Binder.getCallingUid())
3052 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003053 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3054 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003055 .build());
3056 switch (locationResult) {
3057 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003058 if (TelephonyPermissions
3059 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003060 // Safetynet logging for b/154934934
3061 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3062 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003063 throw new SecurityException("Not allowed to access cell info");
3064 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003065 if (TelephonyPermissions
3066 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003067 // Safetynet logging for b/154934934
3068 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3069 }
Nathan Harold5320c422019-05-09 10:26:08 -07003070 try {
3071 cb.onCellInfo(new ArrayList<CellInfo>());
3072 } catch (RemoteException re) {
3073 // Drop without consequences
3074 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003075 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003076 }
3077
Nathan Harolda939a962019-05-09 10:13:47 -07003078
3079 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003080 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3081
3082 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3083 }
3084
3085 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003086 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003087 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003088 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003092 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003096 }
3097
Shishir Agrawala9f32182016-04-12 12:00:16 -07003098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003099 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 Phone phone = PhoneFactory.getPhone(slotIndex);
3101 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 return null;
3103 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003105 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003106 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 return null;
3108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 return phone.getImei();
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003116 }
3117
3118 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003119 public String getTypeAllocationCodeForSlot(int slotIndex) {
3120 Phone phone = PhoneFactory.getPhone(slotIndex);
3121 String tac = null;
3122 if (phone != null) {
3123 String imei = phone.getImei();
3124 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3125 }
3126 return tac;
3127 }
3128
3129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003130 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 Phone phone = PhoneFactory.getPhone(slotIndex);
3132 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003133 return null;
3134 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003135
Jeff Davidson913390f2018-02-23 17:11:49 -08003136 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003137 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003138 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003139 return null;
3140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141
3142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 return phone.getMeid();
3145 } finally {
3146 Binder.restoreCallingIdentity(identity);
3147 }
Jack Yu2af8d712017-03-15 17:14:14 -07003148 }
3149
3150 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003151 public String getManufacturerCodeForSlot(int slotIndex) {
3152 Phone phone = PhoneFactory.getPhone(slotIndex);
3153 String manufacturerCode = null;
3154 if (phone != null) {
3155 String meid = phone.getMeid();
3156 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3157 }
3158 return manufacturerCode;
3159 }
3160
3161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003162 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3163 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003164 Phone phone = PhoneFactory.getPhone(slotIndex);
3165 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003166 return null;
3167 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003168 int subId = phone.getSubId();
3169 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003170 mApp, subId, callingPackage, callingFeatureId,
3171 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003172 return null;
3173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174
3175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 return phone.getDeviceSvn();
3178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003181 }
3182
fionaxu43304da2017-11-27 22:51:16 -08003183 @Override
3184 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
3188 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
fionaxu43304da2017-11-27 22:51:16 -08003192 }
3193
3194 @Override
3195 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 final Phone phone = getPhone(subId);
3199 return phone == null ? null : phone.getCarrierName();
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
3202 }
fionaxu43304da2017-11-27 22:51:16 -08003203 }
3204
calvinpanffe225e2018-11-01 19:43:06 +08003205 @Override
chen xu0026ca62019-03-06 15:28:50 -08003206 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 final Phone phone = getPhone(subId);
3210 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003211 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
3215 }
3216
3217 @Override
chen xu0026ca62019-03-06 15:28:50 -08003218 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003222 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003223 } finally {
3224 Binder.restoreCallingIdentity(identity);
3225 }
3226 }
3227
chen xu651eec72018-11-11 19:03:44 -08003228 @Override
chen xu864e11c2018-12-06 22:10:03 -08003229 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3230 if (!isSubscriptionMccMnc) {
3231 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3232 }
chen xu651eec72018-11-11 19:03:44 -08003233 final Phone phone = PhoneFactory.getPhone(slotIndex);
3234 if (phone == null) {
3235 return TelephonyManager.UNKNOWN_CARRIER_ID;
3236 }
3237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 //
3246 // Internal helper methods.
3247 //
3248
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003249 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3251 *
3252 * @throws SecurityException if the caller does not have the required permission
3253 */
3254 private void enforceModifyPermission() {
3255 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3256 }
3257
Shuo Qiancd19c462020-01-16 20:51:11 -08003258 /**
3259 * Make sure the caller is system.
3260 *
3261 * @throws SecurityException if the caller is not system.
3262 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003263 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003264 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3265 throw new SecurityException("Caller must be system");
3266 }
3267 }
3268
Shuo Qian3b6ee772019-11-13 17:43:31 -08003269 private void enforceActiveEmergencySessionPermission() {
3270 mApp.enforceCallingOrSelfPermission(
3271 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3272 }
3273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 /**
3275 * Make sure the caller has the CALL_PHONE permission.
3276 *
3277 * @throws SecurityException if the caller does not have the required permission
3278 */
3279 private void enforceCallPermission() {
3280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3281 }
3282
paulhu5a773602019-08-23 19:17:33 +08003283 private void enforceSettingsPermission() {
3284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003285 }
3286
Michele Berionne5e411512020-11-13 02:36:59 +00003287 private void enforceRebootPermission() {
3288 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3289 }
3290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 private String createTelUrl(String number) {
3292 if (TextUtils.isEmpty(number)) {
3293 return null;
3294 }
3295
Jake Hambye994d462014-02-03 13:10:13 -08003296 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
Ihab Awadf9e92732013-12-05 18:02:52 -08003299 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3301 }
3302
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003303 private static void logv(String msg) {
3304 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3305 }
3306
Ihab Awadf9e92732013-12-05 18:02:52 -08003307 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003308 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3309 }
3310
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003311 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003313 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003314 }
3315
Sanket Padawe356d7632015-06-22 14:03:32 -07003316 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003317 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 final Phone phone = PhoneFactory.getPhone(slotIndex);
3321 if (phone == null) {
3322 return PhoneConstants.PHONE_TYPE_NONE;
3323 } else {
3324 return phone.getPhoneType();
3325 }
3326 } finally {
3327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003329 }
3330
3331 /**
3332 * Returns the CDMA ERI icon index to display
3333 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003334 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003335 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3336 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3337 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003338 }
3339
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003341 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3342 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003344 mApp, subId, callingPackage, callingFeatureId,
3345 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003346 return -1;
3347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 final Phone phone = getPhone(subId);
3352 if (phone != null) {
3353 return phone.getCdmaEriIconIndex();
3354 } else {
3355 return -1;
3356 }
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003360 }
3361
3362 /**
3363 * Returns the CDMA ERI icon mode,
3364 * 0 - ON
3365 * 1 - FLASHING
3366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003368 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3369 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3370 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003371 }
3372
Sanket Padawe356d7632015-06-22 14:03:32 -07003373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3375 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003377 mApp, subId, callingPackage, callingFeatureId,
3378 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003379 return -1;
3380 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 final Phone phone = getPhone(subId);
3385 if (phone != null) {
3386 return phone.getCdmaEriIconMode();
3387 } else {
3388 return -1;
3389 }
3390 } finally {
3391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 }
3394
3395 /**
3396 * Returns the CDMA ERI text,
3397 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003398 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003399 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3400 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3401 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003402 }
3403
Sanket Padawe356d7632015-06-22 14:03:32 -07003404 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003405 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3406 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003408 mApp, subId, callingPackage, callingFeatureId,
3409 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003410 return null;
3411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003412
3413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 final Phone phone = getPhone(subId);
3416 if (phone != null) {
3417 return phone.getCdmaEriText();
3418 } else {
3419 return null;
3420 }
3421 } finally {
3422 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 }
3425
3426 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003427 * Returns the CDMA MDN.
3428 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003429 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003430 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3432 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003437 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438 return phone.getLine1Number();
3439 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441 return null;
3442 }
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003445 }
3446 }
3447
3448 /**
3449 * Returns the CDMA MIN.
3450 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003451 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003452 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3454 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003455
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 final Phone phone = getPhone(subId);
3459 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3460 return phone.getCdmaMin();
3461 } else {
3462 return null;
3463 }
3464 } finally {
3465 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003466 }
3467 }
3468
Hall Liud892bec2018-11-30 14:51:45 -08003469 @Override
3470 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3471 INumberVerificationCallback callback, String callingPackage) {
3472 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3473 != PERMISSION_GRANTED) {
3474 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3475 }
3476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3477
3478 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3479 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003480 throw new SecurityException("Calling package must be configured in the device config: "
3481 + "calling package: " + callingPackage
3482 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003483 }
3484
3485 if (range == null) {
3486 throw new NullPointerException("Range must be non-null");
3487 }
3488
3489 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003490 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003491
3492 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3493 }
3494
Junda Liuca05d5d2014-08-14 22:36:34 -07003495 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003496 * Returns true if CDMA provisioning needs to run.
3497 */
3498 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499 final long identity = Binder.clearCallingIdentity();
3500 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003501 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
3506
3507 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003508 * Sets the voice mail number of a given subId.
3509 */
3510 @Override
3511 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3513 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3518 new Pair<String, String>(alphaTag, number), new Integer(subId));
3519 return success;
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003523 }
3524
Ta-wei Yen87c49842016-05-13 21:19:52 -07003525 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003526 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3527 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003528 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3529 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003530 if (!TextUtils.equals(callingPackage, systemDialer)) {
3531 throw new SecurityException("caller must be system dialer");
3532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3537 if (phoneAccountHandle == null) {
3538 return null;
3539 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003543 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003544 }
3545
3546 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3548 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 mApp, subId, callingPackage, callingFeatureId,
3552 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003553 return null;
3554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003556 final long identity = Binder.clearCallingIdentity();
3557 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003562 }
3563
3564 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003565 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3566 VisualVoicemailSmsFilterSettings settings) {
3567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568
3569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003576 }
3577
3578 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003579 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003589 }
3590
3591 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003592 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3593 String callingPackage, int subId) {
3594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003603 }
3604
3605 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003606 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003616 }
3617
3618 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003619 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3620 String callingAttributionTag, int subId, String number, int port, String text,
3621 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003623 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003624 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003625 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003626 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3627 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003628 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003629
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003630 /**
fionaxu0152e512016-11-14 13:36:14 -08003631 * Sets the voice activation state of a given subId.
3632 */
3633 @Override
3634 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3636 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637
3638 final long identity = Binder.clearCallingIdentity();
3639 try {
3640 final Phone phone = getPhone(subId);
3641 if (phone != null) {
3642 phone.setVoiceActivationState(activationState);
3643 } else {
3644 loge("setVoiceActivationState fails with invalid subId: " + subId);
3645 }
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003648 }
3649 }
3650
3651 /**
3652 * Sets the data activation state of a given subId.
3653 */
3654 @Override
3655 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3657 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 if (phone != null) {
3663 phone.setDataActivationState(activationState);
3664 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003665 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 }
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003669 }
3670 }
3671
3672 /**
3673 * Returns the voice activation state of a given subId.
3674 */
3675 @Override
3676 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678
fionaxu0152e512016-11-14 13:36:14 -08003679 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 if (phone != null) {
3683 return phone.getVoiceActivationState();
3684 } else {
3685 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3686 }
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003689 }
3690 }
3691
3692 /**
3693 * Returns the data activation state of a given subId.
3694 */
3695 @Override
3696 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
fionaxu0152e512016-11-14 13:36:14 -08003699 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 if (phone != null) {
3703 return phone.getDataActivationState();
3704 } else {
3705 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3706 }
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003709 }
3710 }
3711
3712 /**
Wink Saville36469e72014-06-11 15:17:00 -07003713 * Returns the unread count of voicemails for a subId
3714 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003715 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003716 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3717 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003718 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003719 mApp, subId, callingPackage, callingFeatureId,
3720 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003721 return 0;
3722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 final Phone phone = getPhone(subId);
3726 if (phone != null) {
3727 return phone.getVoiceMessageCount();
3728 } else {
3729 return 0;
3730 }
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003734 }
3735
3736 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003737 * returns true, if the device is in a state where both voice and data
3738 * are supported simultaneously. This can change based on location or network condition.
3739 */
3740 @Override
3741 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 final Phone phone = getPhone(subId);
3745 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003749 }
3750
3751 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003752 * Send the dialer code if called from the current default dialer or the caller has
3753 * carrier privilege.
3754 * @param inputCode The dialer code to send
3755 */
3756 @Override
3757 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003759 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003760 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3761 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003762 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003763 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766
3767 final long identity = Binder.clearCallingIdentity();
3768 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003769 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
fionaxu235cc5e2017-03-06 22:25:57 -08003773 }
3774
Pengquan Menga1bb6272018-09-06 09:59:22 -07003775 @Override
3776 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003777 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003778 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003779 mApp, subId, "getNetworkSelectionMode");
3780 final long identity = Binder.clearCallingIdentity();
3781 try {
3782 if (!isActiveSubscription(subId)) {
3783 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3784 }
3785 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003788 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003789 }
3790
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003792 public boolean isInEmergencySmsMode() {
3793 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 for (Phone phone : PhoneFactory.getPhones()) {
3797 if (phone.isInEmergencySmsMode()) {
3798 return true;
3799 }
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
3804 return false;
3805 }
3806
shilu366312e2019-12-17 09:28:10 -08003807 /**
3808 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3809 * @param subId The subscription to use to check the configuration.
3810 * @param c The callback that will be used to send the result.
3811 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003812 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003813 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3814 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003816 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003817
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003818 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3819 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3820 "IMS not available on device.");
3821 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 final long token = Binder.clearCallingIdentity();
3823 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003827 } catch (ImsException e) {
3828 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 } finally {
3830 Binder.restoreCallingIdentity(token);
3831 }
3832 }
3833
shilu366312e2019-12-17 09:28:10 -08003834 /**
3835 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3836 * @param subId The subscription to use to check the configuration.
3837 * @param c The callback that will be used to send the result.
3838 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003840 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003841 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003842 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003843 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3844 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3845 }
Meng Wangafbc5852019-09-19 17:37:13 -07003846 final long token = Binder.clearCallingIdentity();
3847 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003848 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003849 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3850 .removeRegistrationCallbackForSubscription(c, subId);
3851 } catch (ImsException e) {
3852 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3853 + "is inactive, ignoring unregister.");
3854 // If the subscription is no longer active, just return, since the callback
3855 // will already have been removed internally.
3856 } finally {
3857 Binder.restoreCallingIdentity(token);
3858 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 }
3860
Brad Ebingera34a6c22019-10-22 17:36:18 -07003861 /**
3862 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3863 */
3864 @Override
3865 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3866 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3867 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3868 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3869 "IMS not available on device.");
3870 }
3871 final long token = Binder.clearCallingIdentity();
3872 try {
3873 Phone phone = getPhone(subId);
3874 if (phone == null) {
3875 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3876 + subId + "'");
3877 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3878 }
3879 phone.getImsRegistrationState(regState -> {
3880 try {
3881 consumer.accept((regState == null)
3882 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3883 } catch (RemoteException e) {
3884 // Ignore if the remote process is no longer available to call back.
3885 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3886 }
3887 });
3888 } finally {
3889 Binder.restoreCallingIdentity(token);
3890 }
3891 }
3892
3893 /**
3894 * Get the transport type for the IMS service registration state.
3895 */
3896 @Override
3897 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003898 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003899 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003900 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3901 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3902 "IMS not available on device.");
3903 }
3904 final long token = Binder.clearCallingIdentity();
3905 try {
3906 Phone phone = getPhone(subId);
3907 if (phone == null) {
3908 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3909 + subId + "'");
3910 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3911 }
3912 phone.getImsRegistrationTech(regTech -> {
3913 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3914 int regTechConverted = (regTech == null)
3915 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3916 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3917 regTechConverted);
3918 try {
3919 consumer.accept(regTechConverted);
3920 } catch (RemoteException e) {
3921 // Ignore if the remote process is no longer available to call back.
3922 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3923 }
3924 });
3925 } finally {
3926 Binder.restoreCallingIdentity(token);
3927 }
3928 }
3929
shilu366312e2019-12-17 09:28:10 -08003930 /**
3931 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3932 * @param subId The subscription to use to check the configuration.
3933 * @param c The callback that will be used to send the result.
3934 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003936 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3937 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003938 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003939 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003940 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3941 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3942 "IMS not available on device.");
3943 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3945 final long token = Binder.clearCallingIdentity();
3946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003949 } catch (ImsException e) {
3950 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003951 } finally {
3952 Binder.restoreCallingIdentity(token);
3953 }
3954 }
3955
shilu366312e2019-12-17 09:28:10 -08003956 /**
3957 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3958 * @param subId The subscription to use to check the configuration.
3959 * @param c The callback that will be used to send the result.
3960 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003962 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003963 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003964 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003965 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3966 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3967 }
Meng Wangafbc5852019-09-19 17:37:13 -07003968
3969 final long token = Binder.clearCallingIdentity();
3970 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003971 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003972 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003973 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003974 } catch (ImsException e) {
3975 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3976 + "is inactive, ignoring unregister.");
3977 // If the subscription is no longer active, just return, since the callback
3978 // will already have been removed internally.
3979 } finally {
3980 Binder.restoreCallingIdentity(token);
3981 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 }
3983
3984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003985 public boolean isCapable(int subId, int capability, int regTech) {
3986 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3988 final long token = Binder.clearCallingIdentity();
3989 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003990 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003992 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3994 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003996 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3997 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 } finally {
3999 Binder.restoreCallingIdentity(token);
4000 }
4001 }
4002
4003 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004004 public boolean isAvailable(int subId, int capability, int regTech) {
4005 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 final long token = Binder.clearCallingIdentity();
4007 try {
4008 Phone phone = getPhone(subId);
4009 if (phone == null) return false;
4010 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004011 } catch (com.android.ims.ImsException e) {
4012 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4013 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 } finally {
4015 Binder.restoreCallingIdentity(token);
4016 }
4017 }
4018
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004019 /**
4020 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4021 * subscription.
4022 * @param subId The subscription to use to check the configuration.
4023 * @param callback The callback that will be used to send the result.
4024 * @param capability The MmTelFeature capability that will be used to send the result.
4025 * @param transportType The transport type of the MmTelFeature capability.
4026 */
4027 @Override
4028 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4029 int transportType) {
4030 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4033 "IMS not available on device.");
4034 }
4035 final long token = Binder.clearCallingIdentity();
4036 try {
4037 int slotId = getSlotIndex(subId);
4038 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4039 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4040 + subId + "'");
4041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4042 }
4043 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4044 transportType, aBoolean -> {
4045 try {
4046 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4047 } catch (RemoteException e) {
4048 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4049 + "running. Ignore");
4050 }
4051 });
4052 } finally {
4053 Binder.restoreCallingIdentity(token);
4054 }
4055 }
4056
shilu366312e2019-12-17 09:28:10 -08004057 /**
4058 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4059 * @param subId The subscription to use to check the configuration.
4060 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 @Override
4062 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004064 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004065
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4067 final long token = Binder.clearCallingIdentity();
4068 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004069 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004071 } catch (ImsException e) {
4072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 } finally {
4074 Binder.restoreCallingIdentity(token);
4075 }
4076 }
4077
4078 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004079 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004081 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004087 } catch (ImsException e) {
4088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
4092 }
4093
shilu366312e2019-12-17 09:28:10 -08004094 /**
4095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4096 * @param subId The subscription to use to check the configuration.
4097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004099 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004101 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004105 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4106 } catch (ImsException e) {
4107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
4113 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004114 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004116 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (ImsException e) {
4122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
4126 }
4127
shilu366312e2019-12-17 09:28:10 -08004128 /**
4129 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4130 * @param subId The subscription to use to check the configuration.
4131 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 @Override
4133 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004134 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004135 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (ImsException e) {
4142 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
4146 }
4147
4148 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004149 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004151 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004155 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
4157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
shilu366312e2019-12-17 09:28:10 -08004163 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004164 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4165 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4166 * @param subId The subscription to use to check the configuration.
4167 */
4168 @Override
4169 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004170 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004171 mApp, subId, "isCrossSimCallingEnabledByUser");
4172 final long identity = Binder.clearCallingIdentity();
4173 try {
4174 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4175 return ImsManager.getInstance(mApp,
4176 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4177 } catch (ImsException e) {
4178 throw new ServiceSpecificException(e.getCode());
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
4184 /**
4185 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4186 * Requires MODIFY_PHONE_STATE permission.
4187 * @param subId The subscription to use to check the configuration.
4188 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4189 * false otherwise
4190 */
4191 @Override
4192 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4194 "setCrossSimCallingEnabled");
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4199 .setCrossSimCallingEnabled(isEnabled);
4200 } catch (ImsException e) {
4201 throw new ServiceSpecificException(e.getCode());
4202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
4205 }
4206
4207 /**
shilu366312e2019-12-17 09:28:10 -08004208 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4209 * @param subId The subscription to use to check the configuration.
4210 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004212
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004214 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004215 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 final long identity = Binder.clearCallingIdentity();
4217 try {
4218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004219 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 } catch (ImsException e) {
4222 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
4226 }
4227
4228 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004229 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004231 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004235 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
4244 @Override
4245 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4247 "setVoWiFiNonPersistent");
4248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004252 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
shilu366312e2019-12-17 09:28:10 -08004260 /**
4261 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4262 * @param subId The subscription to use to check the configuration.
4263 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 @Override
4265 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
4270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004271 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004273 } catch (ImsException e) {
4274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
4280 @Override
4281 public void setVoWiFiModeSetting(int subId, int mode) {
4282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4283 "setVoWiFiModeSetting");
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004287 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
4296 @Override
4297 public int getVoWiFiRoamingModeSetting(int subId) {
4298 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004302 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004304 } catch (ImsException e) {
4305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
4309 }
4310
4311 @Override
4312 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4314 "setVoWiFiRoamingModeSetting");
4315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004318 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
4325 }
4326
4327 @Override
4328 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4330 "setRttCapabilityEnabled");
4331 final long identity = Binder.clearCallingIdentity();
4332 try {
4333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004334 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
shilu366312e2019-12-17 09:28:10 -08004342 /**
4343 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4344 * @param subId The subscription to use to check the configuration.
4345 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 @Override
4347 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004348 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004349 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004353 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 } catch (ImsException e) {
4356 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004362 @Override
4363 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4364 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4365 final long identity = Binder.clearCallingIdentity();
4366 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004367 if (!isImsAvailableOnDevice()) {
4368 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4369 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004370 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004371 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004372 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004373 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 @Override
4382 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4383 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4384 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4386 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4387 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004388 try {
4389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004390 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004391 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004392 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004393 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4394 + "is inactive, ignoring unregister.");
4395 // If the subscription is no longer active, just return, since the callback will already
4396 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
allenwtsu99c623b2020-01-03 18:24:23 +08004402
4403 private void checkModifyPhoneStatePermission(int subId, String message) {
4404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4405 message);
4406 }
4407
4408 private boolean isImsProvisioningRequired(int subId, int capability,
4409 boolean isMmtelCapability) {
4410 Phone phone = getPhone(subId);
4411 if (phone == null) {
4412 loge("phone instance null for subid " + subId);
4413 return false;
4414 }
4415 if (isMmtelCapability) {
4416 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4417 return false;
4418 }
4419 } else {
4420 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4421 return false;
4422 }
4423 }
4424 return true;
4425 }
4426
4427 @Override
4428 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4429 boolean isProvisioned) {
4430 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4431
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4435 if (!isImsProvisioningRequired(subId, capability, false)) {
4436 return;
4437 }
4438
4439 // this capability requires provisioning, route to the correct API.
4440 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4441 switch (capability) {
4442 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4443 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4444 ims.setEabProvisioned(isProvisioned);
4445 break;
4446 default: {
4447 throw new IllegalArgumentException("Tried to set provisioning for "
4448 + "rcs capability '" + capability + "', which does not require "
4449 + "provisioning.");
4450 }
4451 }
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455
4456 }
4457
4458
4459 @Override
4460 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4461 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4465 if (!isImsProvisioningRequired(subId, capability, false)) {
4466 return true;
4467 }
4468
4469 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4470 switch (capability) {
4471 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4473 return ims.isEabProvisionedOnDevice();
4474
4475 default: {
4476 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4477 + "capability '" + capability + "', which does not require "
4478 + "provisioning.");
4479 }
4480 }
4481
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004487 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004488 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4489 boolean isProvisioned) {
4490 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004491 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4492 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4493 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004494 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4495 }
allenwtsu99c623b2020-01-03 18:24:23 +08004496 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004500 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004501 return;
4502 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004503 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4504 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4505 loge("setImsProvisioningStatusForCapability: called for technology that does "
4506 + "not support provisioning - " + tech);
4507 return;
4508 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004509
4510 // this capability requires provisioning, route to the correct API.
4511 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4512 switch (capability) {
4513 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4514 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4515 ims.setVolteProvisioned(isProvisioned);
4516 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4517 ims.setWfcProvisioned(isProvisioned);
4518 }
4519 break;
4520 }
4521 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4522 // There is currently no difference in VT provisioning type.
4523 ims.setVtProvisioned(isProvisioned);
4524 break;
4525 }
4526 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4527 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4528 // change the capability of the feature instead if needed.
4529 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4530 == isProvisioned) {
4531 // No change in provisioning.
4532 return;
4533 }
4534 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4535 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004536 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4539 + ", Exception" + e.getMessage());
4540 }
4541 break;
4542 }
4543 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004544 throw new IllegalArgumentException("Tried to set provisioning for "
4545 + "MmTel capability '" + capability + "', which does not require "
4546 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 }
4548 }
4549
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4557 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004558 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4559 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4560 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004561 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4562 }
4563 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004567 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 return true;
4569 }
4570
Brad Ebinger0d79c572021-04-17 15:20:49 -07004571 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4572 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4573 loge("getImsProvisioningStatusForCapability: called for technology that does "
4574 + "not support provisioning - " + tech);
4575 return true;
4576 }
4577
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004578 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4579 switch (capability) {
4580 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4581 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4582 return ims.isVolteProvisionedOnDevice();
4583 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4584 return ims.isWfcProvisionedOnDevice();
4585 }
4586 // This should never happen, since we are checking tech above to make sure it
4587 // is either LTE or IWLAN.
4588 throw new IllegalArgumentException("Invalid radio technology for voice "
4589 + "capability.");
4590 }
4591 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4592 // There is currently no difference in VT provisioning type.
4593 return ims.isVtProvisionedOnDevice();
4594 }
4595 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4596 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4597 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4598 }
4599 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004600 throw new IllegalArgumentException(
4601 "Tried to get provisioning for MmTel capability '" + capability
4602 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004603 }
4604 }
4605
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
4612 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4613 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4614 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4615 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4616 }
4617 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4618 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4619 return (provisionedBits & capability) > 0;
4620 }
4621
4622 @Override
4623 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4624 boolean isProvisioned) {
4625 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4626 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4627 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4628 }
4629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4630 "setProvisioningStatusForCapability");
4631 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4632 // If the current provisioning status for capability already matches isProvisioned,
4633 // do nothing.
4634 if (((provisionedBits & capability) > 0) == isProvisioned) {
4635 return;
4636 }
4637 if (isProvisioned) {
4638 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4639 } else {
4640 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4641 }
4642 }
4643
4644 /**
4645 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4646 * technology. The bitfield should mirror the bitfield defined by
4647 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4648 */
4649 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4650 String key = getMmTelProvisioningKey(subId, tech);
4651 // Default is no capabilities are provisioned.
4652 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4653 }
4654
4655 /**
4656 * Sets the MmTel capability provisioning bitfield (defined by
4657 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4658 * technology specified.
4659 *
4660 * Note: This is a synchronous command and should not be called on UI thread.
4661 */
4662 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4663 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4664 String key = getMmTelProvisioningKey(subId, tech);
4665 editor.putInt(key, newField);
4666 editor.commit();
4667 }
4668
4669 private static String getMmTelProvisioningKey(int subId, int tech) {
4670 // resulting key is provision_ims_mmtel_{subId}_{tech}
4671 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4672 }
4673
4674 /**
4675 * Query CarrierConfig to see if the specified capability requires provisioning for the
4676 * carrier associated with the subscription id.
4677 */
4678 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4679 int capability) {
4680 CarrierConfigManager configManager = new CarrierConfigManager(context);
4681 PersistableBundle c = configManager.getConfigForSubId(subId);
4682 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004683 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004684 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4685 false);
4686 boolean requireVoiceVtProvisioning = c.getBoolean(
4687 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4688
4689 // First check to make sure that the capability requires provisioning.
4690 switch (capability) {
4691 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4692 // intentional fallthrough
4693 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4694 if (requireVoiceVtProvisioning) {
4695 // Voice and Video requires provisioning
4696 return true;
4697 }
4698 break;
4699 }
4700 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4701 if (requireUtProvisioning) {
4702 // UT requires provisioning
4703 return true;
4704 }
4705 break;
4706 }
4707 }
4708 return false;
4709 }
4710
allenwtsu99c623b2020-01-03 18:24:23 +08004711 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4712 int capability) {
4713 CarrierConfigManager configManager = new CarrierConfigManager(context);
4714 PersistableBundle c = configManager.getConfigForSubId(subId);
4715
4716 boolean requireRcsProvisioning = c.getBoolean(
4717 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4718
4719 // First check to make sure that the capability requires provisioning.
4720 switch (capability) {
4721 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4722 // intentional fallthrough
4723 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4724 if (requireRcsProvisioning) {
4725 // OPTION or PRESENCE requires provisioning
4726 return true;
4727 }
4728 break;
4729 }
4730 }
4731 return false;
4732 }
4733
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004735 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4737 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4738 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004739 enforceReadPrivilegedPermission("getImsProvisioningInt");
4740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004743 int slotId = getSlotIndex(subId);
4744 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4745 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4746 + subId + "' for key:" + key);
4747 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4748 }
calvinpanb5a34062021-02-08 19:59:36 +08004749 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004750 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4752 + subId + "' for key:" + key);
4753 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
4757 }
4758
4759 @Override
4760 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4762 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4763 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 enforceReadPrivilegedPermission("getImsProvisioningString");
4765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004768 int slotId = getSlotIndex(subId);
4769 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4770 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4771 + subId + "' for key:" + key);
4772 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4773 }
calvinpanb5a34062021-02-08 19:59:36 +08004774 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004775 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4777 + subId + "' for key:" + key);
4778 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
4784 @Override
4785 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4787 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4788 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4790 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004794 int slotId = getSlotIndex(subId);
4795 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4796 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4797 + subId + "' for key:" + key);
4798 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4799 }
calvinpanb5a34062021-02-08 19:59:36 +08004800 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4801 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004803 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004805 } finally {
4806 Binder.restoreCallingIdentity(identity);
4807 }
4808 }
4809
4810 @Override
4811 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4813 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4814 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4816 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004820 int slotId = getSlotIndex(subId);
4821 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4822 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4823 + subId + "' for key:" + key);
4824 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4825 }
calvinpanb5a34062021-02-08 19:59:36 +08004826 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4827 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004829 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004830 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004831 } finally {
4832 Binder.restoreCallingIdentity(identity);
4833 }
4834 }
4835
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004836 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004837 int slotId = SubscriptionManager.getSlotIndex(subId);
4838 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004839 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4840 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004841 }
4842 return slotId;
4843 }
4844
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004845 private int getSlotIndex(int subId) {
4846 int slotId = SubscriptionManager.getSlotIndex(subId);
4847 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4848 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4849 }
4850 return slotId;
4851 }
4852
Wink Saville36469e72014-06-11 15:17:00 -07004853 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004854 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004855 */
4856 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004857 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4858 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004859 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004860 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004861 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004862 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004863 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004864 mApp, subId, callingPackage, callingFeatureId,
4865 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4867 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 final Phone phone = getPhone(subId);
4872 if (phone != null) {
4873 return phone.getServiceState().getDataNetworkType();
4874 } else {
4875 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4876 }
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 }
4881
4882 /**
4883 * Returns the data network type
4884 */
4885 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004886 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4887 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4888 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004889 }
4890
4891 /**
4892 * Returns the data network type for a subId
4893 */
4894 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004895 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4896 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004898 mApp, subId, callingPackage, callingFeatureId,
4899 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004900 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4901 }
4902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 final Phone phone = getPhone(subId);
4906 if (phone != null) {
4907 return phone.getServiceState().getDataNetworkType();
4908 } else {
4909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4910 }
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004914 }
4915
4916 /**
Wink Saville36469e72014-06-11 15:17:00 -07004917 * Returns the Voice network type for a subId
4918 */
4919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004920 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4921 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 mApp, subId, callingPackage, callingFeatureId,
4924 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004925 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4926 }
4927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 final Phone phone = getPhone(subId);
4931 if (phone != null) {
4932 return phone.getServiceState().getVoiceNetworkType();
4933 } else {
4934 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4935 }
4936 } finally {
4937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004939 }
4940
4941 /**
4942 * @return true if a ICC card is present
4943 */
4944 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004945 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004946 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4947 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004948 }
4949
4950 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004951 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004952 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004953 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004954 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 final long identity = Binder.clearCallingIdentity();
4956 try {
4957 final Phone phone = PhoneFactory.getPhone(slotIndex);
4958 if (phone != null) {
4959 return phone.getIccCard().hasIccCard();
4960 } else {
4961 return false;
4962 }
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004966 }
4967
4968 /**
4969 * Return if the current radio is LTE on CDMA. This
4970 * is a tri-state return value as for a period of time
4971 * the mode may be unknown.
4972 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004973 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004974 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004975 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004976 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004977 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004978 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4979 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4980 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004981 }
4982
Sanket Padawe356d7632015-06-22 14:03:32 -07004983 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4985 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004986 try {
4987 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4988 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004989 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4990 }
4991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 final Phone phone = getPhone(subId);
4995 if (phone == null) {
4996 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4997 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004998 return TelephonyProperties.lte_on_cdma_device()
4999 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 }
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005003 }
Wink Saville36469e72014-06-11 15:17:00 -07005004 }
5005
Wink Saville36469e72014-06-11 15:17:00 -07005006 /**
5007 * {@hide}
5008 * Returns Default subId, 0 in the case of single standby.
5009 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005010 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005011 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005012 }
5013
Shishir Agrawala9f32182016-04-12 12:00:16 -07005014 private int getSlotForDefaultSubscription() {
5015 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5016 }
5017
Wink Savilleb564aae2014-10-23 10:18:09 -07005018 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005019 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005020 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005021
Pengquan Menge92a50d2018-09-21 15:54:48 -07005022 private boolean isActiveSubscription(int subId) {
5023 return mSubscriptionController.isActiveSubId(subId);
5024 }
5025
Ihab Awadf2177b72013-11-25 13:33:23 -08005026 /**
5027 * @see android.telephony.TelephonyManager.WifiCallingChoices
5028 */
5029 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 final long identity = Binder.clearCallingIdentity();
5031 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005032 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5034 getWhenToMakeWifiCallsDefaultPreference());
5035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005038 }
5039
5040 /**
5041 * @see android.telephony.TelephonyManager.WifiCallingChoices
5042 */
5043 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005047 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005052 }
5053
Sailesh Nepald1e68152013-12-12 19:08:02 -08005054 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005055 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005056 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005057 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005058
Jordan Liu4c733742019-02-28 12:03:40 -08005059 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5060 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5061 if (phoneId == -1) {
5062 throw new IllegalArgumentException("Given slot index: " + slotIndex
5063 + " does not correspond to an active phone");
5064 }
5065 return PhoneFactory.getPhone(phoneId);
5066 }
5067
Shishir Agrawal566b7612013-10-28 14:41:00 -07005068 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005069 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5070 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005074 if (DBG) {
5075 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5076 }
5077 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5078 p2);
5079 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005080
Jordan Liu4c733742019-02-28 12:03:40 -08005081
5082 @Override
5083 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5084 int slotIndex, String callingPackage, String aid, int p2) {
5085 enforceModifyPermission();
5086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5087 if (DBG) {
5088 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5089 }
5090 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5091 callingPackage, aid, p2);
5092 }
5093
5094 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5095 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 if (TextUtils.equals(ISDR_AID, aid)) {
5099 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005100 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5101 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 if (bestComponent == null
5103 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5104 loge("The calling package is not allowed to access ISD-R.");
5105 throw new SecurityException(
5106 "The calling package is not allowed to access ISD-R.");
5107 }
Derek Tan740e1672017-06-27 14:56:27 -07005108 }
Derek Tan740e1672017-06-27 14:56:27 -07005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005111 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5112 null /* workSource */);
5113 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 return response;
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005118 }
5119
5120 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005121 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5123 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005124 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5125 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5126 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005127
Jordan Liu4c733742019-02-28 12:03:40 -08005128 @Override
5129 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5130 enforceModifyPermission();
5131 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5132 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5133 channel);
5134 }
5135
5136 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 if (channel < 0) {
5140 return false;
5141 }
Jordan Liu4c733742019-02-28 12:03:40 -08005142 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5143 null /* workSource */);
5144 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 return success;
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005148 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005149 }
5150
5151 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005152 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005153 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005156 if (DBG) {
5157 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5158 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5159 + p3 + " data=" + data);
5160 }
5161 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5162 command, p1, p2, p3, data);
5163 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005164
Jordan Liu4c733742019-02-28 12:03:40 -08005165 @Override
5166 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5167 int command, int p1, int p2, int p3, String data) {
5168 enforceModifyPermission();
5169 if (DBG) {
5170 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5171 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5172 + p3 + " data=" + data);
5173 }
5174 return iccTransmitApduLogicalChannelWithPermission(
5175 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5176 data);
5177 }
5178
5179 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5180 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005183 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 return "";
5185 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005188 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5189 null /* workSource */);
5190 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 // Append the returned status code to the end of the response payload.
5193 String s = Integer.toHexString(
5194 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5195 if (response.payload != null) {
5196 s = IccUtils.bytesToHexString(response.payload) + s;
5197 }
5198 return s;
5199 } finally {
5200 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005201 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005202 }
Jake Hambye994d462014-02-03 13:10:13 -08005203
Evan Charltonc66da362014-05-16 14:06:40 -07005204 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005205 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5206 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5208 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005210 if (DBG) {
5211 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5212 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5213 }
5214 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5215 cla, command, p1, p2, p3, data);
5216 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005217
Jordan Liu4c733742019-02-28 12:03:40 -08005218 @Override
5219 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5220 int command, int p1, int p2, int p3, String data) {
5221 enforceModifyPermission();
5222 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5223 if (DBG) {
5224 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5225 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5226 + " data=" + data);
5227 }
5228
5229 return iccTransmitApduBasicChannelWithPermission(
5230 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5231 p2, p3, data);
5232 }
5233
5234 // open APDU basic channel assuming the caller has sufficient permissions
5235 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5236 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5240 && TextUtils.equals(ISDR_AID, data)) {
5241 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005242 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5243 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 if (bestComponent == null
5245 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5246 loge("The calling package is not allowed to select ISD-R.");
5247 throw new SecurityException(
5248 "The calling package is not allowed to select ISD-R.");
5249 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005250 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005253 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5254 null /* workSource */);
5255 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 // Append the returned status code to the end of the response payload.
5258 String s = Integer.toHexString(
5259 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5260 if (response.payload != null) {
5261 s = IccUtils.bytesToHexString(response.payload) + s;
5262 }
5263 return s;
5264 } finally {
5265 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005266 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005267 }
5268
5269 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005270 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005271 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5273 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) {
5278 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5279 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5280 }
5281
5282 IccIoResult response =
5283 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5284 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5285 subId);
5286
5287 if (DBG) {
5288 log("Exchange SIM_IO [R]" + response);
5289 }
5290
5291 byte[] result = null;
5292 int length = 2;
5293 if (response.payload != null) {
5294 length = 2 + response.payload.length;
5295 result = new byte[length];
5296 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5297 } else {
5298 result = new byte[length];
5299 }
5300
5301 result[length - 1] = (byte) response.sw2;
5302 result[length - 2] = (byte) response.sw1;
5303 return result;
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005306 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005307 }
5308
Nathan Haroldb3014052017-01-25 15:57:32 -08005309 /**
5310 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5311 * on a particular subscription
5312 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005313 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5314 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005316 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005317 return null;
5318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 if (appType != TelephonyManager.APPTYPE_USIM
5323 && appType != TelephonyManager.APPTYPE_SIM) {
5324 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5325 return null;
5326 }
5327 Object response = sendRequest(
5328 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5329 if (response instanceof String[]) {
5330 return (String[]) response;
5331 }
yincheng zhao2737e882019-09-06 17:06:54 -07005332 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005334 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 } finally {
5336 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005337 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005338 }
5339
yincheng zhao2737e882019-09-06 17:06:54 -07005340 /**
5341 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5342 * subscription.
5343 *
5344 * @param subId the id of the subscription.
5345 * @param appType the uicc app type, must be USIM or SIM.
5346 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5347 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005348 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005349 * @return number of fplmns that is successfully written to the SIM.
5350 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005351 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5352 String callingFeatureId) {
5353 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5354 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005355 if (DBG) logv("no permissions for setForbiddenplmns");
5356 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5357 }
5358 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5359 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5360 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5361 }
5362 if (fplmns == null) {
5363 throw new IllegalArgumentException("Fplmn List provided is null");
5364 }
5365 for (String fplmn : fplmns) {
5366 if (!CellIdentity.isValidPlmn(fplmn)) {
5367 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5368 }
5369 }
5370 final long identity = Binder.clearCallingIdentity();
5371 try {
5372 Object response = sendRequest(
5373 CMD_SET_FORBIDDEN_PLMNS,
5374 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5375 subId);
5376 return (int) response;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
5380 }
5381
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005382 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005383 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5385 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 final long identity = Binder.clearCallingIdentity();
5388 try {
5389 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5390 if (response.payload == null) {
5391 return "";
5392 }
Evan Charltonc66da362014-05-16 14:06:40 -07005393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 // Append the returned status code to the end of the response payload.
5395 String s = Integer.toHexString(
5396 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5397 s = IccUtils.bytesToHexString(response.payload) + s;
5398 return s;
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Evan Charltonc66da362014-05-16 14:06:40 -07005402 }
5403
Jake Hambye994d462014-02-03 13:10:13 -08005404 /**
5405 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5406 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5407 *
5408 * @param itemID the ID of the item to read
5409 * @return the NV item as a String, or null on error.
5410 */
5411 @Override
5412 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5415 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
5419 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005420 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5422 return value;
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Jake Hambye994d462014-02-03 13:10:13 -08005426 }
5427
5428 /**
5429 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5430 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5431 *
5432 * @param itemID the ID of the item to read
5433 * @param itemValue the value to write, as a String
5434 * @return true on success; false on any failure
5435 */
5436 @Override
5437 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
5442 final long identity = Binder.clearCallingIdentity();
5443 try {
5444 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5445 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005446 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5448 return success;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
Jake Hambye994d462014-02-03 13:10:13 -08005452 }
5453
5454 /**
5455 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5456 * Used for device configuration by some CDMA operators.
5457 *
5458 * @param preferredRoamingList byte array containing the new PRL
5459 * @return true on success; false on any failure
5460 */
5461 @Override
5462 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5464 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5469 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5470 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5471 return success;
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
Jake Hambye994d462014-02-03 13:10:13 -08005475 }
5476
5477 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005478 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005479 * Used for device configuration by some CDMA operators.
5480 *
chen xu6dac5ab2018-10-26 17:39:23 -07005481 * @param slotIndex - device slot.
5482 *
Jake Hambye994d462014-02-03 13:10:13 -08005483 * @return true on success; false on any failure
5484 */
5485 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005486 public boolean resetModemConfig(int slotIndex) {
5487 Phone phone = PhoneFactory.getPhone(slotIndex);
5488 if (phone != null) {
5489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5490 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
chen xu6dac5ab2018-10-26 17:39:23 -07005492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5495 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5496 return success;
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 }
chen xu6dac5ab2018-10-26 17:39:23 -07005501 return false;
5502 }
5503
5504 /**
5505 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5506 *
5507 * @param slotIndex - device slot.
5508 *
5509 * @return true on success; false on any failure
5510 */
5511 @Override
5512 public boolean rebootModem(int slotIndex) {
5513 Phone phone = PhoneFactory.getPhone(slotIndex);
5514 if (phone != null) {
5515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5516 mApp, phone.getSubId(), "rebootModem");
5517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
5520 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5521 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5522 return success;
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
5526 }
5527 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005528 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005529
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005530 public String[] getPcscfAddress(String apnType, String callingPackage,
5531 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005532 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5534 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005535 return new String[0];
5536 }
5537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005540 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Wink Saville36469e72014-06-11 15:17:00 -07005544 }
5545
Brad Ebinger51f743a2017-01-23 13:50:20 -08005546 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005547 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5548 * {@link #disableIms(int)}.
5549 * @param slotIndex device slot.
5550 */
5551 public void resetIms(int slotIndex) {
5552 enforceModifyPermission();
5553
5554 final long identity = Binder.clearCallingIdentity();
5555 try {
5556 if (mImsResolver == null) {
5557 // may happen if the does not support IMS.
5558 return;
5559 }
5560 mImsResolver.disableIms(slotIndex);
5561 mImsResolver.enableIms(slotIndex);
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
5565 }
5566
5567 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005568 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5569 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005570 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005571 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573
5574 final long identity = Binder.clearCallingIdentity();
5575 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005576 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005577 // may happen if the device does not support IMS.
5578 return;
5579 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005580 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005584 }
5585
5586 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005587 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5588 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005589 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005590 public void disableIms(int slotId) {
5591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005595 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005596 // may happen if the device does not support IMS.
5597 return;
5598 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005603 }
5604
5605 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005606 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5607 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005608 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005609 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005610 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005615 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005616 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5617 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005618 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005619 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005623 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005624 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005625 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5626 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005627 @Override
5628 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005629 enforceModifyPermission();
5630
5631 final long identity = Binder.clearCallingIdentity();
5632 try {
5633 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005634 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
5638 }
5639
5640 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005641 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005642 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005643 */
5644 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005650 // may happen if the device does not support IMS.
5651 return null;
5652 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005653 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005657 }
5658
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005659 /**
5660 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005661 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005662 */
5663 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005669 // may happen if the device does not support IMS.
5670 return null;
5671 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005672 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005676 }
5677
Brad Ebinger884c07b2018-02-15 16:17:40 -08005678 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005679 * Sets the ImsService Package Name that Telephony will bind to.
5680 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005681 * @param slotIndex the slot ID that the ImsService should bind for.
5682 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005683 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005684 * @param featureTypes An integer array of feature types associated with a packageName.
5685 * @param packageName The name of the package that the current configuration will be replaced
5686 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005687 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005688 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005689 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5690 int[] featureTypes, String packageName) {
5691 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5694 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005695 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 final long identity = Binder.clearCallingIdentity();
5698 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005699 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005700 // may happen if the device does not support IMS.
5701 return false;
5702 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005703 Map<Integer, String> featureConfig = new HashMap<>();
5704 for (int featureType : featureTypes) {
5705 featureConfig.put(featureType, packageName);
5706 }
5707 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5708 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005712 }
5713
5714 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005715 * Clears any carrier ImsService overrides for the slot index specified that were previously
5716 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5717 *
5718 * This should only be used for testing.
5719 *
5720 * @param slotIndex the slot ID that the ImsService should bind for.
5721 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5722 */
5723 @Override
5724 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5725 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5727 "clearCarrierImsServiceOverride");
5728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5729 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5730 "clearCarrierImsServiceOverride");
5731
5732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 if (mImsResolver == null) {
5735 // may happen if the device does not support IMS.
5736 return false;
5737 }
5738 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
5742 }
5743
5744 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005745 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005746 *
5747 * @param slotId The slot that the ImsService is associated with.
5748 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5749 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005751 * @return the package name of the ImsService configuration.
5752 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5754 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005755 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005756 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005757 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5759 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 final long identity = Binder.clearCallingIdentity();
5762 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005763 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005764 // may happen if the device does not support IMS.
5765 return "";
5766 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005767 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5769 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005773 }
5774
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005775 /**
5776 * Get the MmTelFeature state associated with the requested subscription id.
5777 * @param subId The subscription that the MmTelFeature is associated with.
5778 * @param callback A callback with an integer containing the
5779 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5780 */
5781 @Override
5782 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5783 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5784 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5786 "IMS not available on device.");
5787 }
5788 final long token = Binder.clearCallingIdentity();
5789 try {
5790 int slotId = getSlotIndex(subId);
5791 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5792 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5793 + subId + "'");
5794 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5795 }
5796 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5797 try {
5798 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5799 } catch (RemoteException e) {
5800 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5801 + "Ignore");
5802 }
5803 });
5804 } finally {
5805 Binder.restoreCallingIdentity(token);
5806 }
5807 }
5808
Daniel Brightbb5840b2021-01-12 15:48:18 -08005809 /**
5810 * Sets the ims registration state on all valid {@link Phone}s.
5811 */
5812 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005813 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005817 // NOTE: Before S, this method only set the default phone.
5818 for (final Phone phone : PhoneFactory.getPhones()) {
5819 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5820 phone.setImsRegistrationState(registered);
5821 }
5822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
Wink Saville36469e72014-06-11 15:17:00 -07005826 }
5827
5828 /**
Stuart Scott54788802015-03-30 13:18:01 -07005829 * Set the network selection mode to automatic.
5830 *
5831 */
5832 @Override
5833 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5835 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
shilufc958392020-01-20 11:36:01 -08005839 if (!isActiveSubscription(subId)) {
5840 return;
5841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005843 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5844 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
Stuart Scott54788802015-03-30 13:18:01 -07005848 }
5849
Jack Yud10cdd42020-09-28 20:28:01 -07005850 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005851 * Ask the radio to connect to the input network and change selection mode to manual.
5852 *
5853 * @param subId the id of the subscription.
5854 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5855 * the operator to attach to.
5856 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5857 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5858 * normal network selection next time.
5859 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005860 */
5861 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005862 public boolean setNetworkSelectionModeManual(
5863 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5865 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005866
5867 if (!isActiveSubscription(subId)) {
5868 return false;
5869 }
5870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 final long identity = Binder.clearCallingIdentity();
5872 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005873 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005875 if (DBG) {
5876 log("setNetworkSelectionModeManual: subId: " + subId
5877 + " operator: " + operatorInfo);
5878 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005883 }
shilu84f6e8b2019-12-19 13:58:01 -08005884 /**
5885 * Get the manual network selection
5886 *
5887 * @param subId the id of the subscription.
5888 *
5889 * @return the previously saved user selected PLMN
5890 */
5891 @Override
5892 public String getManualNetworkSelectionPlmn(int subId) {
5893 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005894 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005895 mApp, subId, "getManualNetworkSelectionPlmn");
5896
5897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005900 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005901 }
5902
5903 final Phone phone = getPhone(subId);
5904 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005905 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005906 }
5907 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5908 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5909 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5910 } finally {
5911 Binder.restoreCallingIdentity(identity);
5912 }
5913 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005914
5915 /**
5916 * Scans for available networks.
5917 */
5918 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005919 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005923 LocationAccessPolicy.LocationPermissionResult locationResult =
5924 LocationAccessPolicy.checkLocationPermission(mApp,
5925 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5926 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005927 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005928 .setCallingPid(Binder.getCallingPid())
5929 .setCallingUid(Binder.getCallingUid())
5930 .setMethod("getCellNetworkScanResults")
5931 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005932 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5933 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005934 .build());
5935 switch (locationResult) {
5936 case DENIED_HARD:
5937 throw new SecurityException("Not allowed to access scan results -- location");
5938 case DENIED_SOFT:
5939 return null;
5940 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941
Pengquan Menga1bb6272018-09-06 09:59:22 -07005942 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 try {
5944 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005945 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005950 }
5951
5952 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005953 * Get the call forwarding info, given the call forwarding reason.
5954 */
5955 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005956 public void getCallForwarding(int subId, int callForwardingReason,
5957 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005958 enforceReadPrivilegedPermission("getCallForwarding");
5959 long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (DBG) {
5962 log("getCallForwarding: subId " + subId
5963 + " callForwardingReason" + callForwardingReason);
5964 }
Hall Liu27d24262020-09-18 19:04:59 -07005965
5966 Phone phone = getPhone(subId);
5967 if (phone == null) {
5968 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005969 callback.onError(
5970 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005971 } catch (RemoteException e) {
5972 // ignore
5973 }
5974 return;
5975 }
5976
5977 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5978 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5979 @Override
5980 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5981 try {
5982 callback.onCallForwardingInfoAvailable(info);
5983 } catch (RemoteException e) {
5984 // ignore
5985 }
5986 }
5987
5988 @Override
5989 public void onError(int error) {
5990 try {
5991 callback.onError(error);
5992 } catch (RemoteException e) {
5993 // ignore
5994 }
5995 }
5996 });
5997 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
6001 }
6002
6003 /**
6004 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6005 * reason, the number to forward, and the timeout before the forwarding is attempted.
6006 */
6007 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006008 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6009 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006010 enforceModifyPermission();
6011 long identity = Binder.clearCallingIdentity();
6012 try {
6013 if (DBG) {
6014 log("setCallForwarding: subId " + subId
6015 + " callForwardingInfo" + callForwardingInfo);
6016 }
Hall Liu27d24262020-09-18 19:04:59 -07006017
6018 Phone phone = getPhone(subId);
6019 if (phone == null) {
6020 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006021 callback.accept(
6022 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006023 } catch (RemoteException e) {
6024 // ignore
6025 }
6026 return;
6027 }
6028
6029 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6030 FunctionalUtils.ignoreRemoteException(callback::accept));
6031
6032 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
6036 }
6037
6038 /**
Hall Liu27d24262020-09-18 19:04:59 -07006039 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006040 */
6041 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006042 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006043 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006044 long identity = Binder.clearCallingIdentity();
6045 try {
Hall Liu27d24262020-09-18 19:04:59 -07006046 Phone phone = getPhone(subId);
6047 if (phone == null) {
6048 try {
6049 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6050 } catch (RemoteException e) {
6051 // ignore
6052 }
6053 return;
6054 }
SongFerngWang0e767992021-03-31 22:08:45 +08006055 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6056 PersistableBundle c = configManager.getConfigForSubId(subId);
6057 boolean requireUssd = c.getBoolean(
6058 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006059
Shuo Qian4a594052020-01-23 11:59:30 -08006060 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006061 if (requireUssd) {
6062 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6063 getSubscriptionCarrierId(subId));
6064 String newUssdCommand = "";
6065 try {
6066 newUssdCommand = carrierXmlParser.getFeature(
6067 CarrierXmlParser.FEATURE_CALL_WAITING)
6068 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6069 } catch (NullPointerException e) {
6070 loge("Failed to generate USSD number" + e);
6071 }
6072 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6073 mMainThreadHandler, callback, carrierXmlParser,
6074 CarrierXmlParser.SsEntry.SSAction.QUERY);
6075 final String ussdCommand = newUssdCommand;
6076 Executors.newSingleThreadExecutor().execute(() -> {
6077 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6078 });
6079 } else {
6080 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6081 callback::accept);
6082 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6083 }
Shuo Qian4a594052020-01-23 11:59:30 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
6087 }
6088
6089 /**
Hall Liu27d24262020-09-18 19:04:59 -07006090 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006091 */
6092 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006093 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006094 enforceModifyPermission();
6095 long identity = Binder.clearCallingIdentity();
6096 try {
Hall Liu27d24262020-09-18 19:04:59 -07006097 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6098
6099 Phone phone = getPhone(subId);
6100 if (phone == null) {
6101 try {
6102 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6103 } catch (RemoteException e) {
6104 // ignore
6105 }
6106 return;
6107 }
6108
SongFerngWang0e767992021-03-31 22:08:45 +08006109 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6110 PersistableBundle c = configManager.getConfigForSubId(subId);
6111 boolean requireUssd = c.getBoolean(
6112 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006113
SongFerngWang0e767992021-03-31 22:08:45 +08006114 if (DBG) log("getCallWaitingStatus: subId " + subId);
6115 if (requireUssd) {
6116 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6117 getSubscriptionCarrierId(subId));
6118 CarrierXmlParser.SsEntry.SSAction ssAction =
6119 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6120 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6121 String newUssdCommand = "";
6122 try {
6123 newUssdCommand = carrierXmlParser.getFeature(
6124 CarrierXmlParser.FEATURE_CALL_WAITING)
6125 .makeCommand(ssAction, null);
6126 } catch (NullPointerException e) {
6127 loge("Failed to generate USSD number" + e);
6128 }
6129 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6130 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6131 final String ussdCommand = newUssdCommand;
6132 Executors.newSingleThreadExecutor().execute(() -> {
6133 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6134 });
6135 } else {
6136 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6137 FunctionalUtils.ignoreRemoteException(callback::accept));
6138
6139 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6140 }
Shuo Qian4a594052020-01-23 11:59:30 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
6144 }
6145
6146 /**
yinxub1bed742017-04-17 11:45:04 -07006147 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006148 *
yinxub1bed742017-04-17 11:45:04 -07006149 * @param subId id of the subscription
6150 * @param request contains the radio access networks with bands/channels to scan
6151 * @param messenger callback messenger for scan results or errors
6152 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006153 * @return the id of the requested scan which can be used to stop the scan.
6154 */
6155 @Override
6156 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006157 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6159 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006160 LocationAccessPolicy.LocationPermissionResult locationResult =
6161 LocationAccessPolicy.checkLocationPermission(mApp,
6162 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6163 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006164 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006165 .setCallingPid(Binder.getCallingPid())
6166 .setCallingUid(Binder.getCallingUid())
6167 .setMethod("requestNetworkScan")
6168 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006169 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6170 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006171 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006172 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006173 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6174 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006175 if (e != null) {
6176 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6177 throw e;
6178 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006179 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006180 return TelephonyScanManager.INVALID_SCAN_ID;
6181 }
6182 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 }
Hall Liu912dfd32019-04-25 14:02:26 -07006184 int callingUid = Binder.getCallingUid();
6185 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 return mNetworkScanRequestTracker.startNetworkScan(
6189 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006190 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
yinxu504e1392017-04-12 16:03:22 -07006194 }
6195
Hall Liub2ac8ef2019-02-28 15:56:23 -08006196 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006197 NetworkScanRequest request, int subId, String callingPackage) {
6198 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006199 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6200 boolean hasNetworkScanPermission =
6201 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6202 == PERMISSION_GRANTED;
6203
6204 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6205 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6206 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006207 }
6208
6209 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6210 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006211 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6212 return new SecurityException("Specific channels must not be"
6213 + " scanned without location access.");
6214 }
6215 }
6216 }
6217
Hall Liub2ac8ef2019-02-28 15:56:23 -08006218 return null;
6219 }
6220
yinxu504e1392017-04-12 16:03:22 -07006221 /**
6222 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006223 *
6224 * @param subId id of the subscription
6225 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006226 */
6227 @Override
6228 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6230 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
Hall Liu912dfd32019-04-25 14:02:26 -07006232 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 final long identity = Binder.clearCallingIdentity();
6234 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006235 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
yinxu504e1392017-04-12 16:03:22 -07006239 }
6240
6241 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006242 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006243 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006244 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006245 */
6246 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006247 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006248 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006249 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006250 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251
6252 final long identity = Binder.clearCallingIdentity();
6253 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006254 if (DBG) log("getAllowedNetworkTypesBitmask");
6255 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6256 int networkTypesBitmask = (result != null ? result[0] : -1);
6257 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6258 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
6261 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006262 }
6263
6264 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006265 * Get the allowed network types for certain reason.
6266 *
6267 * @param subId the id of the subscription.
6268 * @param reason the reason the allowed network type change is taking place
6269 * @return the allowed network types.
6270 */
6271 @Override
6272 public long getAllowedNetworkTypesForReason(int subId,
6273 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006274 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006275 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006276 final long identity = Binder.clearCallingIdentity();
6277 try {
6278 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
6282 }
6283
6284 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006285 * Enable/Disable E-UTRA-NR Dual Connectivity
6286 * @param subId subscription id of the sim card
6287 * @param nrDualConnectivityState expected NR dual connectivity state
6288 * This can be passed following states
6289 * <ol>
6290 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6291 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6292 * <li>Disable NR dual connectivity and force secondary cell to be released
6293 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6294 * </ol>
6295 * @return operation result.
6296 */
6297 @Override
6298 public int setNrDualConnectivityState(int subId,
6299 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6301 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006302 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006303 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6304 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6305 }
6306
Sooraj Sasindran37444802020-08-11 10:40:43 -07006307 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6308 final long identity = Binder.clearCallingIdentity();
6309 try {
6310 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6311 nrDualConnectivityState, subId,
6312 workSource);
6313 if (DBG) log("enableNRDualConnectivity result: " + result);
6314 return result;
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
6318 }
6319
6320 /**
6321 * Is E-UTRA-NR Dual Connectivity enabled
6322 * @return true if dual connectivity is enabled else false
6323 */
6324 @Override
6325 public boolean isNrDualConnectivityEnabled(int subId) {
6326 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006327 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006328 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006329 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006330 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6331 return false;
6332 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6337 null, subId, workSource);
6338 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6339 return isEnabled;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
6342 }
6343 }
6344
6345 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006346 * Set the allowed network types of the device and
6347 * provide the reason triggering the allowed network change.
6348 *
6349 * @param subId the id of the subscription.
6350 * @param reason the reason the allowed network type change is taking place
6351 * @param allowedNetworkTypes the allowed network types.
6352 * @return true on success; false on any failure.
6353 */
6354 @Override
6355 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006356 @TelephonyManager.AllowedNetworkTypesReason int reason,
6357 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6359 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006360 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6361 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6362 return false;
6363 }
6364
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006365 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6366 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6367
6368
6369 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6370 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6371 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006372 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006373
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006374 final long identity = Binder.clearCallingIdentity();
6375 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006376 Boolean success = (Boolean) sendRequest(
6377 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6378 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6379
6380 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6381 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
6385 }
6386
6387 /**
Miaoa84611c2019-03-15 09:21:10 +08006388 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006389 *
Miaoa84611c2019-03-15 09:21:10 +08006390 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006391 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006392 * @hide
6393 */
6394 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006395 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006396 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006398 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 try {
Miaoa84611c2019-03-15 09:21:10 +08006400 if (phone != null) {
6401 return phone.hasMatchedTetherApnSetting();
6402 } else {
6403 return false;
6404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006407 }
Junda Liu475951f2014-11-07 16:45:03 -08006408 }
6409
6410 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006411 * Enable or disable always reporting signal strength changes from radio.
6412 *
6413 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6414 */
6415 @Override
6416 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6417 enforceModifyPermission();
6418 enforceSystemCaller();
6419
6420 final long identity = Binder.clearCallingIdentity();
6421 final Phone phone = getPhone(subId);
6422 try {
6423 if (phone != null) {
6424 if (DBG) {
6425 log("setAlwaysReportSignalStrength: subId=" + subId
6426 + " isEnable=" + isEnable);
6427 }
6428 phone.setAlwaysReportSignalStrength(isEnable);
6429 } else {
6430 loge("setAlwaysReportSignalStrength: no phone found for subId="
6431 + subId);
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
6438 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006439 * Get the user enabled state of Mobile Data.
6440 *
6441 * TODO: remove and use isUserDataEnabled.
6442 * This can't be removed now because some vendor codes
6443 * calls through ITelephony directly while they should
6444 * use TelephonyManager.
6445 *
6446 * @return true on enabled
6447 */
6448 @Override
6449 public boolean getDataEnabled(int subId) {
6450 return isUserDataEnabled(subId);
6451 }
6452
6453 /**
6454 * Get whether mobile data is enabled per user setting.
6455 *
6456 * There are other factors deciding whether mobile data is actually enabled, but they are
6457 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006458 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006459 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006460 *
6461 * @return {@code true} if data is enabled else {@code false}
6462 */
6463 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006464 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006465 try {
6466 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6467 null);
6468 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6470 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 int phoneId = mSubscriptionController.getPhoneId(subId);
6476 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6477 Phone phone = PhoneFactory.getPhone(phoneId);
6478 if (phone != null) {
6479 boolean retVal = phone.isUserDataEnabled();
6480 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6481 return retVal;
6482 } else {
6483 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6484 return false;
6485 }
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006488 }
6489 }
6490
6491 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006492 * Checks if the device is capable of mobile data by considering whether whether the
6493 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6494 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006495 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006496 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006497 */
6498 @Override
6499 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006500 try {
6501 try {
6502 mApp.enforceCallingOrSelfPermission(
6503 android.Manifest.permission.ACCESS_NETWORK_STATE,
6504 null);
6505 } catch (Exception e) {
6506 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6507 "isDataEnabled");
6508 }
6509 } catch (Exception e) {
6510 enforceReadPrivilegedPermission("isDataEnabled");
6511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 int phoneId = mSubscriptionController.getPhoneId(subId);
6516 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6517 Phone phone = PhoneFactory.getPhone(phoneId);
6518 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006519 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6521 return retVal;
6522 } else {
6523 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6524 return false;
6525 }
6526 } finally {
6527 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006528 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006529 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006530
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006531 /**
6532 * Check if data is enabled for a specific reason
6533 * @param subId Subscription index
6534 * @param reason the reason the data enable change is taking place
6535 * @return {@code true} if the overall data is enabled; {@code false} if not.
6536 */
6537 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006538 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006539 @TelephonyManager.DataEnabledReason int reason) {
6540 try {
6541 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6542 null);
6543 } catch (Exception e) {
6544 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006545 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006546 }
6547
6548
6549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 int phoneId = mSubscriptionController.getPhoneId(subId);
6552 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006553 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006554 + " reason=" + reason);
6555 }
6556 Phone phone = PhoneFactory.getPhone(phoneId);
6557 if (phone != null) {
6558 boolean retVal;
6559 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6560 retVal = phone.isUserDataEnabled();
6561 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006562 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006563 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006564 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006565 return retVal;
6566 } else {
6567 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006568 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006569 + subId + " retVal=false");
6570 }
6571 return false;
6572 }
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
6576 }
6577
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006578 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006579 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006580 if (uid == Process.PHONE_UID) {
6581 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6582 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006583 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6584 }
6585
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006586 //load access rules from carrier configs, and check those as well: b/139133814
6587 SubscriptionController subController = SubscriptionController.getInstance();
6588 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6589 || subController == null) return privilegeFromSim;
6590
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006591 PackageManager pkgMgr = phone.getContext().getPackageManager();
6592 String[] packages = pkgMgr.getPackagesForUid(uid);
6593
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006596 int subId = phone.getSubId();
6597 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6598 // A test override is in place for the privileges for this subId, so don't try to
6599 // read the subscription privileges.
6600 return privilegeFromSim;
6601 }
6602 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006603 SubscriptionManager subManager = (SubscriptionManager)
6604 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6605 for (String pkg : packages) {
6606 if (subManager.canManageSubscription(subInfo, pkg)) {
6607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6608 }
6609 }
6610 return privilegeFromSim;
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 }
6615
6616 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6617 String pkgName) {
6618 //load access rules from carrier configs, and check those as well: b/139133814
6619 SubscriptionController subController = SubscriptionController.getInstance();
6620 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6621 || subController == null) return privilegeFromSim;
6622
6623 final long identity = Binder.clearCallingIdentity();
6624 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006625 int subId = phone.getSubId();
6626 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6627 // A test override is in place for the privileges for this subId, so don't try to
6628 // read the subscription privileges.
6629 return privilegeFromSim;
6630 }
6631 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006632 SubscriptionManager subManager = (SubscriptionManager)
6633 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6634 return subManager.canManageSubscription(subInfo, pkgName)
6635 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
6640
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006641 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006642 public int getCarrierPrivilegeStatus(int subId) {
6643 final Phone phone = getPhone(subId);
6644 if (phone == null) {
6645 loge("getCarrierPrivilegeStatus: Invalid subId");
6646 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6647 }
6648 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006649 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006650 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006651 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6652 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006653
6654 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6655 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006656 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006657 }
Junda Liu29340342014-07-10 15:23:27 -07006658
6659 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006660 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006661 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006662 final Phone phone = getPhone(subId);
6663 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006664 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006665 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6666 }
6667 UiccProfile profile =
6668 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6669 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006670 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006671 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6672 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006673 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006674 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006675 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006676 }
6677
6678 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006679 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6680 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006681 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006682 }
6683
6684 int phoneId = SubscriptionManager.getPhoneId(subId);
6685 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006686 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006687 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006688 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6689 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006690 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6691 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6692 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006693 }
6694
6695 @Override
6696 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006697 if (TextUtils.isEmpty(pkgName))
6698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006699 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6700 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6701 UiccCard card = UiccController.getInstance().getUiccCard(i);
6702 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006703 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006704 continue;
6705 }
6706
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006707 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6708 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6709 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006710 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6711 break;
6712 }
6713 }
6714
6715 return result;
Junda Liu29340342014-07-10 15:23:27 -07006716 }
Derek Tan89e89d42014-07-08 17:00:10 -07006717
6718 @Override
Junda Liue64de782015-04-16 17:19:16 -07006719 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6720 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6721 loge("phoneId " + phoneId + " is not valid.");
6722 return null;
6723 }
6724 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006725 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006726 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006727 return null ;
6728 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006729 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006730 }
6731
Amith Yamasani6e118872016-02-19 12:53:51 -08006732 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006733 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006735 List<String> privilegedPackages = new ArrayList<>();
6736 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006737 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6738 // has UICC in that slot.
6739 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006740 if (card.hasCarrierPrivilegeRules()) {
6741 if (packages == null) {
6742 // Only check packages in user 0 for now
6743 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006744 PackageManager.MATCH_DISABLED_COMPONENTS
6745 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006746 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006747 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006748 }
6749 for (int p = packages.size() - 1; p >= 0; p--) {
6750 PackageInfo pkgInfo = packages.get(p);
6751 if (pkgInfo != null && pkgInfo.packageName != null
6752 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006753 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006754 privilegedPackages.add(pkgInfo.packageName);
6755 }
6756 }
6757 }
6758 }
6759 return privilegedPackages;
6760 }
6761
chen xuf7e9fe82019-05-09 19:31:02 -07006762 @Override
6763 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006764 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6765
6766 final long identity = Binder.clearCallingIdentity();
6767
chen xuf7e9fe82019-05-09 19:31:02 -07006768 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006769 try {
6770 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6771 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6772 }
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006775 }
6776 return privilegedPackages;
6777 }
6778
Wink Savilleb564aae2014-10-23 10:18:09 -07006779 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006780 final Phone phone = getPhone(subId);
6781 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006782 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006783 return null;
6784 }
6785 String iccId = card.getIccId();
6786 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006787 return null;
6788 }
6789 return iccId;
6790 }
6791
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006792 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006793 public void setCallComposerStatus(int subId, int status) {
6794 enforceModifyPermission();
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 Phone phone = getPhone(subId);
6799 if (phone != null) {
6800 Phone defaultPhone = phone.getImsPhone();
6801 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6802 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6803 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006804 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6805 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006806 }
6807 }
Shuo Qian284ae752020-12-22 19:10:14 -08006808 } catch (ImsException e) {
6809 throw new ServiceSpecificException(e.getCode());
6810 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006811 Binder.restoreCallingIdentity(identity);
6812 }
6813 }
6814
6815 @Override
6816 public int getCallComposerStatus(int subId) {
6817 enforceReadPrivilegedPermission("getCallComposerStatus");
6818
6819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 Phone phone = getPhone(subId);
6822 if (phone != null) {
6823 Phone defaultPhone = phone.getImsPhone();
6824 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6825 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6826 return imsPhone.getCallComposerStatus();
6827 }
6828 }
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
6832 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6833 }
6834
6835 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006836 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6837 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006838 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 final String iccId = getIccId(subId);
6844 final Phone phone = getPhone(subId);
6845 if (phone == null) {
6846 return false;
6847 }
6848 final String subscriberId = phone.getSubscriberId();
6849
6850 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006851 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 + subscriberId + " to " + number);
6853 }
6854
6855 if (TextUtils.isEmpty(iccId)) {
6856 return false;
6857 }
6858
6859 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6860
6861 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6862 if (alphaTag == null) {
6863 editor.remove(alphaTagPrefKey);
6864 } else {
6865 editor.putString(alphaTagPrefKey, alphaTag);
6866 }
6867
6868 // Record both the line number and IMSI for this ICCID, since we need to
6869 // track all merged IMSIs based on line number
6870 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6871 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6872 if (number == null) {
6873 editor.remove(numberPrefKey);
6874 editor.remove(subscriberPrefKey);
6875 } else {
6876 editor.putString(numberPrefKey, number);
6877 editor.putString(subscriberPrefKey, subscriberId);
6878 }
6879
6880 editor.commit();
6881 return true;
6882 } finally {
6883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006884 }
Derek Tan7226c842014-07-02 17:42:23 -07006885 }
6886
6887 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006888 public String getLine1NumberForDisplay(int subId, String callingPackage,
6889 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006890 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006892 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006893 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006894 return null;
6895 }
Derek Tan97ebb422014-09-05 16:55:38 -07006896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 String iccId = getIccId(subId);
6900 if (iccId != null) {
6901 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6902 if (DBG_MERGE) {
6903 log("getLine1NumberForDisplay returning "
6904 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6905 }
6906 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6909 return null;
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006912 }
Derek Tan7226c842014-07-02 17:42:23 -07006913 }
6914
6915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006916 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6917 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006919 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006920 return null;
6921 }
Derek Tan97ebb422014-09-05 16:55:38 -07006922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 final long identity = Binder.clearCallingIdentity();
6924 try {
6925 String iccId = getIccId(subId);
6926 if (iccId != null) {
6927 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6928 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6929 }
6930 return null;
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006933 }
Derek Tan7226c842014-07-02 17:42:23 -07006934 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006935
6936 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006937 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6938 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006939 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6940 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006942 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006943 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006944 return null;
6945 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006946
Jordan Liub49b04b2019-05-06 14:45:15 -07006947 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6948 // the process, where TelephonyManager was instantiated.
6949 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006950 final long identity = Binder.clearCallingIdentity();
6951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006952 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 final TelephonyManager tele = TelephonyManager.from(context);
6954 final SubscriptionManager sub = SubscriptionManager.from(context);
6955
6956 // Figure out what subscribers are currently active
6957 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958
Jordan Liub49b04b2019-05-06 14:45:15 -07006959 // Only consider subs which match the current subId
6960 // This logic can be simplified. See b/131189269 for progress.
6961 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006962 activeSubscriberIds.add(tele.getSubscriberId(subId));
6963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 // First pass, find a number override for an active subscriber
6966 String mergeNumber = null;
6967 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6968 for (String key : prefs.keySet()) {
6969 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6970 final String subscriberId = (String) prefs.get(key);
6971 if (activeSubscriberIds.contains(subscriberId)) {
6972 final String iccId = key.substring(
6973 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6974 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6975 mergeNumber = (String) prefs.get(numberKey);
6976 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006977 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 + " for active subscriber " + subscriberId);
6979 }
6980 if (!TextUtils.isEmpty(mergeNumber)) {
6981 break;
6982 }
6983 }
6984 }
6985 }
6986
6987 // Shortcut when no active merged subscribers
6988 if (TextUtils.isEmpty(mergeNumber)) {
6989 return null;
6990 }
6991
6992 // Second pass, find all subscribers under that line override
6993 final ArraySet<String> result = new ArraySet<>();
6994 for (String key : prefs.keySet()) {
6995 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6996 final String number = (String) prefs.get(key);
6997 if (mergeNumber.equals(number)) {
6998 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6999 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7000 final String subscriberId = (String) prefs.get(subscriberKey);
7001 if (!TextUtils.isEmpty(subscriberId)) {
7002 result.add(subscriberId);
7003 }
7004 }
7005 }
7006 }
7007
7008 final String[] resultArray = result.toArray(new String[result.size()]);
7009 Arrays.sort(resultArray);
7010 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007011 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7013 }
7014 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007015 } finally {
7016 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007017 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007018 }
7019
7020 @Override
zoey chen38003472019-12-13 17:16:31 +08007021 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7022 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007023
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 final TelephonyManager telephonyManager = mApp.getSystemService(
7027 TelephonyManager.class);
7028 String subscriberId = telephonyManager.getSubscriberId(subId);
7029 if (subscriberId == null) {
7030 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007031 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007032 + subId);
7033 }
7034 return null;
7035 }
7036
7037 final SubscriptionInfo info = SubscriptionController.getInstance()
7038 .getSubscriptionInfo(subId);
7039 final ParcelUuid groupUuid = info.getGroupUuid();
7040 // If it doesn't belong to any group, return just subscriberId of itself.
7041 if (groupUuid == null) {
7042 return new String[]{subscriberId};
7043 }
7044
7045 // Get all subscriberIds from the group.
7046 final List<String> mergedSubscriberIds = new ArrayList<>();
7047 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007048 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007049 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007050 for (SubscriptionInfo subInfo : groupInfos) {
7051 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7052 if (subscriberId != null) {
7053 mergedSubscriberIds.add(subscriberId);
7054 }
7055 }
7056
7057 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060
7061 }
7062 }
7063
7064 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007065 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007066 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007067 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068
7069 final long identity = Binder.clearCallingIdentity();
7070 try {
7071 final Phone phone = getPhone(subId);
7072 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007076 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007077
7078 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007079 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007080 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7081 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007082 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7083 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
7085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 final Phone phone = getPhone(subId);
7088 if (phone == null) {
7089 return false;
7090 }
7091 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7092 cdmaNonRoamingList);
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007095 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007096 }
7097
7098 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007099 @Deprecated
7100 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7101 enforceModifyPermission();
7102
7103 int returnValue = 0;
7104 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007105 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007106 if(result.exception == null) {
7107 if (result.result != null) {
7108 byte[] responseData = (byte[])(result.result);
7109 if(responseData.length > oemResp.length) {
7110 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7111 responseData.length + "bytes. Buffer Size is " +
7112 oemResp.length + "bytes.");
7113 }
7114 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7115 returnValue = responseData.length;
7116 }
7117 } else {
7118 CommandException ex = (CommandException) result.exception;
7119 returnValue = ex.getCommandError().ordinal();
7120 if(returnValue > 0) returnValue *= -1;
7121 }
7122 } catch (RuntimeException e) {
7123 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7124 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7125 if(returnValue > 0) returnValue *= -1;
7126 }
7127
7128 return returnValue;
7129 }
7130
7131 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007132 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007133 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007134 try {
7135 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007136 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007137 mApp, phone.getSubId(), "getRadioAccessFamily");
7138 } catch (SecurityException e) {
7139 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7140 throw e;
7141 }
chen xub97461a2018-10-26 14:17:57 -07007142 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007143 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007144 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 final long identity = Binder.clearCallingIdentity();
7147 try {
chen xub97461a2018-10-26 14:17:57 -07007148 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007149 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007150 mApp, phone.getSubId(), "getRadioAccessFamily");
7151 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
chen xub97461a2018-10-26 14:17:57 -07007155 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007156 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007157
7158 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007159 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007160 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007161 try {
7162 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7163 Binder.getCallingUid())) {
7164 throw new SecurityException("Package uid and package name do not match: "
7165 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7166 }
7167 } catch (PackageManager.NameNotFoundException e) {
7168 throw new SecurityException("Package name invalid:" + callingPackage);
7169 }
7170 RoleManager rm = mApp.getSystemService(RoleManager.class);
7171 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7172 if (!dialerRoleHolders.contains(callingPackage)) {
7173 throw new SecurityException("App must be the dialer role holder to"
7174 + " upload a call composer pic");
7175 }
7176
7177 Executors.newSingleThreadExecutor().execute(() -> {
7178 ByteArrayOutputStream output = new ByteArrayOutputStream(
7179 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7180 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7181 boolean readUntilEnd = false;
7182 int totalBytesRead = 0;
7183 byte[] buffer = new byte[16 * 1024];
7184 while (true) {
7185 int numRead;
7186 try {
7187 numRead = input.read(buffer);
7188 } catch (IOException e) {
7189 try {
7190 fd.checkError();
7191 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7192 null);
7193 } catch (IOException e1) {
7194 // This means that the other side closed explicitly with an error. If this
7195 // happens, log and ignore.
7196 loge("Remote end of call composer picture pipe closed: " + e1);
7197 }
7198 break;
7199 }
7200 if (numRead == -1) {
7201 readUntilEnd = true;
7202 break;
7203 }
7204 totalBytesRead += numRead;
7205 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7206 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7207 try {
7208 input.close();
7209 } catch (IOException e) {
7210 // ignore
7211 }
7212 break;
7213 }
7214 output.write(buffer, 0, numRead);
7215 }
7216 // Generally, the remote end will close the file descriptors. The only case where we
7217 // close is above, where the picture size is too big.
7218
7219 try {
7220 fd.checkError();
7221 } catch (IOException e) {
7222 loge("Remote end for call composer closed with an error: " + e);
7223 return;
7224 }
7225
Hall Liuaa4211e2021-01-20 15:43:39 -08007226 if (!readUntilEnd) {
7227 loge("Did not finish reading entire image; aborting");
7228 return;
7229 }
Hall Liu82694d52020-12-11 18:22:04 -08007230
Hall Liuaa4211e2021-01-20 15:43:39 -08007231 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7232 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7233 new CallComposerPictureTransfer.Factory() {},
7234 imageData,
7235 (result) -> {
7236 if (result.first != null) {
7237 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7238 Bundle outputResult = new Bundle();
7239 outputResult.putParcelable(
7240 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7241 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7242 outputResult);
7243 } else {
7244 callback.send(result.second, null);
7245 }
7246 }
7247 );
Hall Liu82694d52020-12-11 18:22:04 -08007248 });
7249 }
7250
7251 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007252 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007253 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255
7256 final long identity = Binder.clearCallingIdentity();
7257 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007258 ImsManager.getInstance(defaultPhone.getContext(),
7259 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 } finally {
7261 Binder.restoreCallingIdentity(identity);
7262 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007263 }
7264
7265 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007266 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007267 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7269 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007270 return false;
7271 }
Svet Ganovb320e182015-04-16 12:30:10 -07007272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 // Check the user preference and the system-level IMS setting. Even if the user has
7276 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7277 // In the long run, we may instead need to check if there exists a connection service
7278 // which can support video calling.
7279 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007280 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 return imsManager.isVtEnabledByPlatform()
7282 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7283 && imsManager.isVtEnabledByUser();
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007287 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007288
Andrew Leea1239f22015-03-02 17:44:07 -08007289 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007290 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7291 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007293 mApp, subId, callingPackage, callingFeatureId,
7294 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 return false;
7296 }
7297
7298 final long identity = Binder.clearCallingIdentity();
7299 try {
7300 CarrierConfigManager configManager =
7301 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007302 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
Andrew Leea1239f22015-03-02 17:44:07 -08007307 }
7308
7309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007310 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007312 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 return false;
7314 }
7315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 CarrierConfigManager configManager =
7319 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007320 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324 }
Andrew Leea1239f22015-03-02 17:44:07 -08007325 }
7326
Andrew Lee9431b832015-03-09 18:46:45 -07007327 @Override
7328 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007329 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007330 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007331 }
7332
7333 @Override
7334 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
Andrew Lee9431b832015-03-09 18:46:45 -07007341 }
7342
Hall Liuf6668912018-10-31 17:05:23 -07007343 /**
7344 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7345 * support for the feature and device firmware support.
7346 *
7347 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7348 */
7349 @Override
7350 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 final Phone phone = getPhone(subscriptionId);
7353 if (phone == null) {
7354 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7355 return false;
7356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007358 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7360 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 return isCarrierSupported && isDeviceSupported;
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
Hall Liu98187582018-01-22 19:15:32 -08007366 }
7367
Hall Liuf6668912018-10-31 17:05:23 -07007368 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007369 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7370 * RTT setting, will return true if the device and carrier both support RTT.
7371 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007372 */
7373 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 final long identity = Binder.clearCallingIdentity();
7375 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007376 boolean isRttSupported = isRttSupported(subscriptionId);
7377 boolean isUserRttSettingOn = Settings.Secure.getInt(
7378 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7379 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7380 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7381 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007385 }
7386
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 @Deprecated
7388 @Override
7389 public String getDeviceId(String callingPackage) {
7390 return getDeviceIdWithFeature(callingPackage, null);
7391 }
7392
Sanket Padawe7310cc72015-01-14 09:53:20 -08007393 /**
7394 * Returns the unique device ID of phone, for example, the IMEI for
7395 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7396 *
7397 * <p>Requires Permission:
7398 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7399 */
7400 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007401 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007402 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007403 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007404 return null;
7405 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007406 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007407 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007408 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007409 return null;
7410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
7414 return phone.getDeviceId();
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007418 }
7419
Ping Sunc67b7c22016-03-02 19:16:45 +08007420 /**
7421 * {@hide}
7422 * Returns the IMS Registration Status on a particular subid
7423 *
7424 * @param subId
7425 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007426 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007427 Phone phone = getPhone(subId);
7428 if (phone != null) {
7429 return phone.isImsRegistered();
7430 } else {
7431 return false;
7432 }
7433 }
7434
Santos Cordon7a1885b2015-02-03 11:15:19 -08007435 @Override
7436 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final long identity = Binder.clearCallingIdentity();
7438 try {
7439 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
7442 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007443 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007444
Tyler Gunnf70ed162019-04-03 15:28:53 -07007445 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007446 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007447 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007449 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007450 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7451 }
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
7454 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7455 } finally {
7456 Binder.restoreCallingIdentity(identity);
7457 }
7458 }
7459
7460 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007461 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007462 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007463 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007464 mApp,
7465 subscriptionId,
7466 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007467 final long identity = Binder.clearCallingIdentity();
7468 try {
7469 Phone phone = getPhone(subscriptionId);
7470 if (phone == null) {
7471 return null;
7472 }
7473 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7474 } finally {
7475 Binder.restoreCallingIdentity(identity);
7476 }
7477 }
7478
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007479 /**
7480 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007481 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007482 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 final long identity = Binder.clearCallingIdentity();
7484 try {
7485 Phone phone = getPhone(subId);
7486 if (phone != null) {
7487 return phone.isWifiCallingEnabled();
7488 } else {
7489 return false;
7490 }
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007493 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007494 }
7495
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007496 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007497 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007498 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007499 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 Phone phone = getPhone(subId);
7503 if (phone != null) {
7504 return phone.isVideoEnabled();
7505 } else {
7506 return false;
7507 }
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007510 }
7511 }
7512
7513 /**
7514 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7515 * defined in {@link ImsRegistrationImplBase}.
7516 */
7517 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 Phone phone = getPhone(subId);
7521 if (phone != null) {
7522 return phone.getImsRegistrationTech();
7523 } else {
7524 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7525 }
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007528 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007529 }
7530
Stuart Scott8eef64f2015-04-08 15:13:54 -07007531 @Override
7532 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007533 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007534 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7535 return;
7536 }
Kai Shif70f46f2021-03-03 13:59:46 -08007537 Phone defaultPhone = getDefaultPhone();
7538 if (defaultPhone != null) {
7539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7540 mApp, getDefaultPhone().getSubId(), "factoryReset");
7541 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007542 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543
Svet Ganovcc087f82015-05-12 20:35:54 -07007544 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007545 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7546 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007547 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007548 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007549 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007550 Phone phone = getPhone(subId);
7551 if (phone != null) {
7552 SubscriptionManager.setSubscriptionProperty(subId,
7553 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7554 "user=" + RadioAccessFamily.getRafFromNetworkType(
7555 RILConstants.PREFERRED_NETWORK_MODE));
7556 phone.loadAllowedNetworksFromSubscriptionDatabase();
7557 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007559 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007560 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007561 // There has been issues when Sms raw table somehow stores orphan
7562 // fragments. They lead to garbled message when new fragments come
7563 // in and combined with those stale ones. In case this happens again,
7564 // user can reset all network settings which will clean up this table.
7565 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007566 // Clean up IMS settings as well here.
7567 int slotId = getSlotIndex(subId);
7568 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7569 ImsManager.getInstance(mApp, slotId).factoryReset();
7570 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007571
Kai Shif70f46f2021-03-03 13:59:46 -08007572 if (defaultPhone == null) {
7573 return;
7574 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007575 // Erase modem config if erase modem on network setting is enabled.
7576 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7577 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7578 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007579 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007580 }
Kai Shif70f46f2021-03-03 13:59:46 -08007581
7582 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007583 } finally {
7584 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007585 }
7586 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007587
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007588 private void cleanUpSmsRawTable(Context context) {
7589 ContentResolver resolver = context.getContentResolver();
7590 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7591 resolver.delete(uri, null, null);
7592 }
7593
Narayan Kamath1c496c22015-04-16 14:40:19 +01007594 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007595 public String getSimLocaleForSubscriber(int subId) {
7596 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7597 final Phone phone = getPhone(subId);
7598 if (phone == null) {
7599 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007600 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 final long identity = Binder.clearCallingIdentity();
7603 try {
chen xu5d3637b2019-01-21 23:31:38 -08007604 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007605 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007606 if (info == null) {
7607 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7608 return null;
7609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 // Try and fetch the locale from the carrier properties or from the SIM language
7611 // preferences (EF-PL and EF-LI)...
7612 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007614 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7615 if (localeFromDefaultSim != null) {
7616 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7617 if (DBG) log("Using locale from subId: " + subId + " locale: "
7618 + localeFromDefaultSim);
7619 return localeFromDefaultSim.toLanguageTag();
7620 } else {
7621 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 }
7623 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 // The SIM language preferences only store a language (e.g. fr = French), not an
7626 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7627 // the SIM and carrier preferences does not include a country we add the country
7628 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007629 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007631 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 return mccLocale.toLanguageTag();
7633 }
7634
7635 if (DBG) log("No locale found - returning null");
7636 return null;
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
7639 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007640 }
7641
7642 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007643 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007644 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007645 }
7646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 /**
7648 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7649 */
7650 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007651 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007652 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007653 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007654
Chenjie Yu1ba97252018-01-11 18:16:20 -08007655 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007656 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007657
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007658 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007659 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7660 * representing the state of the modem.
7661 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007662 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7663 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007664 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007665 */
7666 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007667 public void requestModemActivityInfo(ResultReceiver result) {
7668 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670
7671 final long identity = Binder.clearCallingIdentity();
7672 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007673 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007676 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007677 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007678
Siddharth Rayb8114062018-06-17 15:02:38 -07007679 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7680 // less than total activity duration.
7681 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7682 if (info == null) {
7683 return false;
7684 }
7685 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007686 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7687 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7688
Siddharth Rayb8114062018-06-17 15:02:38 -07007689 return (info.isValid()
7690 && (info.getSleepTimeMillis() <= activityDurationMs)
7691 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007692 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007693 && (totalTxTimeMs <= activityDurationMs));
7694 }
7695
Jack Yu85bd38a2015-11-09 11:34:32 -08007696 /**
7697 * {@hide}
7698 * Returns the service state information on specified subscription.
7699 */
7700 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007701 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7702 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007705 return null;
7706 }
7707
Hall Liuf19c44f2018-11-27 14:38:17 -08007708 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7709 LocationAccessPolicy.checkLocationPermission(mApp,
7710 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7711 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007712 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007713 .setCallingPid(Binder.getCallingPid())
7714 .setCallingUid(Binder.getCallingUid())
7715 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007716 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007717 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007718 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7719 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007720 .build());
7721
7722 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7723 LocationAccessPolicy.checkLocationPermission(mApp,
7724 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7725 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007726 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007727 .setCallingPid(Binder.getCallingPid())
7728 .setCallingUid(Binder.getCallingUid())
7729 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007730 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007731 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007732 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7733 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007734 .build());
7735 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7736 boolean hasFinePermission =
7737 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7738 boolean hasCoarsePermission =
7739 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7740
Jack Yu479f40e2020-10-27 21:29:25 -07007741 final Phone phone = getPhone(subId);
7742 if (phone == null) {
7743 return null;
7744 }
7745
Jordan Liu0f2bc442020-11-18 16:47:37 -08007746 final long identity = Binder.clearCallingIdentity();
7747
Jack Yu479f40e2020-10-27 21:29:25 -07007748 boolean isCallingPackageDataService = phone.getDataServicePackages()
7749 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007751 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7752 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7753 Rlog.d(LOG_TAG,
7754 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7755 return null;
7756 }
7757
Hall Liuf19c44f2018-11-27 14:38:17 -08007758 ServiceState ss = phone.getServiceState();
7759
7760 // Scrub out the location info in ServiceState depending on what level of access
7761 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007762 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007763 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7764 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007768 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007769
7770 /**
7771 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7772 *
7773 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7774 * voicemail ringtone.
7775 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7776 * PhoneAccount.
7777 */
7778 @Override
7779 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 final long identity = Binder.clearCallingIdentity();
7781 try {
7782 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7783 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007784 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
7790 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007791 }
7792
7793 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007794 * Sets the per-account voicemail ringtone.
7795 *
7796 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7797 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7798 *
7799 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7800 * voicemail ringtone.
7801 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7802 * PhoneAccount.
7803 */
7804 @Override
7805 public void setVoicemailRingtoneUri(String callingPackage,
7806 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007807 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007809 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7810 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7812 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7813 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815
7816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7819 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007820 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 }
7822 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007825 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007826 }
7827
7828 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007829 * Returns whether vibration is set for voicemail notification in Phone settings.
7830 *
7831 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7832 * voicemail vibration setting.
7833 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7834 */
7835 @Override
7836 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7840 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007841 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7845 } finally {
7846 Binder.restoreCallingIdentity(identity);
7847 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007848 }
7849
Youhan Wange64578a2016-05-02 15:32:42 -07007850 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007851 * Sets the per-account voicemail vibration.
7852 *
7853 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7854 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7855 *
7856 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7857 * voicemail vibration setting.
7858 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7859 * specific PhoneAccount.
7860 */
7861 @Override
7862 public void setVoicemailVibrationEnabled(String callingPackage,
7863 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007864 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007865 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007866 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7867 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7869 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7870 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007871 }
7872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7876 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007877 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 }
7879 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007882 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007883 }
7884
7885 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007886 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7887 *
7888 * @throws SecurityException if the caller does not have the required permission
7889 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007890 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007891 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007892 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007893 }
7894
7895 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007896 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7897 * permission.
7898 *
7899 * @throws SecurityException if the caller does not have the required permission
7900 */
7901 private void enforceSendSmsPermission() {
7902 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7903 }
7904
7905 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007906 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007907 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007908 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007909 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007910 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007914 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 if (componentName == null) {
7916 throw new SecurityException(
7917 "Caller not current active visual voicemail package[null]");
7918 }
7919 String vvmPackage = componentName.getPackageName();
7920 if (!callingPackage.equals(vvmPackage)) {
7921 throw new SecurityException("Caller not current active visual voicemail package["
7922 + vvmPackage + "]");
7923 }
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007926 }
7927 }
7928
7929 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007930 * Return the application ID for the app type.
7931 *
7932 * @param subId the subscription ID that this request applies to.
7933 * @param appType the uicc app type.
7934 * @return Application ID for specificied app type, or null if no uicc.
7935 */
7936 @Override
7937 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007938 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007939 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940
7941 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007942 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 if (phone == null) {
7944 return null;
7945 }
7946 String aid = null;
7947 try {
7948 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7949 .getApplicationByType(appType).getAid();
7950 } catch (Exception e) {
7951 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7952 }
7953 return aid;
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007956 }
Youhan Wange64578a2016-05-02 15:32:42 -07007957 }
7958
Youhan Wang4001d252016-05-11 10:29:41 -07007959 /**
7960 * Return the Electronic Serial Number.
7961 *
7962 * @param subId the subscription ID that this request applies to.
7963 * @return ESN or null if error.
7964 */
7965 @Override
7966 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007967 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007968 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969
7970 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007971 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 if (phone == null) {
7973 return null;
7974 }
7975 String esn = null;
7976 try {
7977 esn = phone.getEsn();
7978 } catch (Exception e) {
7979 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7980 }
7981 return esn;
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007984 }
Youhan Wang4001d252016-05-11 10:29:41 -07007985 }
7986
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007987 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007988 * Return the Preferred Roaming List Version.
7989 *
7990 * @param subId the subscription ID that this request applies to.
7991 * @return PRLVersion or null if error.
7992 */
7993 @Override
7994 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007995 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007996 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997
7998 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007999 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 if (phone == null) {
8001 return null;
8002 }
8003 String cdmaPrlVersion = null;
8004 try {
8005 cdmaPrlVersion = phone.getCdmaPrlVersion();
8006 } catch (Exception e) {
8007 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8008 }
8009 return cdmaPrlVersion;
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008012 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008013 }
8014
8015 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008016 * Get snapshot of Telephony histograms
8017 * @return List of Telephony histograms
8018 * @hide
8019 */
8020 @Override
8021 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8023 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024
8025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 return RIL.getTelephonyRILTimingHistograms();
8028 } finally {
8029 Binder.restoreCallingIdentity(identity);
8030 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008031 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008032
8033 /**
8034 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008035 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8036 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008037 * Require system privileges. In the future we may add this to carrier APIs.
8038 *
Michele Berionne482f8202018-11-27 18:57:59 -08008039 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008040 */
8041 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008042 @TelephonyManager.SetCarrierRestrictionResult
8043 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008044 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008045 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008046
Michele Berionne482f8202018-11-27 18:57:59 -08008047 if (carrierRestrictionRules == null) {
8048 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008049 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008053 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008054 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 } finally {
8056 Binder.restoreCallingIdentity(identity);
8057 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008058 }
8059
8060 /**
8061 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008062 * Get the allowed carrier list and the excluded carrier list, including the priority between
8063 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008064 * Require system privileges. In the future we may add this to carrier APIs.
8065 *
Michele Berionne482f8202018-11-27 18:57:59 -08008066 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008067 */
8068 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008069 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008070 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008071 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072
8073 final long identity = Binder.clearCallingIdentity();
8074 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008075 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8076 if (response instanceof CarrierRestrictionRules) {
8077 return (CarrierRestrictionRules) response;
8078 }
8079 // Response is an Exception of some kind,
8080 // which is signalled to the user as a NULL retval
8081 return null;
8082 } catch (Exception e) {
8083 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8084 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008088 }
8089
fionaxu59545b42016-05-25 15:53:37 -07008090 /**
fionaxu59545b42016-05-25 15:53:37 -07008091 * Action set from carrier signalling broadcast receivers to enable/disable radio
8092 * @param subId the subscription ID that this action applies to.
8093 * @param enabled control enable or disable radio.
8094 * {@hide}
8095 */
8096 @Override
8097 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8098 enforceModifyPermission();
8099 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100
8101 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008102 if (phone == null) {
8103 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8104 return;
8105 }
8106 try {
8107 phone.carrierActionSetRadioEnabled(enabled);
8108 } catch (Exception e) {
8109 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 } finally {
8111 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008112 }
8113 }
8114
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008115 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008116 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8117 * network status based on which carrier apps could apply actions accordingly,
8118 * enable/disable default url handler for example.
8119 *
8120 * @param subId the subscription ID that this action applies to.
8121 * @param report control start/stop reporting the default network status.
8122 * {@hide}
8123 */
8124 @Override
8125 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8126 enforceModifyPermission();
8127 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128
8129 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008130 if (phone == null) {
8131 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8132 return;
8133 }
8134 try {
8135 phone.carrierActionReportDefaultNetworkStatus(report);
8136 } catch (Exception e) {
8137 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 } finally {
8139 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008140 }
8141 }
8142
8143 /**
fionaxud9622282017-07-17 17:51:30 -07008144 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8145 * @param subId the subscription ID that this action applies to.
8146 * {@hide}
8147 */
8148 @Override
8149 public void carrierActionResetAll(int subId) {
8150 enforceModifyPermission();
8151 final Phone phone = getPhone(subId);
8152 if (phone == null) {
8153 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8154 return;
8155 }
8156 try {
8157 phone.carrierActionResetAll();
8158 } catch (Exception e) {
8159 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8160 }
8161 }
8162
8163 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008164 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8165 * bug report is being generated.
8166 */
8167 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008168 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008169 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8170 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008171 writer.println("Permission Denial: can't dump Phone from pid="
8172 + Binder.getCallingPid()
8173 + ", uid=" + Binder.getCallingUid()
8174 + "without permission "
8175 + android.Manifest.permission.DUMP);
8176 return;
8177 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008178 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008179 }
Jack Yueb89b242016-06-22 13:27:47 -07008180
Brad Ebingerdac2f002018-04-03 15:17:52 -07008181 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008182 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8183 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8184 @NonNull String[] args) {
8185 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8186 this, in.getFileDescriptor(), out.getFileDescriptor(),
8187 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008188 }
8189
Jack Yueb89b242016-06-22 13:27:47 -07008190 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008191 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008192 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008193 * @param reason the reason the data enable change is taking place
8194 * @param enabled True if enabling the data, otherwise disabling.
8195 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008196 */
8197 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008198 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008199 boolean enabled) {
8200 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8201 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8202 try {
8203 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008204 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008205 } catch (SecurityException se) {
8206 enforceModifyPermission();
8207 }
8208 } else {
8209 enforceModifyPermission();
8210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008211
8212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 Phone phone = getPhone(subId);
8215 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008216 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8217 phone.carrierActionSetMeteredApnsEnabled(enabled);
8218 } else {
8219 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 }
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008224 }
8225 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008226
8227 /**
8228 * Get Client request stats
8229 * @return List of Client Request Stats
8230 * @hide
8231 */
8232 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008233 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8234 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008236 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008237 return null;
8238 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008239 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 if (phone != null) {
8244 return phone.getClientRequestStats();
8245 }
8246
8247 return null;
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008251 }
8252
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008253 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008254 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008255 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008256 }
Jack Yueb4124c2017-02-16 15:32:43 -08008257
8258 /**
Grace Chen70990072017-03-24 17:21:30 -07008259 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008260 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008261 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008262 * @param state State of SIM (power down, power up, pass through)
8263 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8264 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8265 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008266 *
8267 **/
8268 @Override
Grace Chen70990072017-03-24 17:21:30 -07008269 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008270 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008271 Phone phone = PhoneFactory.getPhone(slotIndex);
8272
vagdeviaf9a5b92018-08-15 16:01:53 -07008273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008278 phone.setSimPowerState(state, null, workSource);
8279 }
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
8283 }
8284
8285 /**
8286 * Set SIM card power state.
8287 *
8288 * @param slotIndex SIM slot id.
8289 * @param state State of SIM (power down, power up, pass through)
8290 * @param callback callback to trigger after success or failure
8291 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8292 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8293 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8294 *
8295 **/
8296 @Override
8297 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8298 IIntegerConsumer callback) {
8299 enforceModifyPermission();
8300 Phone phone = PhoneFactory.getPhone(slotIndex);
8301
8302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8303
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 if (phone != null) {
8307 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8308 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 }
8310 } finally {
8311 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008312 }
8313 }
Shuo Qiandd210312017-04-12 22:11:33 +00008314
Tyler Gunn65d45c22017-06-05 11:22:26 -07008315 private boolean isUssdApiAllowed(int subId) {
8316 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008317 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008318 if (configManager == null) {
8319 return false;
8320 }
8321 PersistableBundle pb = configManager.getConfigForSubId(subId);
8322 if (pb == null) {
8323 return false;
8324 }
8325 return pb.getBoolean(
8326 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8327 }
8328
Shuo Qiandd210312017-04-12 22:11:33 +00008329 /**
8330 * Check if phone is in emergency callback mode
8331 * @return true if phone is in emergency callback mode
8332 * @param subId sub id
8333 */
goneil9c5f4872017-12-05 14:07:56 -08008334 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008335 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008336 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008337 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 if (phone != null) {
8342 return phone.isInEcm();
8343 } else {
8344 return false;
8345 }
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008348 }
8349 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008350
8351 /**
8352 * Get the current signal strength information for the given subscription.
8353 * Because this information is not updated when the device is in a low power state
8354 * it should not be relied-upon to be current.
8355 * @param subId Subscription index
8356 * @return the most recent cached signal strength info from the modem
8357 */
8358 @Override
8359 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360 final long identity = Binder.clearCallingIdentity();
8361 try {
8362 Phone p = getPhone(subId);
8363 if (p == null) {
8364 return null;
8365 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 return p.getSignalStrength();
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008372
Pengquan Meng77b7f132018-08-22 14:49:57 -07008373 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008374 * Get the current modem radio state for the given slot.
8375 * @param slotIndex slot index.
8376 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008377 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008378 * @return the current radio power state from the modem
8379 */
8380 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008381 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008382 Phone phone = PhoneFactory.getPhone(slotIndex);
8383 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8385 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008386 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8387 }
8388
8389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 return phone.getRadioPowerState();
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8397 }
8398
8399 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008400 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8401 *
8402 * <p>Requires one of the following permissions:
8403 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8404 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8405 * privileges.
8406 *
8407 * @param subId subscription id
8408 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8409 * {@code false}.
8410 */
8411 @Override
8412 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008413 try {
8414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8415 null);
8416 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008417 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008418 mApp, subId, "isDataRoamingEnabled");
8419 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008420
Pengquan Menga1bb6272018-09-06 09:59:22 -07008421 boolean isEnabled = false;
8422 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008423 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008424 Phone phone = getPhone(subId);
8425 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008426 } finally {
8427 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008428 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008429 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008430 }
8431
8432
8433 /**
8434 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8435 *
8436 * <p> Requires permission:
8437 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8438 * privileges.
8439 *
8440 * @param subId subscription id
8441 * @param isEnabled {@code true} means enable, {@code false} means disable.
8442 */
8443 @Override
8444 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8446 mApp, subId, "setDataRoamingEnabled");
8447
Pengquan Menga1bb6272018-09-06 09:59:22 -07008448 final long identity = Binder.clearCallingIdentity();
8449 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008450 Phone phone = getPhone(subId);
8451 if (phone != null) {
8452 phone.setDataRoamingEnabled(isEnabled);
8453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008456 }
8457 }
8458
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008459 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008460 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008461 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008462 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008463 mApp, subId, "isManualNetworkSelectionAllowed");
8464
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008465 boolean isAllowed = true;
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008468 Phone phone = getPhone(subId);
8469 if (phone != null) {
8470 isAllowed = phone.isCspPlmnEnabled();
8471 }
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 return isAllowed;
8476 }
8477
8478 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008479 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008480 // Verify that tha callingPackage belongs to the calling UID
8481 mApp.getSystemService(AppOpsManager.class)
8482 .checkPackage(Binder.getCallingUid(), callingPackage);
8483
Jordan Liu1e142fc2019-04-22 15:10:43 -07008484 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008485 try {
8486 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008487 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008488 } catch (SecurityException e) {
8489 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8490 // has carrier privileges on an active UICC
8491 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8492 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008493 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008494 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008495 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008496
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008499 UiccController uiccController = UiccController.getInstance();
8500 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008501 if (hasReadPermission) {
8502 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008503 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008504
8505 // Remove private info if the caller doesn't have access
8506 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8507 for (UiccCardInfo cardInfo : cardInfos) {
8508 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8509 // is available
8510 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8511 if (card == null || card.getUiccProfile() == null) {
8512 // assume no access if the card or profile is unavailable
8513 filteredInfos.add(cardInfo.getUnprivileged());
8514 continue;
8515 }
8516 UiccProfile profile = card.getUiccProfile();
8517 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8518 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8519 filteredInfos.add(cardInfo);
8520 } else {
8521 filteredInfos.add(cardInfo.getUnprivileged());
8522 }
8523 }
8524 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 }
8529
8530 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008531 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008532 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8537 if (slots == null) {
8538 Rlog.i(LOG_TAG, "slots is null.");
8539 return null;
8540 }
8541
8542 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8543 for (int i = 0; i < slots.length; i++) {
8544 UiccSlot slot = slots[i];
8545 if (slot == null) {
8546 continue;
8547 }
8548
Jordan Liu7be7e652019-05-06 18:55:02 +00008549 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 UiccCard card = slot.getUiccCard();
8551 if (card != null) {
8552 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008553 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008554 cardId = slot.getEid();
8555 if (TextUtils.isEmpty(cardId)) {
8556 cardId = slot.getIccId();
8557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008558 }
8559
Jordan Liu857451f2019-05-09 16:35:35 -07008560 if (cardId != null) {
8561 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8562 // if cardId is an EID, it's all digits so this is fine
8563 cardId = IccUtils.stripTrailingFs(cardId);
8564 }
8565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 int cardState = 0;
8567 switch (slot.getCardState()) {
8568 case CARDSTATE_ABSENT:
8569 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8570 break;
8571 case CARDSTATE_PRESENT:
8572 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8573 break;
8574 case CARDSTATE_ERROR:
8575 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8576 break;
8577 case CARDSTATE_RESTRICTED:
8578 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8579 break;
8580 default:
8581 break;
8582
8583 }
8584
8585 infos[i] = new UiccSlotInfo(
8586 slot.isActive(),
8587 slot.isEuicc(),
8588 cardId,
8589 cardState,
8590 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008591 slot.isExtendedApduSupported(),
8592 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 }
8594 return infos;
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008597 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008598 }
8599
8600 @Override
8601 public boolean switchSlots(int[] physicalSlots) {
8602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008610 }
Jack Yu4c988042018-02-27 15:30:01 -08008611
8612 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008613 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 return UiccController.getInstance().getCardIdForDefaultEuicc();
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
Pengquan Meng85728fb2018-03-12 16:31:21 -07008622 /**
goneil47ffb6e2018-04-06 15:40:58 -07008623 * A test API to reload the UICC profile.
8624 *
8625 * <p>Requires that the calling app has permission
8626 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8627 * @hide
8628 */
8629 @Override
8630 public void refreshUiccProfile(int subId) {
8631 enforceModifyPermission();
8632
8633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 Phone phone = getPhone(subId);
8636 if (phone == null) {
8637 return;
8638 }
8639 UiccCard uiccCard = phone.getUiccCard();
8640 if (uiccCard == null) {
8641 return;
8642 }
8643 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8644 if (uiccProfile == null) {
8645 return;
8646 }
8647 uiccProfile.refresh();
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
8652
8653 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008654 * Returns false if the mobile data is disabled by default, otherwise return true.
8655 */
8656 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008657 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008658 }
8659
8660 /**
8661 * Returns true if the data roaming is enabled by default, i.e the system property
8662 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8663 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8664 */
8665 private boolean getDefaultDataRoamingEnabled(int subId) {
8666 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008667 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008668 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008669 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8670 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8671 return isDataRoamingEnabled;
8672 }
8673
8674 /**
8675 * Returns the default network type for the given {@code subId}, if the default network type is
8676 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8677 */
8678 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008679 List<Integer> list = TelephonyProperties.default_network();
8680 int phoneId = mSubscriptionController.getPhoneId(subId);
8681 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8682 return list.get(phoneId);
8683 }
8684 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008685 }
fionaxua13278b2018-03-21 00:08:13 -07008686
8687 @Override
8688 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008689 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008690 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
8694 final Phone phone = getPhone(subId);
8695 if (phone == null) {
8696 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8697 return;
8698 }
chen xueaba88a2019-03-15 13:15:10 -07008699 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8700 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008701 if (carrierPrivilegeRules == null) {
8702 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8703 } else {
8704 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008708 }
fionaxua13278b2018-03-21 00:08:13 -07008709 }
8710
8711 @Override
8712 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008713 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714
8715 final long identity = Binder.clearCallingIdentity();
8716 try {
8717 final Phone phone = getPhone(subId);
8718 if (phone == null) {
8719 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8720 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8721 }
8722 return phone.getCarrierIdListVersion();
8723 } finally {
8724 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008725 }
fionaxua13278b2018-03-21 00:08:13 -07008726 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008727
8728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008729 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8730 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008732 mApp, subId, callingPackage, callingFeatureId,
8733 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008734 return -1;
8735 }
8736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
8739 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8740 } finally {
8741 Binder.restoreCallingIdentity(identity);
8742 }
8743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008744
8745 @Override
8746 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008747 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008748 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008749 mApp, subId, "getCdmaRoamingMode");
8750
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
8753 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 @Override
8760 public boolean setCdmaRoamingMode(int subId, int mode) {
8761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8762 mApp, subId, "setCdmaRoamingMode");
8763
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
8766 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8767 } finally {
8768 Binder.restoreCallingIdentity(identity);
8769 }
8770 }
8771
8772 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008773 public int getCdmaSubscriptionMode(int subId) {
8774 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008775 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008776 mApp, subId, "getCdmaSubscriptionMode");
8777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
8786 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008787 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8789 mApp, subId, "setCdmaSubscriptionMode");
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
8793 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008798
sqianc5eccab2018-10-19 18:46:41 -07008799 @Override
sqian8c685422019-02-22 15:55:18 -08008800 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008801 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008803 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8804 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008805 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8806 }
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
sqian854d44b2018-12-12 16:48:18 -08008809 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8810 for (Phone phone: PhoneFactory.getPhones()) {
8811 if (phone.getEmergencyNumberTracker() != null
8812 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8813 emergencyNumberListInternal.put(
8814 phone.getSubId(),
8815 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8816 }
sqian11b7a0e2018-12-05 18:48:28 -08008817 }
sqian854d44b2018-12-12 16:48:18 -08008818 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008819 } finally {
8820 Binder.restoreCallingIdentity(identity);
8821 }
sqianc5eccab2018-10-19 18:46:41 -07008822 }
8823
8824 @Override
sqian8c685422019-02-22 15:55:18 -08008825 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008826 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008827 if (!exactMatch) {
8828 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008829 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008830 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008831 }
8832 final long identity = Binder.clearCallingIdentity();
8833 try {
sqian854d44b2018-12-12 16:48:18 -08008834 for (Phone phone: PhoneFactory.getPhones()) {
8835 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008836 && phone.getEmergencyNumberTracker()
8837 .isEmergencyNumber(number, exactMatch)) {
8838 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008839 }
sqian11b7a0e2018-12-05 18:48:28 -08008840 }
8841 return false;
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
8844 }
8845 }
8846
sqianf4ca7ed2019-01-15 18:32:07 -08008847 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008848 * Start emergency callback mode for GsmCdmaPhone for testing.
8849 */
8850 @Override
8851 public void startEmergencyCallbackMode() {
8852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8853 "startEmergencyCallbackMode");
8854 enforceModifyPermission();
8855 final long identity = Binder.clearCallingIdentity();
8856 try {
8857 for (Phone phone : PhoneFactory.getPhones()) {
8858 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8859 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8860 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8861 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8862 gsmCdmaPhone.obtainMessage(
8863 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8864 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8865 }
8866 }
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
8869 }
8870 }
8871
8872 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008873 * Update emergency number list for test mode.
8874 */
8875 @Override
8876 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8878 "updateEmergencyNumberListTestMode");
8879
8880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 for (Phone phone: PhoneFactory.getPhones()) {
8883 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8884 if (tracker != null) {
8885 tracker.executeEmergencyNumberTestModeCommand(action, num);
8886 }
8887 }
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
8893 /**
8894 * Get the full emergency number list for test mode.
8895 */
8896 @Override
8897 public List<String> getEmergencyNumberListTestMode() {
8898 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8899 "getEmergencyNumberListTestMode");
8900
8901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 Set<String> emergencyNumbers = new HashSet<>();
8904 for (Phone phone: PhoneFactory.getPhones()) {
8905 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8906 if (tracker != null) {
8907 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8908 emergencyNumbers.add(num.getNumber());
8909 }
8910 }
8911 }
8912 return new ArrayList<>(emergencyNumbers);
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
chen xud6b45bd2018-10-30 22:27:10 -07008918 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008919 public int getEmergencyNumberDbVersion(int subId) {
8920 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8921
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 final Phone phone = getPhone(subId);
8925 if (phone == null) {
8926 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8927 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8928 }
8929 return phone.getEmergencyNumberDbVersion();
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
8934
8935 @Override
8936 public void notifyOtaEmergencyNumberDbInstalled() {
8937 enforceModifyPermission();
8938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 for (Phone phone: PhoneFactory.getPhones()) {
8942 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8943 if (tracker != null) {
8944 tracker.updateOtaEmergencyNumberDatabase();
8945 }
8946 }
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
8949 }
8950 }
8951
8952 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008953 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008954 enforceActiveEmergencySessionPermission();
8955
8956 final long identity = Binder.clearCallingIdentity();
8957 try {
8958 for (Phone phone: PhoneFactory.getPhones()) {
8959 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8960 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008961 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8962 }
8963 }
8964 } finally {
8965 Binder.restoreCallingIdentity(identity);
8966 }
8967 }
8968
8969 @Override
8970 public void resetOtaEmergencyNumberDbFilePath() {
8971 enforceActiveEmergencySessionPermission();
8972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 for (Phone phone: PhoneFactory.getPhones()) {
8976 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8977 if (tracker != null) {
8978 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008979 }
8980 }
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008987 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8988 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8989 Phone phone = getPhone(subId);
8990 if (phone == null) {
8991 return null;
8992 }
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 UiccProfile profile = UiccController.getInstance()
8996 .getUiccProfileForPhone(phone.getPhoneId());
8997 if (profile != null) {
8998 return profile.getCertsFromCarrierPrivilegeAccessRules();
8999 }
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 return null;
9004 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009005
9006 /**
9007 * Enable or disable a modem stack.
9008 */
9009 @Override
9010 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9011 enforceModifyPermission();
9012
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 Phone phone = PhoneFactory.getPhone(slotIndex);
9016 if (phone == null) {
9017 return false;
9018 } else {
9019 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9020 }
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
Michelecea4cf22018-12-21 15:00:11 -08009025
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009026 /**
9027 * Whether a modem stack is enabled or not.
9028 */
9029 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9031 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009032 Phone phone = PhoneFactory.getPhone(slotIndex);
9033 if (phone == null) return false;
9034
9035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009036 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9037 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009038 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9039 }
9040
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009043 try {
9044 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9045 } catch (NoSuchElementException ex) {
9046 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9047 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
Michelecea4cf22018-12-21 15:00:11 -08009053 @Override
Michele0ea7d782019-03-19 14:58:42 -07009054 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009055 enforceModifyPermission();
9056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009060 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009061 .commit();
9062 } finally {
9063 Binder.restoreCallingIdentity(identity);
9064 }
9065 }
9066
9067 @Override
Michele0ea7d782019-03-19 14:58:42 -07009068 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009069 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009071 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9072 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009073 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009074 }
Michelecea4cf22018-12-21 15:00:11 -08009075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
Michele0ea7d782019-03-19 14:58:42 -07009078 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
9082 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009083
Michele0ea7d782019-03-19 14:58:42 -07009084 @TelephonyManager.IsMultiSimSupportedResult
9085 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009086 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9087 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9088 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009089 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9090 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009091 }
9092 // Check if the hardware supports multisim functionality. If usage of multisim is not
9093 // supported by the modem, indicate that it is restricted.
9094 PhoneCapability staticCapability =
9095 mPhoneConfigurationManager.getStaticPhoneCapability();
9096 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009097 loge("isMultiSimSupportedInternal: no static configuration available");
9098 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009099 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009100 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009101 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9102 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009103 }
9104 // Check if support of multiple SIMs is restricted by carrier
9105 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009106 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009107 }
9108
Michele0ea7d782019-03-19 14:58:42 -07009109 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009110 }
9111
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009112 /**
9113 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009114 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9115 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9116 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009117 * @param numOfSims number of active sims we want to switch to
9118 */
9119 @Override
9120 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009121 if (numOfSims == 1) {
9122 enforceModifyPermission();
9123 } else {
9124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9125 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9126 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009127 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009128
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009129 try {
Michele30b57b22019-03-01 12:01:14 -08009130 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009131 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009132 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9133 return;
9134 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009135 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9136 } finally {
9137 Binder.restoreCallingIdentity(identity);
9138 }
9139 }
9140
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009141 @Override
9142 public boolean isApplicationOnUicc(int subId, int appType) {
9143 enforceReadPrivilegedPermission("isApplicationOnUicc");
9144 Phone phone = getPhone(subId);
9145 if (phone == null) {
9146 return false;
9147 }
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
9150 UiccCard uiccCard = phone.getUiccCard();
9151 if (uiccCard == null) {
9152 return false;
9153 }
9154 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9155 if (uiccProfile == null) {
9156 return false;
9157 }
9158 if (TelephonyManager.APPTYPE_SIM <= appType
9159 && appType <= TelephonyManager.APPTYPE_ISIM) {
9160 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9161 }
9162 return false;
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
9165 }
9166 }
9167
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009168 /**
chen xub4baa772019-04-03 10:23:41 -07009169 * Get whether making changes to modem configurations will trigger reboot.
9170 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009171 */
9172 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009173 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9174 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009176 mApp, subId, callingPackage, callingFeatureId,
9177 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009178 return false;
9179 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
Nathan Harold29f5f052019-02-15 13:41:57 -08009188 private void updateModemStateMetrics() {
9189 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9190 // TODO: check the state for each modem if the api is ready.
9191 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9192 }
9193
Pengquan Meng3889a572019-01-23 11:16:29 -08009194 @Override
9195 public int[] getSlotsMapping() {
9196 enforceReadPrivilegedPermission("getSlotsMapping");
9197
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9201 // All logical slots should have a mapping to a physical slot.
9202 int[] logicalSlotsMapping = new int[phoneCount];
9203 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9204 for (int i = 0; i < slotInfos.length; i++) {
9205 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9206 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9207 }
9208 }
9209 return logicalSlotsMapping;
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009214
9215 /**
9216 * Get the IRadio HAL Version
9217 */
9218 @Override
9219 public int getRadioHalVersion() {
9220 Phone phone = getDefaultPhone();
9221 if (phone == null) return -1;
9222 HalVersion hv = phone.getHalVersion();
9223 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9224 return hv.major * 100 + hv.minor;
9225 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009226
9227 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009228 * Get the current calling package name.
9229 * @return the current calling package name
9230 */
9231 @Override
9232 public String getCurrentPackageName() {
9233 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9234 }
9235
9236 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009237 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9238 * corresponding network requests on a subId.
9239 *
9240 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009241 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009242 * 2) APN is un-metered for this subscription, or
9243 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009244 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009245 *
9246 * @return whether data is allowed for a apn type.
9247 *
9248 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009249 */
9250 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009251 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009252 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9253 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009254
9255 // Now that all security checks passes, perform the operation as ourselves.
9256 final long identity = Binder.clearCallingIdentity();
9257 try {
9258 Phone phone = getPhone(subId);
9259 if (phone == null) return false;
9260
Jack Yu41407ee2019-05-13 16:54:09 -07009261 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009262 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
9265 }
9266 }
9267
9268 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009269 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009270 enforceReadPrivilegedPermission("isApnMetered");
9271
9272 // Now that all security checks passes, perform the operation as ourselves.
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 Phone phone = getPhone(subId);
9276 if (phone == null) return true; // By default return true.
9277
Jack Yu41407ee2019-05-13 16:54:09 -07009278 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009283
9284 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009285 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9286 int subscriptionId, IBooleanConsumer resultCallback) {
9287 enforceModifyPermission();
9288 long token = Binder.clearCallingIdentity();
9289 try {
9290 Phone phone = getPhone(subscriptionId);
9291 if (phone == null) {
9292 try {
9293 if (resultCallback != null) {
9294 resultCallback.accept(false);
9295 }
9296 } catch (RemoteException e) {
9297 // ignore
9298 }
9299 return;
9300 }
9301 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9302 Pair.create(specifiers, (x) -> {
9303 try {
9304 if (resultCallback != null) {
9305 resultCallback.accept(x);
9306 }
9307 } catch (RemoteException e) {
9308 // ignore
9309 }
9310 });
9311 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9312 } finally {
9313 Binder.restoreCallingIdentity(token);
9314 }
9315 }
9316
9317 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009318 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009321 mApp, subId, "getSystemSelectionChannels");
9322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 List<RadioAccessSpecifier> specifiers =
9326 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9327 null, subId, workSource);
9328 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9329 return specifiers;
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
9335 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009336 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009337 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009338 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9339 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9340 if (iccRecords == null) {
9341 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9342 return false;
9343 }
9344 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9345 }
9346
9347 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009348 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9349 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009350 if (callingPackage == null) {
9351 callingPackage = getCurrentPackageName();
9352 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009353 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9354 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009355 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9356 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009357 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9358 }
9359 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9360 Intent intent = new Intent();
9361 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9362 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9363 // Bring up choose default SMS subscription dialog right now
9364 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9365 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9366 mApp.startActivity(intent);
9367 }
chen xud5ca2d52019-05-28 15:20:57 -07009368
9369 @Override
9370 public String getMmsUAProfUrl(int subId) {
9371 //TODO investigate if this API should require proper permission check in R b/133791609
9372 final long identity = Binder.clearCallingIdentity();
9373 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009374 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9375 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9376 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9377 return carrierUAProfUrl;
9378 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009379 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9380 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
9386 @Override
9387 public String getMmsUserAgent(int subId) {
9388 //TODO investigate if this API should require proper permission check in R b/133791609
9389 final long identity = Binder.clearCallingIdentity();
9390 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009391 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9392 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9393 if (!TextUtils.isEmpty(carrierUserAgent)) {
9394 return carrierUserAgent;
9395 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009396 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9397 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009398 } finally {
9399 Binder.restoreCallingIdentity(identity);
9400 }
9401 }
Jack Yub07d4972019-05-28 16:12:25 -07009402
9403 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009404 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9405 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009406
Jack Yub07d4972019-05-28 16:12:25 -07009407 final long identity = Binder.clearCallingIdentity();
9408 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009409 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009410 if (phone == null) return false;
9411
Hall Liua62f5da2020-09-25 10:42:19 -07009412 switch (policy) {
9413 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9414 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9415 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9416 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9417 default:
9418 throw new IllegalArgumentException(policy + " is not a valid policy");
9419 }
Jack Yub07d4972019-05-28 16:12:25 -07009420 } finally {
9421 Binder.restoreCallingIdentity(identity);
9422 }
9423 }
9424
9425 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009426 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009427 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009428 enforceModifyPermission();
9429
changbettyd5c246e2019-12-24 15:40:37 +08009430 final long identity = Binder.clearCallingIdentity();
9431 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009432 Phone phone = getPhone(subscriptionId);
9433 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009434
Hall Liua62f5da2020-09-25 10:42:19 -07009435 switch (policy) {
9436 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9437 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9438 break;
9439 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9440 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9441 break;
9442 default:
9443 throw new IllegalArgumentException(policy + " is not a valid policy");
9444 }
changbettyd5c246e2019-12-24 15:40:37 +08009445 } finally {
9446 Binder.restoreCallingIdentity(identity);
9447 }
9448 }
9449
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009450 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009451 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009452 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9453 * otherwise.
9454 */
9455 @Override
9456 public void setCepEnabled(boolean isCepEnabled) {
9457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9458
9459 final long identity = Binder.clearCallingIdentity();
9460 try {
9461 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9462 for (Phone phone : PhoneFactory.getPhones()) {
9463 Phone defaultPhone = phone.getImsPhone();
9464 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9465 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9466 ImsPhoneCallTracker imsPhoneCallTracker =
9467 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9468 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9469 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9470 + imsPhone.getMsisdn());
9471 }
9472 }
9473 } finally {
9474 Binder.restoreCallingIdentity(identity);
9475 }
9476 }
allenwtsu46dcc572020-01-08 18:24:03 +08009477
9478 /**
9479 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9480 *
9481 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9482 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9483 * before being read.
9484 */
9485 @Override
9486 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9487 isCompressed) {
9488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9489 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009490 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9491 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9492 }
9493 if (!isImsAvailableOnDevice()) {
9494 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9495 "IMS not available on device.");
9496 }
9497
9498 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009499 try {
Hui Wang761a6682020-10-31 05:12:53 +00009500 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9501 } finally {
9502 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009503 }
9504 }
zoey chene02881a2019-12-30 16:11:23 +08009505
9506 @Override
9507 public boolean isIccLockEnabled(int subId) {
9508 enforceReadPrivilegedPermission("isIccLockEnabled");
9509
9510 // Now that all security checks passes, perform the operation as ourselves.
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
9513 Phone phone = getPhone(subId);
9514 if (phone != null && phone.getIccCard() != null) {
9515 return phone.getIccCard().getIccLockEnabled();
9516 } else {
9517 return false;
9518 }
9519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
9523
9524 /**
9525 * Set the ICC pin lock enabled or disabled.
9526 *
9527 * @return an integer representing the status of IccLock enabled or disabled in the following
9528 * three cases:
9529 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9530 * successfully.
9531 * - Positive number and zero for remaining password attempts.
9532 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9533 *
9534 */
9535 @Override
9536 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9537 enforceModifyPermission();
9538
9539 Phone phone = getPhone(subId);
9540 if (phone == null) {
9541 return 0;
9542 }
9543 // Now that all security checks passes, perform the operation as ourselves.
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9547 new Pair<Boolean, String>(enabled, password), phone, null);
9548 return attemptsRemaining;
9549
9550 } catch (Exception e) {
9551 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 return 0;
9556 }
9557
9558 /**
9559 * Change the ICC password used in ICC pin lock.
9560 *
9561 * @return an integer representing the status of IccLock changed in the following three cases:
9562 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9563 * - Positive number and zero for remaining password attempts.
9564 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9565 *
9566 */
9567 @Override
9568 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9569 enforceModifyPermission();
9570
9571 Phone phone = getPhone(subId);
9572 if (phone == null) {
9573 return 0;
9574 }
9575 // Now that all security checks passes, perform the operation as ourselves.
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9579 new Pair<String, String>(oldPassword, newPassword), phone, null);
9580 return attemptsRemaining;
9581
9582 } catch (Exception e) {
9583 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 return 0;
9588 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009589
9590 /**
9591 * Request for receiving user activity notification
9592 */
9593 @Override
9594 public void requestUserActivityNotification() {
9595 if (!mNotifyUserActivity.get()
9596 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9597 mNotifyUserActivity.set(true);
9598 }
9599 }
9600
9601 /**
9602 * Called when userActivity is signalled in the power manager.
9603 * This is safe to call from any thread, with any window manager locks held or not.
9604 */
9605 @Override
9606 public void userActivity() {
9607 // ***************************************
9608 // * Inherited from PhoneWindowManager *
9609 // ***************************************
9610 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9611 // WITH ITS LOCKS HELD.
9612 //
9613 // This code must be VERY careful about the locks
9614 // it acquires.
9615 // In fact, the current code acquires way too many,
9616 // and probably has lurking deadlocks.
9617
9618 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9619 throw new SecurityException("Only the OS may call notifyUserActivity()");
9620 }
9621
9622 if (mNotifyUserActivity.getAndSet(false)) {
9623 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9624 USER_ACTIVITY_NOTIFICATION_DELAY);
9625 }
9626 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009627
9628 @Override
9629 public boolean canConnectTo5GInDsdsMode() {
9630 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9631 }
Jack Yud10cdd42020-09-28 20:28:01 -07009632
9633 @Override
9634 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9635 String callingFeatureId) {
9636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9637 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9638 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9639 }
9640
9641 Phone phone = getPhone(subId);
9642 if (phone == null) {
9643 throw new RuntimeException("phone is not available");
9644 }
9645 // Now that all security checks passes, perform the operation as ourselves.
9646 final long identity = Binder.clearCallingIdentity();
9647 try {
9648 return phone.getEquivalentHomePlmns();
9649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
9652 }
Daniel Bright59e67312020-11-13 11:49:37 -08009653
9654 @Override
9655 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009656 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9657 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009658 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009659 if (radioInterfaceCapabilities == null) {
9660 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009661 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009662 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009663 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009664
Hui Wang641e81c2020-10-12 12:14:23 -07009665 @Override
9666 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9667 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009668 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9669 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9670 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9671 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9672 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009673 if (DBG) {
9674 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9675 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9676 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9677 }
9678
9679 if (!SubscriptionManager.isValidSubscriptionId(subId)
9680 || appType < TelephonyManager.APPTYPE_UNKNOWN
9681 || appType > TelephonyManager.APPTYPE_ISIM
9682 || nafUrl == null || securityProtocol == null || callback == null) {
9683 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9684 if (callback != null) {
9685 try {
9686 callback.onAuthenticationFailure(
9687 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9688 } catch (RemoteException exception) {
9689 log("Fail to notify onAuthenticationFailure due to " + exception);
9690 }
9691 return;
9692 }
9693 }
9694
9695 final long token = Binder.clearCallingIdentity();
9696 try {
9697 getGbaManager(subId).bootstrapAuthenticationRequest(
9698 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9699 forceBootStrapping, callback));
9700 } finally {
9701 Binder.restoreCallingIdentity(token);
9702 }
9703 }
9704
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009705 /**
9706 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9707 * requested radio power state will actually be set. See {@link
9708 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9709 *
9710 * @param subId the subscription ID of the phone requesting to set the radio power state.
9711 * @param enable {@code true} if trying to turn radio on.
9712 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9713 * false}.
9714 */
9715 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9716 Phone phone = getPhone(subId);
9717 if (phone != null) {
9718 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9719 return true;
9720 }
9721 return false;
9722 }
9723
9724 private int handleDataThrottlingRequest(int subId,
9725 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009726 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9727 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9728 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9729 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9730 throw new IllegalArgumentException("modem does not support data throttling");
9731 }
9732
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009733 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9734 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9735 if (!setRadioPowerForThermal(subId, true)) {
9736 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9737 }
9738
9739 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9740
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009741 if (isDataThrottlingSupported) {
9742 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009743 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009744 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9745 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9746 } else if (thermalMitigationResult
9747 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9748 throw new IllegalArgumentException("modem does not support data throttling");
9749 }
9750 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009751 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009752
9753 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009754 }
9755
Jack Nudelman644b91a2021-03-12 14:09:48 -08009756 private static List<String> getThermalMitigationAllowlist(Context context) {
9757 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9758 for (String pckg : context.getResources()
9759 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9760 sThermalMitigationAllowlistedPackages.add(pckg);
9761 }
9762 }
9763
9764 return sThermalMitigationAllowlistedPackages;
9765 }
9766
9767 /**
9768 * Used by shell commands to add an authorized package name for thermal mitigation.
9769 * @param packageName name of package to be allowlisted
9770 * @param context
9771 */
9772 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9773 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9774 sThermalMitigationAllowlistedPackages.add(packageName);
9775 }
9776
9777 /**
9778 * Used by shell commands to remove an authorized package name for thermal mitigation.
9779 * @param packageName name of package to remove from allowlist
9780 * @param context
9781 */
9782 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9783 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9784 sThermalMitigationAllowlistedPackages.remove(packageName);
9785 }
9786
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009787 /**
9788 * Thermal mitigation request to control functionalities at modem.
9789 *
9790 * @param subId the id of the subscription.
9791 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009792 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009793 *
9794 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9795 */
9796 @Override
9797 @ThermalMitigationResult
9798 public int sendThermalMitigationRequest(
9799 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009800 ThermalMitigationRequest thermalMitigationRequest,
9801 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009802 enforceModifyPermission();
9803
Jack Nudelman644b91a2021-03-12 14:09:48 -08009804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9805 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9806 .contains(callingPackage)) {
9807 throw new SecurityException("Calling package must be configured in the device config. "
9808 + "calling package: " + callingPackage);
9809 }
9810
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9812 final long identity = Binder.clearCallingIdentity();
9813
9814 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9815 try {
9816 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9817 switch (thermalMitigationAction) {
9818 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9819 thermalMitigationResult =
9820 handleDataThrottlingRequest(subId,
9821 thermalMitigationRequest.getDataThrottlingRequest());
9822 break;
9823 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9824 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9825 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9826 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9827 }
9828
9829 // Ensure that radio is on. If not able to power on due to phone being
9830 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9831 if (!setRadioPowerForThermal(subId, true)) {
9832 thermalMitigationResult =
9833 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9834 break;
9835 }
9836
9837 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9838 false);
9839 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9840 break;
9841 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9842 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9843 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9844 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9845 }
9846
9847 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9848 if (registry != null) {
9849 TelephonyConnectionService service =
9850 registry.getTelephonyConnectionService();
9851 Phone phone = getPhone(subId);
9852 if (phone == null) {
9853 thermalMitigationResult =
9854 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9855 break;
9856 }
9857
9858 if (PhoneConstantConversions.convertCallState(phone.getState())
9859 != TelephonyManager.CALL_STATE_IDLE
9860 || phone.isInEmergencySmsMode() || phone.isInEcm()
9861 || (service != null && service.isEmergencyCallPending())) {
9862 String errorMessage = "Phone state is not valid. call state = "
9863 + PhoneConstantConversions.convertCallState(phone.getState())
9864 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9865 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9866 errorMessage += service == null
9867 ? " TelephonyConnectionService is null"
9868 : " isEmergencyCallPending = "
9869 + service.isEmergencyCallPending();
9870 Log.e(LOG_TAG, errorMessage);
9871 thermalMitigationResult =
9872 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9873 break;
9874 }
9875 } else {
9876 thermalMitigationResult =
9877 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9878 break;
9879 }
9880
9881 // Turn radio off. If not able to power off due to phone being unavailable,
9882 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9883 if (!setRadioPowerForThermal(subId, false)) {
9884 thermalMitigationResult =
9885 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9886 break;
9887 }
9888 thermalMitigationResult =
9889 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9890 break;
9891 default:
9892 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9893 + "not exist. Requested action: " + thermalMitigationAction);
9894 }
9895 } catch (IllegalArgumentException e) {
9896 throw e;
9897 } catch (Exception e) {
9898 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9899 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9900 } finally {
9901 Binder.restoreCallingIdentity(identity);
9902 }
9903
9904 if (DBG) {
9905 log("thermalMitigationRequest returning with thermalMitigationResult: "
9906 + thermalMitigationResult);
9907 }
9908
9909 return thermalMitigationResult;
9910 }
Hui Wang641e81c2020-10-12 12:14:23 -07009911
9912 /**
9913 * Set the GbaService Package Name that Telephony will bind to.
9914 *
9915 * @param subId The sim that the GbaService is associated with.
9916 * @param packageName The name of the package to be replaced with.
9917 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9918 */
9919 @Override
9920 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9921 enforceModifyPermission();
9922
9923 final long identity = Binder.clearCallingIdentity();
9924 try {
9925 return getGbaManager(subId).overrideServicePackage(packageName);
9926 } finally {
9927 Binder.restoreCallingIdentity(identity);
9928 }
9929 }
9930
9931 /**
9932 * Return the package name of the currently bound GbaService.
9933 *
9934 * @param subId The sim that the GbaService is associated with.
9935 * @return the package name of the GbaService configuration, null if GBA is not supported.
9936 */
9937 @Override
9938 public String getBoundGbaService(int subId) {
9939 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9940
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 return getGbaManager(subId).getServicePackage();
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
9949 /**
9950 * Set the release time for telephony to unbind GbaService.
9951 *
9952 * @param subId The sim that the GbaService is associated with.
9953 * @param interval The release time to unbind GbaService by millisecond.
9954 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9955 */
9956 @Override
9957 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9958 enforceModifyPermission();
9959
9960 final long identity = Binder.clearCallingIdentity();
9961 try {
9962 return getGbaManager(subId).overrideReleaseTime(interval);
9963 } finally {
9964 Binder.restoreCallingIdentity(identity);
9965 }
9966 }
9967
9968 /**
9969 * Return the release time for telephony to unbind GbaService.
9970 *
9971 * @param subId The sim that the GbaService is associated with.
9972 * @return The release time to unbind GbaService by millisecond.
9973 */
9974 @Override
9975 public int getGbaReleaseTime(int subId) {
9976 enforceReadPrivilegedPermission("getGbaReleaseTime");
9977
9978 final long identity = Binder.clearCallingIdentity();
9979 try {
9980 return getGbaManager(subId).getReleaseTime();
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
9986 private GbaManager getGbaManager(int subId) {
9987 GbaManager instance = GbaManager.getInstance(subId);
9988 if (instance == null) {
9989 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9990 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9991 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9992 }
9993 return instance;
9994 }
Hui Wang761a6682020-10-31 05:12:53 +00009995
9996 /**
9997 * indicate whether the device and the carrier can support
9998 * RCS VoLTE single registration.
9999 */
10000 @Override
10001 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010002 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10003 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10004 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10005 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010006
10007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10009 }
10010
10011 final long identity = Binder.clearCallingIdentity();
10012 try {
10013 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10014 if (rpm != null) {
10015 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
10016 }
10017 return false;
10018 } finally {
10019 Binder.restoreCallingIdentity(identity);
10020 }
10021 }
10022
10023 /**
10024 * Register RCS provisioning callback.
10025 */
10026 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010027 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010028 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010029 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010030 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010031 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10032 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010033
10034 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10035 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10036 }
10037 if (!isImsAvailableOnDevice()) {
10038 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10039 "IMS not available on device.");
10040 }
10041
10042 final long identity = Binder.clearCallingIdentity();
10043 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010044 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010045 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -080010046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10047 "Service not available for the subscription.");
10048 }
Hui Wang761a6682020-10-31 05:12:53 +000010049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
10052 }
10053
10054 /**
10055 * Unregister RCS provisioning callback.
10056 */
10057 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010058 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010059 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010060 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010061 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010062 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10063 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010064
10065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10066 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10067 }
10068 if (!isImsAvailableOnDevice()) {
10069 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10070 "IMS not available on device.");
10071 }
10072
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010075 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010076 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
10081
10082 /**
10083 * trigger RCS reconfiguration.
10084 */
10085 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010086 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10087 "triggerRcsReconfiguration",
10088 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010089
10090 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10091 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10092 }
10093 if (!isImsAvailableOnDevice()) {
10094 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10095 "IMS not available on device.");
10096 }
10097
10098 final long identity = Binder.clearCallingIdentity();
10099 try {
10100 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 }
10105
10106 /**
10107 * Provide the client configuration parameters of the RCS application.
10108 */
10109 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010110 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10111 "setRcsClientConfiguration",
10112 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010113
10114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10116 }
10117 if (!isImsAvailableOnDevice()) {
10118 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10119 "IMS not available on device.");
10120 }
10121
10122 final long identity = Binder.clearCallingIdentity();
10123
10124 try {
10125 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10126 if (configBinder == null) {
10127 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10128 } else {
10129 configBinder.setRcsClientConfiguration(rcc);
10130 }
10131 } catch (RemoteException e) {
10132 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10133 } finally {
10134 Binder.restoreCallingIdentity(identity);
10135 }
10136 }
10137
10138 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010139 * Enables or disables the test mode for RCS VoLTE single registration.
10140 */
10141 @Override
10142 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10144 "setRcsSingleRegistrationTestModeEnabled");
10145
10146 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10147 }
10148
10149 /**
10150 * Gets the test mode for RCS VoLTE single registration.
10151 */
10152 @Override
10153 public boolean getRcsSingleRegistrationTestModeEnabled() {
10154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10155 "getRcsSingleRegistrationTestModeEnabled");
10156
10157 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10158 }
10159
10160 /**
Hui Wang761a6682020-10-31 05:12:53 +000010161 * Overrides the config of RCS VoLTE single registration enabled for the device.
10162 */
10163 @Override
10164 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10166 "setDeviceSingleRegistrationEnabledOverride");
10167 enforceModifyPermission();
10168
10169 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10170 : Boolean.parseBoolean(enabledStr);
10171 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010172 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010173 }
10174
10175 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010176 * Sends a device to device communication message. Only usable via shell.
10177 * @param message message to send.
10178 * @param value message value.
10179 */
10180 @Override
10181 public void sendDeviceToDeviceMessage(int message, int value) {
10182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010183 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010184 enforceModifyPermission();
10185
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
10188 TelephonyConnectionService service =
10189 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10190 if (service == null) {
10191 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10192 return;
10193 }
10194 service.sendTestDeviceToDeviceMessage(message, value);
10195 } finally {
10196 Binder.restoreCallingIdentity(identity);
10197 }
10198 }
10199
Tyler Gunnbabbda02021-02-10 11:05:02 -080010200 /**
10201 * Sets the specified device to device transport active.
10202 * @param transport The transport to set active.
10203 */
10204 @Override
10205 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10206 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10207 "setActiveDeviceToDeviceTransport");
10208 enforceModifyPermission();
10209
10210 final long identity = Binder.clearCallingIdentity();
10211 try {
10212 TelephonyConnectionService service =
10213 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10214 if (service == null) {
10215 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10216 return;
10217 }
10218 service.setActiveDeviceToDeviceTransport(transport);
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
Tyler Gunn92479152021-01-20 16:30:10 -080010223
10224 /**
Hui Wang761a6682020-10-31 05:12:53 +000010225 * Gets the config of RCS VoLTE single registration enabled for the device.
10226 */
10227 @Override
10228 public boolean getDeviceSingleRegistrationEnabled() {
10229 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10230 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10231 }
10232
10233 /**
10234 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10235 */
10236 @Override
10237 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10238 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10239 "setCarrierSingleRegistrationEnabledOverride");
10240 enforceModifyPermission();
10241
10242 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10243 : Boolean.parseBoolean(enabledStr);
10244 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10245 subId, enabled);
10246 }
10247
10248 /**
10249 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10250 */
10251 @Override
10252 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10253 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10254 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10255 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010256
10257 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010258 * Overrides the ims feature validation result
10259 */
10260 @Override
10261 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10263 "setImsFeatureValidationOverride");
10264
10265 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10266 : Boolean.parseBoolean(enabledStr);
10267 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10268 subId, enabled);
10269 }
10270
10271 /**
10272 * Gets the ims feature validation override value
10273 */
10274 @Override
10275 public boolean getImsFeatureValidationOverride(int subId) {
10276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10277 "getImsFeatureValidationOverride");
10278 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10279 }
10280
10281 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010282 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10283 * their mobile plan.
10284 */
10285 @Override
10286 public String getMobileProvisioningUrl() {
10287 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10288 final long identity = Binder.clearCallingIdentity();
10289 try {
10290 return getDefaultPhone().getMobileProvisioningUrl();
10291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010295
James.cf Linbcdf8b32021-01-14 16:44:13 +080010296 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010297 * Get the EAB contact from the EAB database.
10298 */
10299 @Override
10300 public String getContactFromEab(String contact) {
10301 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10302 enforceModifyPermission();
10303 final long identity = Binder.clearCallingIdentity();
10304 try {
10305 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
10309 }
10310
10311 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010312 * Remove the EAB contacts from the EAB database.
10313 */
10314 @Override
10315 public int removeContactFromEab(int subId, String contacts) {
10316 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10317 enforceModifyPermission();
10318 final long identity = Binder.clearCallingIdentity();
10319 try {
10320 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010326 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010327 public boolean getDeviceUceEnabled() {
10328 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 return mApp.getDeviceUceEnabled();
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 @Override
10338 public void setDeviceUceEnabled(boolean isEnabled) {
10339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10340 final long identity = Binder.clearCallingIdentity();
10341 try {
10342 mApp.setDeviceUceEnabled(isEnabled);
10343 } finally {
10344 Binder.restoreCallingIdentity(identity);
10345 }
10346 }
10347
Brad Ebinger14d467f2021-02-12 06:18:28 +000010348 /**
10349 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10350 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10351 */
10352 // Used for SHELL command only right now.
10353 @Override
10354 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10355 List<String> featureTags) {
10356 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10357 "addUceRegistrationOverrideShell");
10358 final long identity = Binder.clearCallingIdentity();
10359 try {
10360 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10361 new ArraySet<>(featureTags));
10362 } catch (ImsException e) {
10363 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
10368
10369 /**
10370 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10371 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10372 */
10373 // Used for SHELL command only right now.
10374 @Override
10375 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10376 List<String> featureTags) {
10377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10378 "removeUceRegistrationOverrideShell");
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10382 new ArraySet<>(featureTags));
10383 } catch (ImsException e) {
10384 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10385 } finally {
10386 Binder.restoreCallingIdentity(identity);
10387 }
10388 }
10389
10390 /**
10391 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10392 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10393 */
10394 // Used for SHELL command only right now.
10395 @Override
10396 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10398 "clearUceRegistrationOverrideShell");
10399 final long identity = Binder.clearCallingIdentity();
10400 try {
10401 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10402 } catch (ImsException e) {
10403 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10404 } finally {
10405 Binder.restoreCallingIdentity(identity);
10406 }
10407 }
10408
10409 /**
10410 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10411 */
10412 // Used for SHELL command only right now.
10413 @Override
10414 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10415 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10416 "getLatestRcsContactUceCapabilityShell");
10417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10420 } catch (ImsException e) {
10421 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10422 } finally {
10423 Binder.restoreCallingIdentity(identity);
10424 }
10425 }
10426
10427 /**
10428 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10429 * device does not have an active PUBLISH.
10430 */
10431 // Used for SHELL command only right now.
10432 @Override
10433 public String getLastUcePidfXmlShell(int subId) {
10434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10438 } catch (ImsException e) {
10439 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10440 } finally {
10441 Binder.restoreCallingIdentity(identity);
10442 }
10443 }
10444
10445
James.cf Lin4b784aa2021-01-31 03:25:15 +080010446 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010447 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10448 String callingPackage) {
10449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10450 mApp, subId, "setSignalStrengthUpdateRequest");
10451
10452 final int callingUid = Binder.getCallingUid();
10453 // Verify that tha callingPackage belongs to the calling UID
10454 mApp.getSystemService(AppOpsManager.class)
10455 .checkPackage(callingUid, callingPackage);
10456
10457 validateSignalStrengthUpdateRequest(request, callingUid);
10458
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10462 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10463
10464 if (result instanceof IllegalStateException) {
10465 throw (IllegalStateException) result;
10466 }
10467 } finally {
10468 Binder.restoreCallingIdentity(identity);
10469 }
10470 }
10471
10472 @Override
10473 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10474 String callingPackage) {
10475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10476 mApp, subId, "clearSignalStrengthUpdateRequest");
10477
10478 final int callingUid = Binder.getCallingUid();
10479 // Verify that tha callingPackage belongs to the calling UID
10480 mApp.getSystemService(AppOpsManager.class)
10481 .checkPackage(callingUid, callingPackage);
10482
10483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10486 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10487
10488 if (result instanceof IllegalStateException) {
10489 throw (IllegalStateException) result;
10490 }
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10497 int callingUid) {
10498 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10499 // phone/system process do not have further restriction on request
10500 return;
10501 }
10502
10503 // Applications has restrictions on how to use the request:
10504 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10505 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10506 // This is not system caller which has been checked above
10507 throw new IllegalArgumentException(
10508 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10509 }
10510
10511 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10512 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10513 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10514 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10515 || info.isEnabled()) {
10516 throw new IllegalArgumentException(
10517 "Only system can set hide fields in SignalThresholdInfo");
10518 }
10519
10520 // Thresholds length for each RAN need in range. This has been validated in
10521 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10522 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10523 final int[] thresholds = info.getThresholds();
10524 Objects.requireNonNull(thresholds);
10525 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10526 || thresholds.length
10527 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10528 throw new IllegalArgumentException(
10529 "thresholds length is out of range: " + thresholds.length);
10530 }
10531 }
10532 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010533
10534 /**
10535 * Gets the current phone capability.
10536 *
10537 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10538 * @return the PhoneCapability which describes the data connection capability of modem.
10539 * It's used to evaluate possible phone config change, for example from single
10540 * SIM device to multi-SIM device.
10541 */
10542 @Override
10543 public PhoneCapability getPhoneCapability() {
10544 enforceReadPrivilegedPermission("getPhoneCapability");
10545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10548 } finally {
10549 Binder.restoreCallingIdentity(identity);
10550 }
10551 }
Michele Berionne5e411512020-11-13 02:36:59 +000010552
10553 /**
10554 * Prepare TelephonyManager for an unattended reboot. The reboot is
10555 * required to be done shortly after the API is invoked.
10556 */
10557 @Override
10558 @TelephonyManager.PrepareUnattendedRebootResult
10559 public int prepareForUnattendedReboot() {
10560 enforceRebootPermission();
10561
10562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10565 } finally {
10566 Binder.restoreCallingIdentity(identity);
10567 }
10568 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010569
10570 /**
10571 * Request to get the current slicing configuration including URSP rules and
10572 * NSSAIs (configured, allowed and rejected).
10573 *
10574 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10575 */
10576 @Override
10577 public void getSlicingConfig(ResultReceiver callback) {
10578 enforceReadPrivilegedPermission("getSlicingConfig");
10579
10580 final long identity = Binder.clearCallingIdentity();
10581 try {
10582 Phone phone = getDefaultPhone();
10583 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10584 } finally {
10585 Binder.restoreCallingIdentity(identity);
10586 }
10587 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010588}