blob: 23390cfb0b8c6f66714ca7ce734e46c9d50bea14 [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;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070080import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800113import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800114import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700118import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800120import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800121import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700122import android.telephony.gba.GbaAuthRequest;
123import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700124import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000127import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700128import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000129import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700132import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700136import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700187import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700195import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196import com.android.internal.telephony.uicc.IccIoResult;
197import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800198import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700199import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000202import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800203import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000204import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800205import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700206import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700207import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800208import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800209import com.android.phone.callcomposer.CallComposerPictureManager;
210import com.android.phone.callcomposer.CallComposerPictureTransfer;
211import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700212import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700213import com.android.phone.slicestore.SliceStore;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700214import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800215import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700216import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700217import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800218import com.android.services.telephony.TelecomAccountRegistry;
219import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800220import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800221
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700223import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.io.IOException;
225import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700226import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000229import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800230import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800231import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800232import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800233import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100234import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700236import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800237import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800238import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700239import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800241import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800242import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
244/**
245 * Implementation of the ITelephony interface.
246 */
Santos Cordon117fee72014-05-16 17:56:12 -0700247public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 private static final String LOG_TAG = "PhoneInterfaceManager";
249 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
250 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800251 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253 // Message codes used with mMainThreadHandler
254 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700255 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
256 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700257 private static final int CMD_OPEN_CHANNEL = 9;
258 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
259 private static final int CMD_CLOSE_CHANNEL = 11;
260 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800261 private static final int CMD_NV_READ_ITEM = 13;
262 private static final int EVENT_NV_READ_ITEM_DONE = 14;
263 private static final int CMD_NV_WRITE_ITEM = 15;
264 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
265 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
266 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700267 private static final int CMD_RESET_MODEM_CONFIG = 19;
268 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800269 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
270 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800271 private static final int CMD_SEND_ENVELOPE = 25;
272 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000273 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
274 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700275 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
276 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
277 private static final int CMD_EXCHANGE_SIM_IO = 31;
278 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
280 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700281 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700283 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
284 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700285 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
286 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
287 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
288 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700289 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
290 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
291 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
292 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700293 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800294 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
295 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000296 private static final int CMD_SWITCH_SLOTS = 50;
297 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700298 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
299 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
300 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
301 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
302 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
303 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
304 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
305 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700306 private static final int CMD_GET_ALL_CELL_INFO = 60;
307 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
308 private static final int CMD_GET_CELL_LOCATION = 62;
309 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700310 private static final int CMD_MODEM_REBOOT = 64;
311 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700312 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
313 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800314 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
315 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700316 private static final int CMD_GET_MODEM_STATUS = 70;
317 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700318 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
319 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700320 private static final int CMD_ERASE_MODEM_CONFIG = 74;
321 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800322 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
323 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
324 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
325 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800326 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
327 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800328 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800329 private static final int CMD_GET_CALL_FORWARDING = 83;
330 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
331 private static final int CMD_SET_CALL_FORWARDING = 85;
332 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
333 private static final int CMD_GET_CALL_WAITING = 87;
334 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
335 private static final int CMD_SET_CALL_WAITING = 89;
336 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700337 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
338 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
339 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
340 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700341 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
342 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800343 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
344 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800345 private static final int CMD_SET_DATA_THROTTLING = 99;
346 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800347 private static final int CMD_SET_SIM_POWER = 101;
348 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800349 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
350 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
351 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
352 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800353 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
354 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000355 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800356 private static final int CMD_GET_SLICING_CONFIG = 110;
357 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800358 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700359 private static final int CMD_ENABLE_VONR = 113;
360 private static final int EVENT_ENABLE_VONR_DONE = 114;
361 private static final int CMD_IS_VONR_ENABLED = 115;
362 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700363 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
364 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800366 // Parameters of select command.
367 private static final int SELECT_COMMAND = 0xA4;
368 private static final int SELECT_P1 = 0x04;
369 private static final int SELECT_P2 = 0;
370 private static final int SELECT_P3 = 0x10;
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /** The singleton instance. */
373 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800374 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375
Wink Saville3ab207e2014-11-20 13:07:20 -0800376 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800378 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700379 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700381 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800383 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800384 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700385 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800386 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387
Peter Wangdafb9ac2020-01-15 14:13:38 -0800388 /** User Activity */
389 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800390 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
391
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700392 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
393
Derek Tan97ebb422014-09-05 16:55:38 -0700394 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
395 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800396 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800397 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700398
Michelecea4cf22018-12-21 15:00:11 -0800399 // String to store multi SIM allowed
400 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
401
Derek Tan740e1672017-06-27 14:56:27 -0700402 // The AID of ISD-R.
403 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
404
yinxub1bed742017-04-17 11:45:04 -0700405 private NetworkScanRequestTracker mNetworkScanRequestTracker;
406
David Kelly5e06a7f2018-03-12 14:10:59 +0000407 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
408 private static final int MANUFACTURER_CODE_LENGTH = 8;
409
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800410 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800411 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800412
Sarah Chin2ec39f62022-08-31 17:03:26 -0700413 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
414 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
415
Derek Tan89e89d42014-07-08 17:00:10 -0700416 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700417 * Experiment flag to enable erase modem config on reset network, default value is false
418 */
419 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
420 "reset_network_erase_modem_config_enabled";
421
Rambo Wang0f050d82021-02-12 11:43:36 -0800422 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800423
sandeepjsb6c87872021-09-27 15:34:44 +0000424 /**
425 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
426 * one ICCID active at the same time.
427 * Apps should use below API signatures if targeting SDK is T and beyond.
428 *
429 * @hide
430 */
431 @ChangeId
432 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
433 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800434
Naina Nallurid63128d2019-09-17 14:10:30 -0700435 /**
Chen Xu540470b2021-12-14 17:15:47 -0800436 * Apps targeting on Android T and beyond will get exception whenever icc close channel
437 * operation fails.
438 */
439 @ChangeId
440 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
441 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
442
443 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 * A request object to use for transmitting data to an ICC.
445 */
446 private static final class IccAPDUArgument {
447 public int channel, cla, command, p1, p2, p3;
448 public String data;
449
450 public IccAPDUArgument(int channel, int cla, int command,
451 int p1, int p2, int p3, String data) {
452 this.channel = channel;
453 this.cla = cla;
454 this.command = command;
455 this.p1 = p1;
456 this.p2 = p2;
457 this.p3 = p3;
458 this.data = data;
459 }
460 }
461
462 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700463 * A request object to use for transmitting data to an ICC.
464 */
465 private static final class ManualNetworkSelectionArgument {
466 public OperatorInfo operatorInfo;
467 public boolean persistSelection;
468
469 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
470 this.operatorInfo = operatorInfo;
471 this.persistSelection = persistSelection;
472 }
473 }
474
Sarah Chin71b3a852022-09-28 15:54:19 -0700475 private static final class PurchasePremiumCapabilityArgument {
476 public @TelephonyManager.PremiumCapability int capability;
477 public @NonNull String appName;
478 public @NonNull IIntegerConsumer callback;
479
480 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
481 @NonNull String appName, @NonNull IIntegerConsumer callback) {
482 this.capability = capability;
483 this.appName = appName;
484 this.callback = callback;
485 }
486 }
487
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700488 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
490 * request after sending. The main thread will notify the request when it is complete.
491 */
492 private static final class MainThreadRequest {
493 /** The argument to use for the request */
494 public Object argument;
495 /** The result of the request that is run on the main thread */
496 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800497 // The subscriber id that this request applies to. Defaults to
498 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
499 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500
Nathan Harold92bed182018-10-12 18:16:49 -0700501 // In cases where subId is unavailable, the caller needs to specify the phone.
502 public Phone phone;
503
vagdeviaf9a5b92018-08-15 16:01:53 -0700504 public WorkSource workSource;
505
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506 public MainThreadRequest(Object argument) {
507 this.argument = argument;
508 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800509
Nathan Harold92bed182018-10-12 18:16:49 -0700510 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
511 this.argument = argument;
512 if (phone != null) {
513 this.phone = phone;
514 }
515 this.workSource = workSource;
516 }
517
vagdeviaf9a5b92018-08-15 16:01:53 -0700518 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800519 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800520 if (subId != null) {
521 this.subId = subId;
522 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700523 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 }
526
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800527 private static final class IncomingThirdPartyCallArgs {
528 public final ComponentName component;
529 public final String callId;
530 public final String callerDisplayName;
531
532 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
533 String callerDisplayName) {
534 this.component = component;
535 this.callId = callId;
536 this.callerDisplayName = callerDisplayName;
537 }
538 }
539
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 /**
541 * A handler that processes messages on the main thread in the phone process. Since many
542 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
543 * inbound binder threads to the main thread in the phone process. The Binder thread
544 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
545 * on, which will be notified when the operation completes and will contain the result of the
546 * request.
547 *
548 * <p>If a MainThreadRequest object is provided in the msg.obj field,
549 * note that request.result must be set to something non-null for the calling thread to
550 * unblock.
551 */
552 private final class MainThreadHandler extends Handler {
553 @Override
554 public void handleMessage(Message msg) {
555 MainThreadRequest request;
556 Message onCompleted;
557 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000558 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800560 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700561
562 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 case CMD_HANDLE_USSD_REQUEST: {
564 request = (MainThreadRequest) msg.obj;
565 final Phone phone = getPhoneFromRequest(request);
566 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800567 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700568 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700569
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 if (!isUssdApiAllowed(request.subId)) {
571 // Carrier does not support use of this API, return failure.
572 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
573 UssdResponse response = new UssdResponse(ussdRequest, null);
574 Bundle returnData = new Bundle();
575 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
576 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700577
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 request.result = true;
579 notifyRequester(request);
580 return;
581 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700582
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 try {
584 request.result = phone != null
585 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
586 } catch (CallStateException cse) {
587 request.result = false;
588 }
589 // Wake up the requesting thread
590 notifyRequester(request);
591 break;
pkanwar32d516d2016-10-14 19:37:38 -0700592 }
593
Yorke Lee716f67e2015-06-17 15:39:16 -0700594 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700595 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700596 final Phone phone = getPhoneFromRequest(request);
597 request.result = phone != null ?
598 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
599 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700600 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700601 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000608 uiccPort = getUiccPortFromRequest(request);
609 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700610 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800611 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700613 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800615 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000616 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800617 iccArgument.channel, iccArgument.cla, iccArgument.command,
618 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
619 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700620 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 ar = (AsyncResult) msg.obj;
625 request = (MainThreadRequest) ar.userObj;
626 if (ar.exception == null && ar.result != null) {
627 request.result = ar.result;
628 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800629 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 if (ar.result == null) {
631 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800632 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800634 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 } else {
636 loge("iccTransmitApduLogicalChannel: Unknown exception");
637 }
638 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700639 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
643 request = (MainThreadRequest) msg.obj;
644 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000645 uiccPort = getUiccPortFromRequest(request);
646 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800648 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 } else {
651 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800652 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000653 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800654 iccArgument.cla, iccArgument.command, iccArgument.p1,
655 iccArgument.p2,
656 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700657 }
658 break;
659
660 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result;
665 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800666 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 if (ar.result == null) {
668 loge("iccTransmitApduBasicChannel: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("iccTransmitApduBasicChannel: CommandException: " +
671 ar.exception);
672 } else {
673 loge("iccTransmitApduBasicChannel: Unknown exception");
674 }
675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 break;
678
679 case CMD_EXCHANGE_SIM_IO:
680 request = (MainThreadRequest) msg.obj;
681 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000682 uiccPort = getUiccPortFromRequest(request);
683 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 } else {
688 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
689 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000690 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
692 iccArgument.data, onCompleted);
693 }
694 break;
695
696 case EVENT_EXCHANGE_SIM_IO_DONE:
697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
699 if (ar.exception == null && ar.result != null) {
700 request.result = ar.result;
701 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800702 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700704 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 break;
706
Derek Tan4d5e5c12014-02-04 11:54:58 -0800707 case CMD_SEND_ENVELOPE:
708 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000709 uiccPort = getUiccPortFromRequest(request);
710 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800712 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700714 } else {
715 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800716 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700717 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 break;
719
720 case EVENT_SEND_ENVELOPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800725 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800726 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700727 if (ar.result == null) {
728 loge("sendEnvelopeWithStatus: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("sendEnvelopeWithStatus: CommandException: " +
731 ar.exception);
732 } else {
733 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
734 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 break;
738
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 case CMD_OPEN_CHANNEL:
740 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000741 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800742 IccLogicalChannelRequest openChannelRequest =
743 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000744 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800746 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800747 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700748 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 } else {
750 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800751 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
752 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_OPEN_CHANNEL_DONE:
757 ar = (AsyncResult) msg.obj;
758 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700759 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 int[] result = (int[]) ar.result;
762 int channelId = result[0];
763 byte[] selectResponse = null;
764 if (result.length > 1) {
765 selectResponse = new byte[result.length - 1];
766 for (int i = 1; i < result.length; ++i) {
767 selectResponse[i - 1] = (byte) result[i];
768 }
769 }
770 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800771 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800772
773 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700774 if (uiccPort == null) {
775 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
776 } else {
777 IccLogicalChannelRequest channelRequest =
778 (IccLogicalChannelRequest) request.argument;
779 channelRequest.channel = channelId;
780 uiccPort.onLogicalChannelOpened(channelRequest);
781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 if (ar.result == null) {
784 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700786 if (ar.exception != null) {
787 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
788 }
789
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700790 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700791 if (ar.exception instanceof CommandException) {
792 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800793 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700794 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700795 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700796 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700797 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700798 }
799 }
800 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800801 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700803 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700805 break;
806
807 case CMD_CLOSE_CHANNEL:
808 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000809 uiccPort = getUiccPortFromRequest(request);
810 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700811 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800812 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800813 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800814 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700815 } else {
816 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000817 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700819 break;
820
821 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null) {
825 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800826 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700827 if (uiccPort == null) {
828 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
829 } else {
830 final int channelId = (Integer) request.argument;
831 uiccPort.onLogicalChannelClosed(channelId);
832 }
Chen Xu540470b2021-12-14 17:15:47 -0800833 } else {
834 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800835 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800836 if (ar.exception instanceof CommandException) {
837 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
838 CommandException.Error error =
839 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800840 if (error == CommandException.Error.INVALID_ARGUMENTS) {
841 // should only throw exceptions from the binder threads.
842 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800843 "iccCloseLogicalChannel: invalid argument ");
844 }
845 } else {
846 loge("iccCloseLogicalChannel: Unknown exception");
847 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800848 request.result = (exception != null) ? exception :
849 new IllegalStateException(
850 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800851 }
852 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800853 break;
854
855 case CMD_NV_READ_ITEM:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800858 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
859 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800860 break;
861
862 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800865 if (ar.exception == null && ar.result != null) {
866 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700867 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800868 request.result = "";
869 if (ar.result == null) {
870 loge("nvReadItem: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("nvReadItem: CommandException: " +
873 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700874 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800875 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 }
877 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700878 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700879 break;
880
Jake Hambye994d462014-02-03 13:10:13 -0800881 case CMD_NV_WRITE_ITEM:
882 request = (MainThreadRequest) msg.obj;
883 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
884 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800885 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700886 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800887 break;
888
889 case EVENT_NV_WRITE_ITEM_DONE:
890 handleNullReturnEvent(msg, "nvWriteItem");
891 break;
892
893 case CMD_NV_WRITE_CDMA_PRL:
894 request = (MainThreadRequest) msg.obj;
895 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800896 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800897 break;
898
899 case EVENT_NV_WRITE_CDMA_PRL_DONE:
900 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
901 break;
902
chen xu6dac5ab2018-10-26 17:39:23 -0700903 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800904 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700905 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800907 break;
908
chen xu6dac5ab2018-10-26 17:39:23 -0700909 case EVENT_RESET_MODEM_CONFIG_DONE:
910 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800911 break;
912
Sooraj Sasindran37444802020-08-11 10:40:43 -0700913 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
916 request);
917 Phone phone = getPhoneFromRequest(request);
918 if (phone != null) {
919 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
920 } else {
921 loge("isNRDualConnectivityEnabled: No phone object");
922 request.result = false;
923 notifyRequester(request);
924 }
925 break;
926 }
927
928 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result;
933 } else {
934 // request.result must be set to something non-null
935 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700936 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700937 request.result = ar.result;
938 } else {
939 request.result = false;
940 }
941 if (ar.result == null) {
942 loge("isNRDualConnectivityEnabled: Empty response");
943 } else if (ar.exception instanceof CommandException) {
944 loge("isNRDualConnectivityEnabled: CommandException: "
945 + ar.exception);
946 } else {
947 loge("isNRDualConnectivityEnabled: Unknown exception");
948 }
949 }
950 notifyRequester(request);
951 break;
952
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700953 case CMD_IS_VONR_ENABLED: {
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
956 request);
957 Phone phone = getPhoneFromRequest(request);
958 if (phone != null) {
959 phone.isVoNrEnabled(onCompleted, request.workSource);
960 } else {
961 loge("isVoNrEnabled: No phone object");
962 request.result = false;
963 notifyRequester(request);
964 }
965 break;
966 }
967
968 case EVENT_IS_VONR_ENABLED_DONE:
969 ar = (AsyncResult) msg.obj;
970 request = (MainThreadRequest) ar.userObj;
971 if (ar.exception == null && ar.result != null) {
972 request.result = ar.result;
973 } else {
974 // request.result must be set to something non-null
975 // for the calling thread to unblock
976 if (ar.result != null) {
977 request.result = ar.result;
978 } else {
979 request.result = false;
980 }
981 if (ar.result == null) {
982 loge("isVoNrEnabled: Empty response");
983 } else if (ar.exception instanceof CommandException) {
984 loge("isVoNrEnabled: CommandException: "
985 + ar.exception);
986 } else {
987 loge("isVoNrEnabled: Unknown exception");
988 }
989 }
990 notifyRequester(request);
991 break;
992
Sooraj Sasindran37444802020-08-11 10:40:43 -0700993 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
996 Phone phone = getPhoneFromRequest(request);
997 if (phone != null) {
998 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
999 request.workSource);
1000 } else {
1001 loge("enableNrDualConnectivity: No phone object");
1002 request.result =
1003 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1004 notifyRequester(request);
1005 }
1006 break;
1007 }
1008
1009 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception == null) {
1013 request.result =
1014 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1015 } else {
1016 request.result =
1017 TelephonyManager
1018 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1019 if (ar.exception instanceof CommandException) {
1020 CommandException.Error error =
1021 ((CommandException) (ar.exception)).getCommandError();
1022 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1023 request.result =
1024 TelephonyManager
1025 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001026 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1027 request.result =
1028 TelephonyManager
1029 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001030 }
1031 loge("enableNrDualConnectivity" + ": CommandException: "
1032 + ar.exception);
1033 } else {
1034 loge("enableNrDualConnectivity" + ": Unknown exception");
1035 }
1036 }
1037 notifyRequester(request);
1038 break;
1039 }
1040
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001041 case CMD_ENABLE_VONR: {
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1044 Phone phone = getPhoneFromRequest(request);
1045 if (phone != null) {
1046 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1047 request.workSource);
1048 } else {
1049 loge("setVoNrEnabled: No phone object");
1050 request.result =
1051 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1052 notifyRequester(request);
1053 }
1054 break;
1055 }
1056
1057 case EVENT_ENABLE_VONR_DONE: {
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
1060 if (ar.exception == null) {
1061 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1062 } else {
1063 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1068 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1069 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1070 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1071 } else {
1072 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1073 }
1074 loge("setVoNrEnabled" + ": CommandException: "
1075 + ar.exception);
1076 } else {
1077 loge("setVoNrEnabled" + ": Unknown exception");
1078 }
1079 }
1080 notifyRequester(request);
1081 break;
1082 }
1083
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1087 request);
1088 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001089 break;
1090
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001092 ar = (AsyncResult) msg.obj;
1093 request = (MainThreadRequest) ar.userObj;
1094 if (ar.exception == null && ar.result != null) {
1095 request.result = ar.result; // Integer
1096 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301097 // request.result must be set to something non-null
1098 // for the calling thread to unblock
1099 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001100 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001101 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001103 loge("getAllowedNetworkTypesBitmask: CommandException: "
1104 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001106 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 }
1108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001109 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 break;
1111
SongFerngWang3ef3e072020-12-21 16:41:52 +08001112 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001113 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1115 request);
1116 Pair<Integer, Long> reasonWithNetworkTypes =
1117 (Pair<Integer, Long>) request.argument;
1118 getPhoneFromRequest(request).setAllowedNetworkTypes(
1119 reasonWithNetworkTypes.first,
1120 reasonWithNetworkTypes.second,
1121 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001122 break;
1123
SongFerngWang3ef3e072020-12-21 16:41:52 +08001124 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1125 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001126 break;
1127
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001128 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1129 request = (MainThreadRequest)msg.obj;
1130 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001131 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001132 break;
1133
1134 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1135 ar = (AsyncResult)msg.obj;
1136 request = (MainThreadRequest)ar.userObj;
1137 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001138 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001139 break;
1140
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001141 case CMD_SET_VOICEMAIL_NUMBER:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1144 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001145 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1146 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001147 break;
1148
1149 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1150 handleNullReturnEvent(msg, "setVoicemailNumber");
1151 break;
1152
Stuart Scott54788802015-03-30 13:18:01 -07001153 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1156 request);
1157 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1158 break;
1159
1160 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1161 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1162 break;
1163
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 case CMD_PERFORM_NETWORK_SCAN:
1165 request = (MainThreadRequest) msg.obj;
1166 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1167 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1168 break;
1169
Hall Liu27d24262020-09-18 19:04:59 -07001170 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001171 request = (MainThreadRequest) msg.obj;
1172 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001173 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1174 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1175 request.argument;
1176 int callForwardingReason = args.first;
1177 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001178 break;
Hall Liu27d24262020-09-18 19:04:59 -07001179 }
1180 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001183 TelephonyManager.CallForwardingInfoCallback callback =
1184 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1185 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001186 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001187 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001188 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1189 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1190 // Service Class is a bit mask per 3gpp 27.007. Search for
1191 // any service for voice call.
1192 if ((callForwardInfo.serviceClass
1193 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001194 callForwardingInfo = new CallForwardingInfo(
1195 callForwardInfo.status
1196 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001197 callForwardInfo.reason,
1198 callForwardInfo.number,
1199 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001200 break;
1201 }
1202 }
1203 // Didn't find a call forward info for voice call.
1204 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001205 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1206 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
Hall Liu27d24262020-09-18 19:04:59 -07001208 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 } else {
1210 if (ar.result == null) {
1211 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1212 }
1213 if (ar.exception != null) {
1214 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1215 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001216 int errorCode = TelephonyManager
1217 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001218 if (ar.exception instanceof CommandException) {
1219 CommandException.Error error =
1220 ((CommandException) (ar.exception)).getCommandError();
1221 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001222 errorCode = TelephonyManager
1223 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001224 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001225 errorCode = TelephonyManager
1226 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001227 }
1228 }
Hall Liu27d24262020-09-18 19:04:59 -07001229 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001230 }
Shuo Qian4a594052020-01-23 11:59:30 -08001231 break;
Hall Liu27d24262020-09-18 19:04:59 -07001232 }
Shuo Qian4a594052020-01-23 11:59:30 -08001233
Hall Liu27d24262020-09-18 19:04:59 -07001234 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001235 request = (MainThreadRequest) msg.obj;
1236 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001237 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001238 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001239 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1240 request.argument).first;
1241 request.phone.setCallForwardingOption(
1242 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001243 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001244 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001245 callForwardingInfoToSet.getReason(),
1246 callForwardingInfoToSet.getNumber(),
1247 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1248 break;
Hall Liu27d24262020-09-18 19:04:59 -07001249 }
Shuo Qian4a594052020-01-23 11:59:30 -08001250
Hall Liu27d24262020-09-18 19:04:59 -07001251 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001252 ar = (AsyncResult) msg.obj;
1253 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001254 Consumer<Integer> callback =
1255 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1256 request.argument).second;
1257 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001258 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001259 int errorCode = TelephonyManager.CallForwardingInfoCallback
1260 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001261 if (ar.exception instanceof CommandException) {
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001265 errorCode = TelephonyManager.CallForwardingInfoCallback
1266 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001267 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001268 errorCode = TelephonyManager.CallForwardingInfoCallback
1269 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001270 }
1271 }
1272 callback.accept(errorCode);
1273 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001274 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001275 }
Shuo Qian4a594052020-01-23 11:59:30 -08001276 break;
Hall Liu27d24262020-09-18 19:04:59 -07001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278
Hall Liu27d24262020-09-18 19:04:59 -07001279 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001280 request = (MainThreadRequest) msg.obj;
1281 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1282 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1283 break;
Hall Liu27d24262020-09-18 19:04:59 -07001284 }
Shuo Qian4a594052020-01-23 11:59:30 -08001285
Hall Liu27d24262020-09-18 19:04:59 -07001286 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001289 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001290 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001291 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001292 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001293 // Service Class is a bit mask per 3gpp 27.007.
1294 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001295 if (callForwardResults.length > 1
1296 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001297 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001299 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1300 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001301 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001302 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001303 }
1304 } else {
1305 if (ar.result == null) {
1306 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1307 }
1308 if (ar.exception != null) {
1309 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1310 }
1311 if (ar.exception instanceof CommandException) {
1312 CommandException.Error error =
1313 ((CommandException) (ar.exception)).getCommandError();
1314 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001315 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001316 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1318 callWaitingStatus =
1319 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001320 }
1321 }
1322 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001323 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001324 break;
Hall Liu27d24262020-09-18 19:04:59 -07001325 }
Shuo Qian4a594052020-01-23 11:59:30 -08001326
Hall Liu27d24262020-09-18 19:04:59 -07001327 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001330 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1331 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001332 break;
Hall Liu27d24262020-09-18 19:04:59 -07001333 }
Shuo Qian4a594052020-01-23 11:59:30 -08001334
Hall Liu27d24262020-09-18 19:04:59 -07001335 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001338 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1339 Consumer<Integer> callback =
1340 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1341 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001342 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001343 if (ar.exception instanceof CommandException) {
1344 CommandException.Error error =
1345 ((CommandException) (ar.exception)).getCommandError();
1346 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1347 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001348 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1349 callback.accept(
1350 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001351 } else {
1352 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1353 }
1354 } else {
1355 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1356 }
1357 } else {
1358 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1359 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001360 }
Shuo Qian4a594052020-01-23 11:59:30 -08001361 break;
Hall Liu27d24262020-09-18 19:04:59 -07001362 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001363 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 CellNetworkScanResult cellScanResult;
1367 if (ar.exception == null && ar.result != null) {
1368 cellScanResult = new CellNetworkScanResult(
1369 CellNetworkScanResult.STATUS_SUCCESS,
1370 (List<OperatorInfo>) ar.result);
1371 } else {
1372 if (ar.result == null) {
1373 loge("getCellNetworkScanResults: Empty response");
1374 }
1375 if (ar.exception != null) {
1376 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1377 }
1378 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1379 if (ar.exception instanceof CommandException) {
1380 CommandException.Error error =
1381 ((CommandException) (ar.exception)).getCommandError();
1382 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1383 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1384 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1385 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1386 }
1387 }
1388 cellScanResult = new CellNetworkScanResult(errorCode, null);
1389 }
1390 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001392 break;
1393
1394 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1395 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001396 ManualNetworkSelectionArgument selArg =
1397 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001398 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1399 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001400 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1401 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001402 break;
1403
1404 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 if (ar.exception == null) {
1408 request.result = true;
1409 } else {
1410 request.result = false;
1411 loge("setNetworkSelectionModeManual " + ar.exception);
1412 }
1413 notifyRequester(request);
1414 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001415 break;
1416
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001417 case CMD_GET_MODEM_ACTIVITY_INFO:
1418 request = (MainThreadRequest) msg.obj;
1419 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001420 if (defaultPhone != null) {
1421 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001422 } else {
1423 ResultReceiver result = (ResultReceiver) request.argument;
1424 Bundle bundle = new Bundle();
1425 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001426 new ModemActivityInfo(0, 0, 0,
1427 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001428 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001429 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001430 break;
1431
Hall Liud0f208c2020-10-14 16:54:44 -07001432 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001435 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001436 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001437 if (mLastModemActivityInfo == null) {
1438 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1439 mLastModemActivitySpecificInfo[0] =
1440 new ActivityStatsTechSpecificInfo(
1441 0,
1442 0,
1443 new int[ModemActivityInfo.getNumTxPowerLevels()],
1444 0);
1445 mLastModemActivityInfo =
1446 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1447 }
1448
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001449 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001450 // Update the last modem activity info and the result of the request.
1451 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1452 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001453 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001454 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001455 mLastModemActivityInfo =
1456 new ModemActivityInfo(
1457 mLastModemActivityInfo.getTimestampMillis(),
1458 mLastModemActivityInfo.getSleepTimeMillis(),
1459 mLastModemActivityInfo.getIdleTimeMillis(),
1460 mLastModemActivitySpecificInfo);
1461
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001462 } else {
1463 if (ar.result == null) {
1464 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001465 error = TelephonyManager.ModemActivityInfoException
1466 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001467 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001468 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001469 error = TelephonyManager.ModemActivityInfoException
1470 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001471 } else {
1472 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001473 error = TelephonyManager.ModemActivityInfoException
1474 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 }
1476 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001477 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001478 if (mLastModemActivityInfo != null) {
1479 bundle.putParcelable(
1480 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1481 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001482 } else {
1483 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1484 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001485 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001486 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001487 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001488 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489
Meng Wang1a7c35a2016-05-05 20:56:15 -07001490 case CMD_SET_ALLOWED_CARRIERS:
1491 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001492 CarrierRestrictionRules argument =
1493 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001494 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001495 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 break;
1497
1498 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 if (ar.exception == null && ar.result != null) {
1502 request.result = ar.result;
1503 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001504 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1505 if (ar.exception instanceof CommandException) {
1506 loge("setAllowedCarriers: CommandException: " + ar.exception);
1507 CommandException.Error error =
1508 ((CommandException) (ar.exception)).getCommandError();
1509 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1510 request.result =
1511 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1512 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001513 } else {
1514 loge("setAllowedCarriers: Unknown exception");
1515 }
1516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001517 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001518 break;
1519
1520 case CMD_GET_ALLOWED_CARRIERS:
1521 request = (MainThreadRequest) msg.obj;
1522 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001523 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001524 break;
1525
1526 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1527 ar = (AsyncResult) msg.obj;
1528 request = (MainThreadRequest) ar.userObj;
1529 if (ar.exception == null && ar.result != null) {
1530 request.result = ar.result;
1531 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001532 request.result = new IllegalStateException(
1533 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001534 if (ar.result == null) {
1535 loge("getAllowedCarriers: Empty response");
1536 } else if (ar.exception instanceof CommandException) {
1537 loge("getAllowedCarriers: CommandException: " +
1538 ar.exception);
1539 } else {
1540 loge("getAllowedCarriers: Unknown exception");
1541 }
1542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001544 break;
1545
Nathan Haroldb3014052017-01-25 15:57:32 -08001546 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 if (ar.exception == null && ar.result != null) {
1550 request.result = ar.result;
1551 } else {
1552 request.result = new IllegalArgumentException(
1553 "Failed to retrieve Forbidden Plmns");
1554 if (ar.result == null) {
1555 loge("getForbiddenPlmns: Empty response");
1556 } else {
1557 loge("getForbiddenPlmns: Unknown exception");
1558 }
1559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001560 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001561 break;
1562
1563 case CMD_GET_FORBIDDEN_PLMNS:
1564 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001565 uiccPort = getUiccPortFromRequest(request);
1566 if (uiccPort == null) {
1567 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001568 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001569 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001570 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001571 break;
1572 }
1573 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001574 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001575 if (uiccApp == null) {
1576 loge("getForbiddenPlmns() no app with specified type -- "
1577 + appType);
1578 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001579 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001580 break;
1581 } else {
1582 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1583 + " specified type -- " + appType);
1584 }
1585 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1586 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1587 onCompleted);
1588 break;
1589
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001590 case CMD_SWITCH_SLOTS:
1591 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001592 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001593 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001594 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 break;
1596
1597 case EVENT_SWITCH_SLOTS_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001601 notifyRequester(request);
1602 break;
1603 case CMD_GET_NETWORK_SELECTION_MODE:
1604 request = (MainThreadRequest) msg.obj;
1605 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1606 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1607 break;
1608
1609 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1610 ar = (AsyncResult) msg.obj;
1611 request = (MainThreadRequest) ar.userObj;
1612 if (ar.exception != null) {
1613 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1614 } else {
1615 int mode = ((int[]) ar.result)[0];
1616 if (mode == 0) {
1617 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1618 } else {
1619 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1620 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001621 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001622 notifyRequester(request);
1623 break;
1624 case CMD_GET_CDMA_ROAMING_MODE:
1625 request = (MainThreadRequest) msg.obj;
1626 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1627 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1628 break;
1629 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1630 ar = (AsyncResult) msg.obj;
1631 request = (MainThreadRequest) ar.userObj;
1632 if (ar.exception != null) {
1633 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1634 } else {
1635 request.result = ((int[]) ar.result)[0];
1636 }
1637 notifyRequester(request);
1638 break;
1639 case CMD_SET_CDMA_ROAMING_MODE:
1640 request = (MainThreadRequest) msg.obj;
1641 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1642 int mode = (int) request.argument;
1643 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1644 break;
1645 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 request.result = ar.exception == null;
1649 notifyRequester(request);
1650 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001651 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1652 request = (MainThreadRequest) msg.obj;
1653 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1654 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1655 break;
1656 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 if (ar.exception != null) {
1660 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1661 } else {
1662 request.result = ((int[]) ar.result)[0];
1663 }
1664 notifyRequester(request);
1665 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001666 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1669 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001670 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1671 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001672 break;
1673 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1674 ar = (AsyncResult) msg.obj;
1675 request = (MainThreadRequest) ar.userObj;
1676 request.result = ar.exception == null;
1677 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001678 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001679 case CMD_GET_ALL_CELL_INFO:
1680 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001681 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001682 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001683 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 case EVENT_GET_ALL_CELL_INFO_DONE:
1685 ar = (AsyncResult) msg.obj;
1686 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001687 // If a timeout occurs, the response will be null
1688 request.result = (ar.exception == null && ar.result != null)
1689 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001690 synchronized (request) {
1691 request.notifyAll();
1692 }
1693 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 case CMD_REQUEST_CELL_INFO_UPDATE:
1695 request = (MainThreadRequest) msg.obj;
1696 request.phone.requestCellInfoUpdate(request.workSource,
1697 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1698 break;
1699 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1700 ar = (AsyncResult) msg.obj;
1701 request = (MainThreadRequest) ar.userObj;
1702 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1703 try {
1704 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001705 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001706 cb.onError(
1707 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1708 ar.exception.getClass().getName(),
1709 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001710 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001711 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001712 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 } else {
1714 // use the result as returned
1715 cb.onCellInfo((List<CellInfo>) ar.result);
1716 }
1717 } catch (RemoteException re) {
1718 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1719 }
1720 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001721 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001722 request = (MainThreadRequest) msg.obj;
1723 WorkSource ws = (WorkSource) request.argument;
1724 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001725 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001726 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001727 }
1728 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001729 ar = (AsyncResult) msg.obj;
1730 request = (MainThreadRequest) ar.userObj;
1731 if (ar.exception == null) {
1732 request.result = ar.result;
1733 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001734 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001735 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001736 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 }
1738
1739 synchronized (request) {
1740 request.notifyAll();
1741 }
1742 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001743 }
chen xu6dac5ab2018-10-26 17:39:23 -07001744 case CMD_MODEM_REBOOT:
1745 request = (MainThreadRequest) msg.obj;
1746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001747 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001748 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001749 case EVENT_CMD_MODEM_REBOOT_DONE:
1750 handleNullReturnEvent(msg, "rebootModem");
1751 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001752 case CMD_REQUEST_ENABLE_MODEM:
1753 request = (MainThreadRequest) msg.obj;
1754 boolean enable = (boolean) request.argument;
1755 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001756 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001757 PhoneConfigurationManager.getInstance()
1758 .enablePhone(request.phone, enable, onCompleted);
1759 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001760 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001761 ar = (AsyncResult) msg.obj;
1762 request = (MainThreadRequest) ar.userObj;
1763 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001764 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001765 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001766 if ((boolean) request.result) {
1767 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1768 updateModemStateMetrics();
1769 } else {
1770 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1771 + ar.exception);
1772 }
1773 notifyRequester(request);
1774 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001775 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001776 case CMD_GET_MODEM_STATUS:
1777 request = (MainThreadRequest) msg.obj;
1778 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1779 PhoneConfigurationManager.getInstance()
1780 .getPhoneStatusFromModem(request.phone, onCompleted);
1781 break;
1782 case EVENT_GET_MODEM_STATUS_DONE:
1783 ar = (AsyncResult) msg.obj;
1784 request = (MainThreadRequest) ar.userObj;
1785 int id = request.phone.getPhoneId();
1786 if (ar.exception == null && ar.result != null) {
1787 request.result = ar.result;
1788 //update the cache as modem status has changed
1789 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1790 (boolean) request.result);
1791 } else {
1792 // Return true if modem status cannot be retrieved. For most cases,
1793 // modem status is on. And for older version modems, GET_MODEM_STATUS
1794 // and disable modem are not supported. Modem is always on.
1795 // TODO: this should be fixed in R to support a third
1796 // status UNKNOWN b/131631629
1797 request.result = true;
1798 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1799 + ar.exception);
1800 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001801 notifyRequester(request);
1802 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001803 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1806 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1807 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1808 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1809 break;
1810 }
1811 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1812 ar = (AsyncResult) msg.obj;
1813 request = (MainThreadRequest) ar.userObj;
1814 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1815 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1816 args.second.accept(ar.exception == null);
1817 notifyRequester(request);
1818 break;
1819 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001820 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1823 Phone phone = getPhoneFromRequest(request);
1824 if (phone != null) {
1825 phone.getSystemSelectionChannels(onCompleted);
1826 } else {
1827 loge("getSystemSelectionChannels: No phone object");
1828 request.result = new ArrayList<RadioAccessSpecifier>();
1829 notifyRequester(request);
1830 }
1831 break;
1832 }
1833 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1834 ar = (AsyncResult) msg.obj;
1835 request = (MainThreadRequest) ar.userObj;
1836 if (ar.exception == null && ar.result != null) {
1837 request.result = ar.result;
1838 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001839 request.result = new IllegalStateException(
1840 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001841 if (ar.result == null) {
1842 loge("getSystemSelectionChannels: Empty response");
1843 } else {
1844 loge("getSystemSelectionChannels: Unknown exception");
1845 }
1846 }
1847 notifyRequester(request);
1848 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001849 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 if (ar.exception == null && ar.result != null) {
1853 request.result = ar.result;
1854 } else {
1855 request.result = -1;
1856 loge("Failed to set Forbidden Plmns");
1857 if (ar.result == null) {
1858 loge("setForbidenPlmns: Empty response");
1859 } else if (ar.exception != null) {
1860 loge("setForbiddenPlmns: Exception: " + ar.exception);
1861 request.result = -1;
1862 } else {
1863 loge("setForbiddenPlmns: Unknown exception");
1864 }
1865 }
1866 notifyRequester(request);
1867 break;
1868 case CMD_SET_FORBIDDEN_PLMNS:
1869 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001870 uiccPort = getUiccPortFromRequest(request);
1871 if (uiccPort == null) {
1872 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001873 request.result = -1;
1874 notifyRequester(request);
1875 break;
1876 }
1877 Pair<Integer, List<String>> setFplmnsArgs =
1878 (Pair<Integer, List<String>>) request.argument;
1879 appType = setFplmnsArgs.first;
1880 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001881 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001882 if (uiccApp == null) {
1883 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1884 request.result = -1;
1885 loge("Failed to get UICC App");
1886 notifyRequester(request);
1887 } else {
1888 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1889 ((SIMRecords) uiccApp.getIccRecords())
1890 .setForbiddenPlmns(onCompleted, fplmns);
1891 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001892 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001893 case CMD_ERASE_MODEM_CONFIG:
1894 request = (MainThreadRequest) msg.obj;
1895 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1896 defaultPhone.eraseModemConfig(onCompleted);
1897 break;
1898 case EVENT_ERASE_MODEM_CONFIG_DONE:
1899 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001900 break;
zoey chene02881a2019-12-30 16:11:23 +08001901
Kai Shif70f46f2021-03-03 13:59:46 -08001902 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1903 request = (MainThreadRequest) msg.obj;
1904 request.result = defaultPhone.eraseDataInSharedPreferences();
1905 notifyRequester(request);
1906 break;
1907
zoey chene02881a2019-12-30 16:11:23 +08001908 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1909 request = (MainThreadRequest) msg.obj;
1910 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1911 Pair<String, String> changed = (Pair<String, String>) request.argument;
1912 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1913 changed.first, changed.second, onCompleted);
1914 break;
1915 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1916 ar = (AsyncResult) msg.obj;
1917 request = (MainThreadRequest) ar.userObj;
1918 if (ar.exception == null) {
1919 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001920 // If the operation is successful, update the PIN storage
1921 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1922 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001923 UiccController.getInstance().getPinStorage()
1924 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001925 } else {
1926 request.result = msg.arg1;
1927 }
1928 notifyRequester(request);
1929 break;
1930
Michele Berionne5e411512020-11-13 02:36:59 +00001931 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001932 request = (MainThreadRequest) msg.obj;
1933 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1934 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1935 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1936 enabled.first, enabled.second, onCompleted);
1937 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001938 }
zoey chene02881a2019-12-30 16:11:23 +08001939 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1940 ar = (AsyncResult) msg.obj;
1941 request = (MainThreadRequest) ar.userObj;
1942 if (ar.exception == null) {
1943 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001944 // If the operation is successful, update the PIN storage
1945 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1946 int phoneId = getPhoneFromRequest(request).getPhoneId();
1947 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001948 UiccController.getInstance().getPinStorage()
1949 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001950 } else {
1951 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1952 }
zoey chene02881a2019-12-30 16:11:23 +08001953 } else {
1954 request.result = msg.arg1;
1955 }
Michele Berionne5e411512020-11-13 02:36:59 +00001956
1957
zoey chene02881a2019-12-30 16:11:23 +08001958 notifyRequester(request);
1959 break;
1960
Peter Wangdafb9ac2020-01-15 14:13:38 -08001961 case MSG_NOTIFY_USER_ACTIVITY:
1962 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001963 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001964 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1965 getDefaultPhone().getContext().sendBroadcastAsUser(
1966 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1967 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001968
1969 case CMD_SET_DATA_THROTTLING: {
1970 request = (MainThreadRequest) msg.obj;
1971 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1972 DataThrottlingRequest dataThrottlingRequest =
1973 (DataThrottlingRequest) request.argument;
1974 Phone phone = getPhoneFromRequest(request);
1975 if (phone != null) {
1976 phone.setDataThrottling(onCompleted,
1977 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1978 dataThrottlingRequest.getCompletionDurationMillis());
1979 } else {
1980 loge("setDataThrottling: No phone object");
1981 request.result =
1982 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1983 notifyRequester(request);
1984 }
1985
1986 break;
1987 }
1988 case EVENT_SET_DATA_THROTTLING_DONE:
1989 ar = (AsyncResult) msg.obj;
1990 request = (MainThreadRequest) ar.userObj;
1991
1992 if (ar.exception == null) {
1993 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1994 } else if (ar.exception instanceof CommandException) {
1995 loge("setDataThrottling: CommandException: " + ar.exception);
1996 CommandException.Error error =
1997 ((CommandException) (ar.exception)).getCommandError();
1998
1999 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2000 request.result = TelephonyManager
2001 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2002 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2003 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002004 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2005 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002006 } else {
2007 request.result =
2008 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2009 }
2010 } else {
2011 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2012 }
2013 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2014 notifyRequester(request);
2015 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002016
2017 case CMD_SET_SIM_POWER: {
2018 request = (MainThreadRequest) msg.obj;
2019 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2020 request = (MainThreadRequest) msg.obj;
2021 int stateToSet =
2022 ((Pair<Integer, IIntegerConsumer>)
2023 request.argument).first;
2024 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2025 break;
2026 }
2027 case EVENT_SET_SIM_POWER_DONE: {
2028 ar = (AsyncResult) msg.obj;
2029 request = (MainThreadRequest) ar.userObj;
2030 IIntegerConsumer callback =
2031 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2032 if (ar.exception != null) {
2033 loge("setSimPower exception: " + ar.exception);
2034 int errorCode = TelephonyManager.CallForwardingInfoCallback
2035 .RESULT_ERROR_UNKNOWN;
2036 if (ar.exception instanceof CommandException) {
2037 CommandException.Error error =
2038 ((CommandException) (ar.exception)).getCommandError();
2039 if (error == CommandException.Error.SIM_ERR) {
2040 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2041 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2042 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2043 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2044 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2045 } else {
2046 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2047 }
2048 }
2049 try {
2050 callback.accept(errorCode);
2051 } catch (RemoteException e) {
2052 // Ignore if the remote process is no longer available to call back.
2053 Log.w(LOG_TAG, "setSimPower: callback not available.");
2054 }
2055 } else {
2056 try {
2057 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2058 } catch (RemoteException e) {
2059 // Ignore if the remote process is no longer available to call back.
2060 Log.w(LOG_TAG, "setSimPower: callback not available.");
2061 }
2062 }
2063 break;
2064 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002065 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2066 request = (MainThreadRequest) msg.obj;
2067
2068 final Phone phone = getPhoneFromRequest(request);
2069 if (phone == null || phone.getServiceStateTracker() == null) {
2070 request.result = new IllegalStateException("Phone or SST is null");
2071 notifyRequester(request);
2072 break;
2073 }
2074
2075 Pair<Integer, SignalStrengthUpdateRequest> pair =
2076 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2077 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2078 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002079 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002080 request.subId, pair.first /*callingUid*/,
2081 pair.second /*request*/, onCompleted);
2082 break;
2083 }
2084 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2085 ar = (AsyncResult) msg.obj;
2086 request = (MainThreadRequest) ar.userObj;
2087 // request.result will be the exception of ar if present, true otherwise.
2088 // Be cautious not to leave result null which will wait() forever
2089 request.result = ar.exception != null ? ar.exception : true;
2090 notifyRequester(request);
2091 break;
2092 }
2093 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2094 request = (MainThreadRequest) msg.obj;
2095
2096 Phone phone = getPhoneFromRequest(request);
2097 if (phone == null || phone.getServiceStateTracker() == null) {
2098 request.result = new IllegalStateException("Phone or SST is null");
2099 notifyRequester(request);
2100 break;
2101 }
2102
2103 Pair<Integer, SignalStrengthUpdateRequest> pair =
2104 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2105 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2106 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002107 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002108 request.subId, pair.first /*callingUid*/,
2109 pair.second /*request*/, onCompleted);
2110 break;
2111 }
2112 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2113 ar = (AsyncResult) msg.obj;
2114 request = (MainThreadRequest) ar.userObj;
2115 request.result = ar.exception != null ? ar.exception : true;
2116 notifyRequester(request);
2117 break;
2118 }
Jordan Liu109698e2020-11-24 14:50:34 -08002119
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 case CMD_GET_SLICING_CONFIG: {
2121 request = (MainThreadRequest) msg.obj;
2122 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2123 request.phone.getSlicingConfig(onCompleted);
2124 break;
2125 }
2126 case EVENT_GET_SLICING_CONFIG_DONE: {
2127 ar = (AsyncResult) msg.obj;
2128 request = (MainThreadRequest) ar.userObj;
2129 ResultReceiver result = (ResultReceiver) request.argument;
2130
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002131 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002132 Bundle bundle = new Bundle();
2133 int resultCode = 0;
2134 if (ar.exception != null) {
2135 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2136 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002137 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002138 } else if (ar.result == null) {
2139 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002140 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002141 } else {
2142 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002143 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2144 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002145 }
2146
2147 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002148 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002149 }
2150 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2151 result.send(resultCode, bundle);
2152 notifyRequester(request);
2153 break;
2154 }
2155
Sarah Chin71b3a852022-09-28 15:54:19 -07002156 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002157 request = (MainThreadRequest) msg.obj;
2158 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002159 PurchasePremiumCapabilityArgument arg =
2160 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002161 SliceStore.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002162 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002163 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002164 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002165
Sarah Chin71b3a852022-09-28 15:54:19 -07002166 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002167 ar = (AsyncResult) msg.obj;
2168 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002169 PurchasePremiumCapabilityArgument arg =
2170 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002171 try {
2172 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002173 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002174 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 + ", result= "
2177 + TelephonyManager.convertPurchaseResultToString(result));
2178 } catch (RemoteException e) {
2179 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002180 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002181 + " failed: " + e;
2182 if (DBG) log(logStr);
2183 AnomalyReporter.reportAnomaly(
2184 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2185 }
2186 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002187 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002188
Michele Berionne5e411512020-11-13 02:36:59 +00002189 case CMD_PREPARE_UNATTENDED_REBOOT:
2190 request = (MainThreadRequest) msg.obj;
2191 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002192 UiccController.getInstance().getPinStorage()
2193 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002194 notifyRequester(request);
2195 break;
2196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 default:
2198 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2199 break;
2200 }
2201 }
Jake Hambye994d462014-02-03 13:10:13 -08002202
Pengquan Menga1bb6272018-09-06 09:59:22 -07002203 private void notifyRequester(MainThreadRequest request) {
2204 synchronized (request) {
2205 request.notifyAll();
2206 }
2207 }
2208
Jake Hambye994d462014-02-03 13:10:13 -08002209 private void handleNullReturnEvent(Message msg, String command) {
2210 AsyncResult ar = (AsyncResult) msg.obj;
2211 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2212 if (ar.exception == null) {
2213 request.result = true;
2214 } else {
2215 request.result = false;
2216 if (ar.exception instanceof CommandException) {
2217 loge(command + ": CommandException: " + ar.exception);
2218 } else {
2219 loge(command + ": Unknown exception");
2220 }
2221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002222 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 }
2225
2226 /**
2227 * Posts the specified command to be executed on the main thread,
2228 * waits for the request to complete, and returns the result.
2229 * @see #sendRequestAsync
2230 */
2231 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002232 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2233 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002234 }
2235
2236 /**
2237 * Posts the specified command to be executed on the main thread,
2238 * waits for the request to complete, and returns the result.
2239 * @see #sendRequestAsync
2240 */
2241 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2242 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002243 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002244 }
2245
2246 /**
2247 * Posts the specified command to be executed on the main thread,
2248 * waits for the request to complete, and returns the result.
2249 * @see #sendRequestAsync
2250 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002251 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002252 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2253 }
2254
2255 /**
2256 * Posts the specified command to be executed on the main thread,
2257 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2258 * if not timeout or null otherwise.
2259 * @see #sendRequestAsync
2260 */
2261 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2262 long timeoutInMs) {
2263 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002264 }
2265
2266 /**
2267 * Posts the specified command to be executed on the main thread,
2268 * waits for the request to complete, and returns the result.
2269 * @see #sendRequestAsync
2270 */
Nathan Harold92bed182018-10-12 18:16:49 -07002271 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002272 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002273 }
2274
2275 /**
2276 * Posts the specified command to be executed on the main thread,
2277 * waits for the request to complete, and returns the result.
2278 * @see #sendRequestAsync
2279 */
2280 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002281 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2282 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002283 }
2284
2285 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002286 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2287 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2288 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002289 * @see #sendRequestAsync
2290 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002291 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2292 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2294 throw new RuntimeException("This method will deadlock if called from the main thread.");
2295 }
2296
Nathan Harold92bed182018-10-12 18:16:49 -07002297 MainThreadRequest request = null;
2298 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2299 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2300 } else if (phone != null) {
2301 request = new MainThreadRequest(argument, phone, workSource);
2302 } else {
2303 request = new MainThreadRequest(argument, subId, workSource);
2304 }
2305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 Message msg = mMainThreadHandler.obtainMessage(command, request);
2307 msg.sendToTarget();
2308
Rambo Wang0f050d82021-02-12 11:43:36 -08002309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002311 if (timeoutInMs >= 0) {
2312 // Wait for at least timeoutInMs before returning null request result
2313 long now = SystemClock.elapsedRealtime();
2314 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002315 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002316 try {
2317 request.wait(deadline - now);
2318 } catch (InterruptedException e) {
2319 // Do nothing, go back and check if request is completed or timeout
2320 } finally {
2321 now = SystemClock.elapsedRealtime();
2322 }
2323 }
2324 } else {
2325 // Wait for the request to complete
2326 while (request.result == null) {
2327 try {
2328 request.wait();
2329 } catch (InterruptedException e) {
2330 // Do nothing, go back and wait until the request is complete
2331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333 }
2334 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002335 if (request.result == null) {
2336 Log.wtf(LOG_TAG,
2337 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 return request.result;
2340 }
2341
2342 /**
2343 * Asynchronous ("fire and forget") version of sendRequest():
2344 * Posts the specified command to be executed on the main thread, and
2345 * returns immediately.
2346 * @see #sendRequest
2347 */
2348 private void sendRequestAsync(int command) {
2349 mMainThreadHandler.sendEmptyMessage(command);
2350 }
2351
2352 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002353 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002354 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002355 */
2356 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002357 sendRequestAsync(command, argument, null, null);
2358 }
2359
2360 /**
2361 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2362 * @see {@link #sendRequest(int,Object)}
2363 */
2364 private void sendRequestAsync(
2365 int command, Object argument, Phone phone, WorkSource workSource) {
2366 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002367 Message msg = mMainThreadHandler.obtainMessage(command, request);
2368 msg.sendToTarget();
2369 }
2370
2371 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 * Initialize the singleton PhoneInterfaceManager instance.
2373 * This is only done once, at startup, from PhoneApp.onCreate().
2374 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002375 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 synchronized (PhoneInterfaceManager.class) {
2377 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002378 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 } else {
2380 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2381 }
2382 return sInstance;
2383 }
2384 }
2385
2386 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002387 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002390 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002391 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002393 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002395 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002396 mTelephonySharedPreferences =
2397 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002398 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002399 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002400 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002401 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002402 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 publish();
2404 }
2405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002406 private Phone getDefaultPhone() {
2407 Phone thePhone = getPhone(getDefaultSubscription());
2408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2409 }
2410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 private void publish() {
2412 if (DBG) log("publish: " + this);
2413
Peter Wangc035ce42020-01-08 21:00:22 -08002414 TelephonyFrameworkInitializer
2415 .getTelephonyServiceManager()
2416 .getTelephonyServiceRegisterer()
2417 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
Stuart Scott584921c2015-01-15 17:10:34 -08002420 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002421 if (request.phone != null) {
2422 return request.phone;
2423 } else {
2424 return getPhoneFromSubId(request.subId);
2425 }
2426 }
2427
2428 private Phone getPhoneFromSubId(int subId) {
2429 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2430 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002431 }
2432
Rambo Wange53e07d2022-05-10 13:01:13 -07002433 @Nullable
2434 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 Phone phone = getPhoneFromRequest(request);
2436 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002437 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 }
2439
Wink Saville36469e72014-06-11 15:17:00 -07002440 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002441 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002442 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002443 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444
Kai Shif70f46f2021-03-03 13:59:46 -08002445 private void sendEraseModemConfig(@NonNull Phone phone) {
2446 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2447 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2448 }
2449
2450 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2451 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2452 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002453 }
2454
Peter Wang44b186e2020-01-13 23:33:09 -08002455 private boolean isImsAvailableOnDevice() {
2456 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2457 if (pm == null) {
2458 // For some reason package manger is not available.. This will fail internally anyway,
2459 // so do not throw error and allow.
2460 return true;
2461 }
2462 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2463 }
2464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002466 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 if (DBG) log("dial: " + number);
2471 // No permission check needed here: This is just a wrapper around the
2472 // ACTION_DIAL intent, which is available to any app since it puts up
2473 // the UI before it does anything.
2474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 final long identity = Binder.clearCallingIdentity();
2476 try {
2477 String url = createTelUrl(number);
2478 if (url == null) {
2479 return;
2480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 // PENDING: should we just silently fail if phone is offhook or ringing?
2483 PhoneConstants.State state = mCM.getState(subId);
2484 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2485 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2486 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2487 mApp.startActivity(intent);
2488 }
2489 } finally {
2490 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492 }
2493
2494 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002495 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002496 }
2497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 if (DBG) log("call: " + number);
2500
2501 // This is just a wrapper around the ACTION_CALL intent, but we still
2502 // need to do a permission check since we're calling startActivity()
2503 // from the context of the phone app.
2504 enforceCallPermission();
2505
Jordan Liu1617b712019-07-10 15:06:26 -07002506 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 != AppOpsManager.MODE_ALLOWED) {
2508 return;
2509 }
2510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 String url = createTelUrl(number);
2514 if (url == null) {
2515 return;
2516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002518 boolean isValid = false;
2519 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2520 if (slist != null) {
2521 for (SubscriptionInfo subInfoRecord : slist) {
2522 if (subInfoRecord.getSubscriptionId() == subId) {
2523 isValid = true;
2524 break;
2525 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002526 }
Wink Saville08874612014-08-31 19:19:58 -07002527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528 if (!isValid) {
2529 return;
2530 }
Wink Saville08874612014-08-31 19:19:58 -07002531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2533 intent.putExtra(SUBSCRIPTION_KEY, subId);
2534 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2535 mApp.startActivity(intent);
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002542 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002543 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2544 }
2545
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2549 }
2550
Wink Savilleb564aae2014-10-23 10:18:09 -07002551 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002556 Phone phone = getPhone(subId);
2557 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 checkSimPin.start();
2559 return checkSimPin.unlockSim(null, pin);
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
2562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
2564
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002570 Phone phone = getPhone(subId);
2571 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572 checkSimPuk.start();
2573 return checkSimPuk.unlockSim(puk, pin);
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
2576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002577 }
2578
2579 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002580 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002581 * a synchronous one.
2582 */
2583 private static class UnlockSim extends Thread {
2584
2585 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002586 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587
2588 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002589 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2590 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591
2592 // For replies from SimCard interface
2593 private Handler mHandler;
2594
2595 // For async handler to identify request type
2596 private static final int SUPPLY_PIN_COMPLETE = 100;
2597
Michele Berionne5e411512020-11-13 02:36:59 +00002598 UnlockSim(int phoneId, IccCard simCard) {
2599 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 mSimCard = simCard;
2601 }
2602
2603 @Override
2604 public void run() {
2605 Looper.prepare();
2606 synchronized (UnlockSim.this) {
2607 mHandler = new Handler() {
2608 @Override
2609 public void handleMessage(Message msg) {
2610 AsyncResult ar = (AsyncResult) msg.obj;
2611 switch (msg.what) {
2612 case SUPPLY_PIN_COMPLETE:
2613 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2614 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002615 mRetryCount = msg.arg1;
2616 if (ar.exception != null) {
2617 if (ar.exception instanceof CommandException &&
2618 ((CommandException)(ar.exception)).getCommandError()
2619 == CommandException.Error.PASSWORD_INCORRECT) {
2620 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002621 } //When UiccCardApp dispose,handle message and return exception
2622 else if (ar.exception instanceof CommandException &&
2623 ((CommandException) (ar.exception)).getCommandError()
2624 == CommandException.Error.ABORTED) {
2625 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002626 } else {
2627 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2628 }
2629 } else {
2630 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002632 mDone = true;
2633 UnlockSim.this.notifyAll();
2634 }
2635 break;
2636 }
2637 }
2638 };
2639 UnlockSim.this.notifyAll();
2640 }
2641 Looper.loop();
2642 }
2643
2644 /*
2645 * Use PIN or PUK to unlock SIM card
2646 *
2647 * If PUK is null, unlock SIM card with PIN
2648 *
2649 * If PUK is not null, unlock SIM card with PUK and set PIN code
2650 */
Wink Saville9de0f752013-10-22 19:04:03 -07002651 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002652
2653 while (mHandler == null) {
2654 try {
2655 wait();
2656 } catch (InterruptedException e) {
2657 Thread.currentThread().interrupt();
2658 }
2659 }
2660 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2661
2662 if (puk == null) {
2663 mSimCard.supplyPin(pin, callback);
2664 } else {
2665 mSimCard.supplyPuk(puk, pin, callback);
2666 }
2667
2668 while (!mDone) {
2669 try {
2670 Log.d(LOG_TAG, "wait for done");
2671 wait();
2672 } catch (InterruptedException e) {
2673 // Restore the interrupted status
2674 Thread.currentThread().interrupt();
2675 }
2676 }
2677 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002678 int[] resultArray = new int[2];
2679 resultArray[0] = mResult;
2680 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002681
2682 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002683 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002684 }
2685
Wink Saville9de0f752013-10-22 19:04:03 -07002686 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688 }
2689
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002690 /**
2691 * This method has been removed due to privacy and stability concerns.
2692 */
2693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002695 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2696 return;
Wink Saville36469e72014-06-11 15:17:00 -07002697 }
2698
Nathan Harold1f889d82020-06-04 17:05:26 -07002699 @Override
2700 public void updateServiceLocationWithPackageName(String callingPackage) {
2701 mApp.getSystemService(AppOpsManager.class)
2702 .checkPackage(Binder.getCallingUid(), callingPackage);
2703
Nathan Haroldf096d982020-11-18 17:18:06 -08002704 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002705 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2706 // Callers targeting S have no business invoking this method.
2707 return;
2708 }
2709
2710 LocationAccessPolicy.LocationPermissionResult locationResult =
2711 LocationAccessPolicy.checkLocationPermission(mApp,
2712 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2713 .setCallingPackage(callingPackage)
2714 .setCallingFeatureId(null)
2715 .setCallingPid(Binder.getCallingPid())
2716 .setCallingUid(Binder.getCallingUid())
2717 .setMethod("updateServiceLocation")
2718 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2719 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2720 .build());
2721 // Apps that lack location permission have no business calling this method;
2722 // however, because no permission was declared in the public API, denials must
2723 // all be "soft".
2724 switch (locationResult) {
2725 case DENIED_HARD: /* fall through */
2726 case DENIED_SOFT:
2727 return;
2728 }
2729
2730 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002733 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002735 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 }
2737 } finally {
2738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
2741
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002742 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002743 @Override
2744 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002745 return isRadioOnWithFeature(callingPackage, null);
2746 }
2747
2748
2749 @Override
2750 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2751 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2752 callingFeatureId);
2753 }
2754
2755 @Deprecated
2756 @Override
2757 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2758 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002762 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2763 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002765 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002766 return false;
2767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768
2769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 return isRadioOnForSubscriber(subId);
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002775 }
2776
2777 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2783 } else {
2784 return false;
2785 }
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790
2791 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002792 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
Wink Saville36469e72014-06-11 15:17:00 -07002794
Wink Savilleb564aae2014-10-23 10:18:09 -07002795 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
2802 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2803 }
2804 } finally {
2805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002806 }
Wink Saville36469e72014-06-11 15:17:00 -07002807 }
2808
2809 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002810 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002811 }
2812
Wink Savilleb564aae2014-10-23 10:18:09 -07002813 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone == null) {
2820 return false;
2821 }
2822 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2823 toggleRadioOnOffForSubscriber(subId);
2824 }
2825 return true;
2826 } finally {
2827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 }
Wink Saville36469e72014-06-11 15:17:00 -07002830
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002831 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002832 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002833 /*
2834 * If any of the Radios are available, it will need to be
2835 * shutdown. So return true if any Radio is available.
2836 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2840 Phone phone = PhoneFactory.getPhone(i);
2841 if (phone != null && phone.isRadioAvailable()) return true;
2842 }
2843 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2844 return false;
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002847 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002848 }
2849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002851 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 enforceModifyPermission();
2853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2857 logv("Shutting down Phone " + i);
2858 shutdownRadioUsingPhoneId(i);
2859 }
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002862 }
2863 }
2864
2865 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002866 Phone phone = PhoneFactory.getPhone(phoneId);
2867 if (phone != null && phone.isRadioAvailable()) {
2868 phone.shutdownRadio();
2869 }
2870 }
2871
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002874
2875 final long identity = Binder.clearCallingIdentity();
2876 try {
2877 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2878 if (defaultPhone != null) {
2879 defaultPhone.setRadioPower(turnOn);
2880 return true;
2881 } else {
2882 loge("There's no default phone.");
2883 return false;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002887 }
Wink Saville36469e72014-06-11 15:17:00 -07002888 }
2889
Wink Savilleb564aae2014-10-23 10:18:09 -07002890 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892
2893 final long identity = Binder.clearCallingIdentity();
2894 try {
2895 final Phone phone = getPhone(subId);
2896 if (phone != null) {
2897 phone.setRadioPower(turnOn);
2898 return true;
2899 } else {
2900 return false;
2901 }
2902 } finally {
2903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002907 /**
2908 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2909 * no reason to power it off. When any of the voters want to power it off, it will be turned
2910 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2911 * powering it off, and these radio off votes will be cleared.
2912 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2913 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2914 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2915 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2916 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2917 * check its vote.
2918 *
2919 * @param subId The subscription ID.
2920 * @param reason The reason for powering off radio.
2921 * @return true on success and false on failure.
2922 */
2923 public boolean requestRadioPowerOffForReason(int subId,
2924 @TelephonyManager.RadioPowerReason int reason) {
2925 enforceModifyPermission();
2926
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 if (phone != null) {
2931 phone.setRadioPowerForReason(false, reason);
2932 return true;
2933 } else {
2934 return false;
2935 }
2936 } finally {
2937 Binder.restoreCallingIdentity(identity);
2938 }
2939 }
2940
2941 /**
2942 * Remove the vote on powering off the radio for a reason, as requested by
2943 * {@link requestRadioPowerOffForReason}.
2944 *
2945 * @param subId The subscription ID.
2946 * @param reason The reason for powering off radio.
2947 * @return true on success and false on failure.
2948 */
2949 public boolean clearRadioPowerOffForReason(int subId,
2950 @TelephonyManager.RadioPowerReason int reason) {
2951 enforceModifyPermission();
2952
2953 final long identity = Binder.clearCallingIdentity();
2954 try {
2955 final Phone phone = getPhone(subId);
2956 if (phone != null) {
2957 phone.setRadioPowerForReason(true, reason);
2958 return true;
2959 } else {
2960 return false;
2961 }
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
2965 }
2966
2967 /**
2968 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2969 *
2970 * @param subId The subscription ID.
2971 * @param callingPackage The package making the call.
2972 * @param callingFeatureId The feature in the package.
2973 * @return List of reasons for powering off radio.
2974 */
2975 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2976 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2977
2978 final long identity = Binder.clearCallingIdentity();
2979 List result = new ArrayList();
2980 try {
2981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2982 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2983 return result;
2984 }
2985
2986 final Phone phone = getPhone(subId);
2987 if (phone != null) {
2988 result.addAll(phone.getRadioPowerOffReasons());
2989 }
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 return result;
2994 }
2995
Wink Saville36469e72014-06-11 15:17:00 -07002996 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002997 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002998 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002999 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 int subId = mSubscriptionController.getDefaultDataSubId();
3004 final Phone phone = getPhone(subId);
3005 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003006 phone.getDataSettingsManager().setDataEnabled(
3007 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 return true;
3009 } else {
3010 return false;
3011 }
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Wink Saville36469e72014-06-11 15:17:00 -07003017 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003018 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003019 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 int subId = mSubscriptionController.getDefaultDataSubId();
3025 final Phone phone = getPhone(subId);
3026 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003027 phone.getDataSettingsManager().setDataEnabled(
3028 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 return true;
3030 } else {
3031 return false;
3032 }
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003035 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
3037
Sanket Padawe356d7632015-06-22 14:03:32 -07003038 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003039 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 final long identity = Binder.clearCallingIdentity();
3041 try {
3042 final Phone phone = getPhone(subId);
3043 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003044 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 } else {
3046 return false;
3047 }
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 }
3052
3053 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003054 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003055 }
3056
pkanwarae03a6b2016-11-06 20:37:09 -08003057 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 enforceCallPermission();
3059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3063 return;
3064 }
3065 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3066 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
pkanwar32d516d2016-10-14 19:37:38 -07003070 };
3071
Wink Savilleb564aae2014-10-23 10:18:09 -07003072 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3078 return false;
3079 }
3080 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003084 }
3085
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003086 /**
3087 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3088 * tag on getCallState Binder call.
3089 */
3090 @Deprecated
3091 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003093 if (CompatChanges.isChangeEnabled(
3094 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3095 Binder.getCallingUid())) {
3096 // Do not allow this API to be called on API version 31+, it should only be
3097 // called on old apps using this Binder call directly.
3098 throw new SecurityException("This method can only be used for applications "
3099 + "targeting API version 30 or less.");
3100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101 final long identity = Binder.clearCallingIdentity();
3102 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003103 Phone phone = getPhone(getDefaultSubscription());
3104 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3105 PhoneConstantConversions.convertCallState(phone.getState());
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
3109 }
3110
3111 @Override
3112 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3113 if (CompatChanges.isChangeEnabled(
3114 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3115 Binder.getCallingUid())) {
3116 // Check READ_PHONE_STATE for API version 31+
3117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3118 featureId, "getCallStateForSubscription")) {
3119 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3120 + "targeting API level 31+.");
3121 }
3122 }
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3127 PhoneConstantConversions.convertCallState(phone.getState());
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003131 }
3132
Sanket Padawe356d7632015-06-22 14:03:32 -07003133 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003134 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003135 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3136 }
3137
3138 @Override
3139 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 final long identity = Binder.clearCallingIdentity();
3141 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003142 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003144 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 } else {
3146 return PhoneConstantConversions.convertDataState(
3147 PhoneConstants.DataState.DISCONNECTED);
3148 }
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 }
3153
Sanket Padawe356d7632015-06-22 14:03:32 -07003154 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003155 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003156 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3157 }
3158
3159 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003160 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003163 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003165 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 } else {
3167 return TelephonyManager.DATA_ACTIVITY_NONE;
3168 }
3169 } finally {
3170 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003172 }
3173
3174 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003175 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003176 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003177 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003178
3179 LocationAccessPolicy.LocationPermissionResult locationResult =
3180 LocationAccessPolicy.checkLocationPermission(mApp,
3181 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3182 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003183 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003184 .setCallingPid(Binder.getCallingPid())
3185 .setCallingUid(Binder.getCallingUid())
3186 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003187 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003188 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3189 .build());
3190 switch (locationResult) {
3191 case DENIED_HARD:
3192 throw new SecurityException("Not allowed to access cell location");
3193 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003194 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3195 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003202 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003203 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
Svetoslav64fad262015-04-14 14:35:21 -07003207 }
3208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003210 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003211 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3212 // registered cell info, so return a NULL country instead.
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003215 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3216 // Get default phone in this case.
3217 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3218 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003219 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003221 if (phone == null) return "";
3222 ServiceStateTracker sst = phone.getServiceStateTracker();
3223 if (sst == null) return "";
3224 LocaleTracker lt = sst.getLocaleTracker();
3225 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003226 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003230 }
3231
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003232 /**
3233 * This method was removed due to potential issues caused by performing partial
3234 * updates of service state, and lack of a credible use case.
3235 *
3236 * This has the ability to break the telephony implementation by disabling notification of
3237 * changes in device connectivity. DO NOT USE THIS!
3238 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003239 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 public void enableLocationUpdates() {
3241 mApp.enforceCallingOrSelfPermission(
3242 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003243 }
3244
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003245 /**
3246 * This method was removed due to potential issues caused by performing partial
3247 * updates of service state, and lack of a credible use case.
3248 *
3249 * This has the ability to break the telephony implementation by disabling notification of
3250 * changes in device connectivity. DO NOT USE THIS!
3251 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 @Override
3253 public void disableLocationUpdates() {
3254 mApp.enforceCallingOrSelfPermission(
3255 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
3258 @Override
3259 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003260 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3261 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003262 try {
3263 mApp.getSystemService(AppOpsManager.class)
3264 .checkPackage(Binder.getCallingUid(), callingPackage);
3265 } catch (SecurityException e) {
3266 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3267 throw e;
3268 }
3269
Nathan Haroldf096d982020-11-18 17:18:06 -08003270 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003271 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3272 throw new SecurityException(
3273 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3274 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003275
Jordan Liu1617b712019-07-10 15:06:26 -07003276 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3278 return null;
3279 }
Svetoslav64fad262015-04-14 14:35:21 -07003280
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003281 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003283 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003284 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285
Nathan Haroldf180aac2018-06-01 18:43:55 -07003286 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3287 for (CellInfo ci : info) {
3288 if (ci instanceof CellInfoGsm) {
3289 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3290 } else if (ci instanceof CellInfoWcdma) {
3291 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003294 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295 }
3296
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003297 private List<CellInfo> getCachedCellInfo() {
3298 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3299 for (Phone phone : PhoneFactory.getPhones()) {
3300 List<CellInfo> info = phone.getAllCellInfo();
3301 if (info != null) cellInfos.addAll(info);
3302 }
3303 return cellInfos;
3304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003305
3306 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003307 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003308 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003309 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003310
3311 LocationAccessPolicy.LocationPermissionResult locationResult =
3312 LocationAccessPolicy.checkLocationPermission(mApp,
3313 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3314 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003315 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003316 .setCallingPid(Binder.getCallingPid())
3317 .setCallingUid(Binder.getCallingUid())
3318 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003319 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003320 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3321 .build());
3322 switch (locationResult) {
3323 case DENIED_HARD:
3324 throw new SecurityException("Not allowed to access cell info");
3325 case DENIED_SOFT:
3326 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 }
3328
Nathan Haroldf096d982020-11-18 17:18:06 -08003329 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003330 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3331 return getCachedCellInfo();
3332 }
3333
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003334 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3339 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003340 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003341 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 if (info != null) cellInfos.addAll(info);
3343 }
3344 return cellInfos;
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
3348 }
3349
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003350 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003351 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3352 String callingFeatureId) {
3353 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3354 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003355 }
3356
3357 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003358 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3359 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003361 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003362 }
3363
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003364 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3365 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003367 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003368
3369 LocationAccessPolicy.LocationPermissionResult locationResult =
3370 LocationAccessPolicy.checkLocationPermission(mApp,
3371 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3372 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003373 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003374 .setCallingPid(Binder.getCallingPid())
3375 .setCallingUid(Binder.getCallingUid())
3376 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003377 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3378 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003379 .build());
3380 switch (locationResult) {
3381 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003382 if (TelephonyPermissions
3383 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003384 // Safetynet logging for b/154934934
3385 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3386 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003387 throw new SecurityException("Not allowed to access cell info");
3388 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003389 if (TelephonyPermissions
3390 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003391 // Safetynet logging for b/154934934
3392 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3393 }
Nathan Harold5320c422019-05-09 10:26:08 -07003394 try {
3395 cb.onCellInfo(new ArrayList<CellInfo>());
3396 } catch (RemoteException re) {
3397 // Drop without consequences
3398 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003399 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003400 }
3401
Nathan Harolda939a962019-05-09 10:13:47 -07003402
3403 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003404 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3405
3406 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3407 }
3408
3409 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003410 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003411 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003412 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003416 Phone phone = getPhone(subId);
3417 if (phone == null) {
3418 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3419 } else {
3420 phone.setCellInfoListRate(rateInMillis, workSource);
3421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
Shishir Agrawala9f32182016-04-12 12:00:16 -07003427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003428 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003429 Phone phone = PhoneFactory.getPhone(slotIndex);
3430 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003431 return null;
3432 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003433 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003434 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003435 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003436 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003437 return null;
3438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 return phone.getImei();
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003446 }
3447
3448 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003449 public String getTypeAllocationCodeForSlot(int slotIndex) {
3450 Phone phone = PhoneFactory.getPhone(slotIndex);
3451 String tac = null;
3452 if (phone != null) {
3453 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003454 try {
3455 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3456 } catch (IndexOutOfBoundsException e) {
3457 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3458 return null;
3459 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003460 }
3461 return tac;
3462 }
3463
3464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003465 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003466 try {
3467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3468 } catch (SecurityException se) {
3469 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3470 throw new SecurityException("Package " + callingPackage + " does not belong to "
3471 + Binder.getCallingUid());
3472 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003473 Phone phone = PhoneFactory.getPhone(slotIndex);
3474 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003475 return null;
3476 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477
Jeff Davidson913390f2018-02-23 17:11:49 -08003478 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003479 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003480 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003481 return null;
3482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 return phone.getMeid();
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
Jack Yu2af8d712017-03-15 17:14:14 -07003490 }
3491
3492 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003493 public String getManufacturerCodeForSlot(int slotIndex) {
3494 Phone phone = PhoneFactory.getPhone(slotIndex);
3495 String manufacturerCode = null;
3496 if (phone != null) {
3497 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003498 try {
3499 manufacturerCode =
3500 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3501 } catch (IndexOutOfBoundsException e) {
3502 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3503 return null;
3504 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003505 }
3506 return manufacturerCode;
3507 }
3508
3509 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003510 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3511 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003512 Phone phone = PhoneFactory.getPhone(slotIndex);
3513 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 return null;
3515 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003516 int subId = phone.getSubId();
3517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003518 mApp, subId, callingPackage, callingFeatureId,
3519 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003520 return null;
3521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522
3523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 return phone.getDeviceSvn();
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003529 }
3530
fionaxu43304da2017-11-27 22:51:16 -08003531 @Override
3532 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = getPhone(subId);
3536 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
fionaxu43304da2017-11-27 22:51:16 -08003540 }
3541
3542 @Override
3543 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 return phone == null ? null : phone.getCarrierName();
3548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
fionaxu43304da2017-11-27 22:51:16 -08003551 }
3552
calvinpanffe225e2018-11-01 19:43:06 +08003553 @Override
chen xu0026ca62019-03-06 15:28:50 -08003554 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003559 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
chen xu0026ca62019-03-06 15:28:50 -08003566 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003570 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003571 } finally {
3572 Binder.restoreCallingIdentity(identity);
3573 }
3574 }
3575
chen xu651eec72018-11-11 19:03:44 -08003576 @Override
chen xu864e11c2018-12-06 22:10:03 -08003577 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3578 if (!isSubscriptionMccMnc) {
3579 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3580 }
chen xu651eec72018-11-11 19:03:44 -08003581 final Phone phone = PhoneFactory.getPhone(slotIndex);
3582 if (phone == null) {
3583 return TelephonyManager.UNKNOWN_CARRIER_ID;
3584 }
3585 final long identity = Binder.clearCallingIdentity();
3586 try {
3587 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
3591 }
3592
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003593 //
3594 // Internal helper methods.
3595 //
3596
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003597 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003598 * Make sure the caller is the calling package itself
3599 *
3600 * @throws SecurityException if the caller is not the calling package
3601 */
3602 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3603 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003604 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3605 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003606 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003607 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003608 } catch (PackageManager.NameNotFoundException e) {
3609 // packageUid is -1
3610 }
3611 if (packageUid != callingUid) {
3612 throw new SecurityException(message + ": Package " + callingPackage
3613 + " does not belong to " + callingUid);
3614 }
3615 }
3616
3617 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003618 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3619 *
3620 * @throws SecurityException if the caller does not have the required permission
3621 */
3622 private void enforceModifyPermission() {
3623 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3624 }
3625
Shuo Qian3b6ee772019-11-13 17:43:31 -08003626 private void enforceActiveEmergencySessionPermission() {
3627 mApp.enforceCallingOrSelfPermission(
3628 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3629 }
3630
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 /**
3632 * Make sure the caller has the CALL_PHONE permission.
3633 *
3634 * @throws SecurityException if the caller does not have the required permission
3635 */
3636 private void enforceCallPermission() {
3637 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3638 }
3639
paulhu5a773602019-08-23 19:17:33 +08003640 private void enforceSettingsPermission() {
3641 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003642 }
3643
Michele Berionne5e411512020-11-13 02:36:59 +00003644 private void enforceRebootPermission() {
3645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3646 }
3647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 private String createTelUrl(String number) {
3649 if (TextUtils.isEmpty(number)) {
3650 return null;
3651 }
3652
Jake Hambye994d462014-02-03 13:10:13 -08003653 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 }
3655
Ihab Awadf9e92732013-12-05 18:02:52 -08003656 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003657 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3658 }
3659
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003660 private static void logv(String msg) {
3661 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3662 }
3663
Ihab Awadf9e92732013-12-05 18:02:52 -08003664 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003665 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3666 }
3667
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003668 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003669 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003670 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003671 }
3672
Sanket Padawe356d7632015-06-22 14:03:32 -07003673 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003674 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 final Phone phone = PhoneFactory.getPhone(slotIndex);
3678 if (phone == null) {
3679 return PhoneConstants.PHONE_TYPE_NONE;
3680 } else {
3681 return phone.getPhoneType();
3682 }
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003686 }
3687
3688 /**
3689 * Returns the CDMA ERI icon index to display
3690 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003691 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003692 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3693 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3694 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003695 }
3696
Sanket Padawe356d7632015-06-22 14:03:32 -07003697 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003698 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3699 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003701 mApp, subId, callingPackage, callingFeatureId,
3702 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003703 return -1;
3704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 final Phone phone = getPhone(subId);
3709 if (phone != null) {
3710 return phone.getCdmaEriIconIndex();
3711 } else {
3712 return -1;
3713 }
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003717 }
3718
3719 /**
3720 * Returns the CDMA ERI icon mode,
3721 * 0 - ON
3722 * 1 - FLASHING
3723 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003725 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3726 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3727 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003728 }
3729
Sanket Padawe356d7632015-06-22 14:03:32 -07003730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003731 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3732 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003734 mApp, subId, callingPackage, callingFeatureId,
3735 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003736 return -1;
3737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 final Phone phone = getPhone(subId);
3742 if (phone != null) {
3743 return phone.getCdmaEriIconMode();
3744 } else {
3745 return -1;
3746 }
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003750 }
3751
3752 /**
3753 * Returns the CDMA ERI text,
3754 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003755 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003756 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3757 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3758 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003759 }
3760
Sanket Padawe356d7632015-06-22 14:03:32 -07003761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3763 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003765 mApp, subId, callingPackage, callingFeatureId,
3766 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003767 return null;
3768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 final Phone phone = getPhone(subId);
3773 if (phone != null) {
3774 return phone.getCdmaEriText();
3775 } else {
3776 return null;
3777 }
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003781 }
3782
3783 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003784 * Returns the CDMA MDN.
3785 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003786 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003787 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 return phone.getLine1Number();
3796 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 return null;
3799 }
3800 } finally {
3801 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003802 }
3803 }
3804
3805 /**
3806 * Returns the CDMA MIN.
3807 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003808 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003809 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3811 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812
3813 final long identity = Binder.clearCallingIdentity();
3814 try {
3815 final Phone phone = getPhone(subId);
3816 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3817 return phone.getCdmaMin();
3818 } else {
3819 return null;
3820 }
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003823 }
3824 }
3825
Hall Liud892bec2018-11-30 14:51:45 -08003826 @Override
3827 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3828 INumberVerificationCallback callback, String callingPackage) {
3829 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3830 != PERMISSION_GRANTED) {
3831 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3832 }
3833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3834
3835 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3836 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003837 throw new SecurityException("Calling package must be configured in the device config: "
3838 + "calling package: " + callingPackage
3839 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003840 }
3841
3842 if (range == null) {
3843 throw new NullPointerException("Range must be non-null");
3844 }
3845
3846 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003847 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003848
3849 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3850 }
3851
Junda Liuca05d5d2014-08-14 22:36:34 -07003852 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003853 * Returns true if CDMA provisioning needs to run.
3854 */
3855 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 final long identity = Binder.clearCallingIdentity();
3857 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003858 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003862 }
3863
3864 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003865 * Sets the voice mail number of a given subId.
3866 */
3867 @Override
3868 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003869 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3870 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871
3872 final long identity = Binder.clearCallingIdentity();
3873 try {
3874 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3875 new Pair<String, String>(alphaTag, number), new Integer(subId));
3876 return success;
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003880 }
3881
Ta-wei Yen87c49842016-05-13 21:19:52 -07003882 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003883 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003885 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3886 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003887 if (!TextUtils.equals(callingPackage, systemDialer)) {
3888 throw new SecurityException("caller must be system dialer");
3889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3894 if (phoneAccountHandle == null) {
3895 return null;
3896 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 } finally {
3899 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003900 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003901 }
3902
3903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003904 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3905 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003908 mApp, subId, callingPackage, callingFeatureId,
3909 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003910 return null;
3911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003913 final long identity = Binder.clearCallingIdentity();
3914 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003915 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003916 } finally {
3917 Binder.restoreCallingIdentity(identity);
3918 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003919 }
3920
3921 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003922 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3923 VisualVoicemailSmsFilterSettings settings) {
3924 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003929 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003933 }
3934
3935 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003936 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3937 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938
3939 final long identity = Binder.clearCallingIdentity();
3940 try {
3941 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003942 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003946 }
3947
3948 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003949 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3950 String callingPackage, int subId) {
3951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952
3953 final long identity = Binder.clearCallingIdentity();
3954 try {
3955 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003956 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003960 }
3961
3962 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003963 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965
3966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003973 }
3974
3975 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003976 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3977 String callingAttributionTag, int subId, String number, int port, String text,
3978 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003980 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003981 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003982 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003983 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3984 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003985 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003986
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003987 /**
fionaxu0152e512016-11-14 13:36:14 -08003988 * Sets the voice activation state of a given subId.
3989 */
3990 @Override
3991 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3993 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 final Phone phone = getPhone(subId);
3998 if (phone != null) {
3999 phone.setVoiceActivationState(activationState);
4000 } else {
4001 loge("setVoiceActivationState fails with invalid subId: " + subId);
4002 }
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004005 }
4006 }
4007
4008 /**
4009 * Sets the data activation state of a given subId.
4010 */
4011 @Override
4012 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4014 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015
4016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 final Phone phone = getPhone(subId);
4019 if (phone != null) {
4020 phone.setDataActivationState(activationState);
4021 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004022 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 }
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004026 }
4027 }
4028
4029 /**
4030 * Returns the voice activation state of a given subId.
4031 */
4032 @Override
4033 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035
fionaxu0152e512016-11-14 13:36:14 -08004036 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 if (phone != null) {
4040 return phone.getVoiceActivationState();
4041 } else {
4042 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4043 }
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004046 }
4047 }
4048
4049 /**
4050 * Returns the data activation state of a given subId.
4051 */
4052 @Override
4053 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055
fionaxu0152e512016-11-14 13:36:14 -08004056 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 if (phone != null) {
4060 return phone.getDataActivationState();
4061 } else {
4062 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4063 }
4064 } finally {
4065 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004066 }
4067 }
4068
4069 /**
Wink Saville36469e72014-06-11 15:17:00 -07004070 * Returns the unread count of voicemails for a subId
4071 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4074 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004076 mApp, subId, callingPackage, callingFeatureId,
4077 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004078 return 0;
4079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 final Phone phone = getPhone(subId);
4083 if (phone != null) {
4084 return phone.getVoiceMessageCount();
4085 } else {
4086 return 0;
4087 }
4088 } finally {
4089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091 }
4092
4093 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004094 * returns true, if the device is in a state where both voice and data
4095 * are supported simultaneously. This can change based on location or network condition.
4096 */
4097 @Override
4098 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 final Phone phone = getPhone(subId);
4102 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004106 }
4107
4108 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004109 * Send the dialer code if called from the current default dialer or the caller has
4110 * carrier privilege.
4111 * @param inputCode The dialer code to send
4112 */
4113 @Override
4114 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004117 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4118 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004119 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004120 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
fionaxu235cc5e2017-03-06 22:25:57 -08004130 }
4131
Pengquan Menga1bb6272018-09-06 09:59:22 -07004132 @Override
4133 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004134 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004135 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004136 mApp, subId, "getNetworkSelectionMode");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 if (!isActiveSubscription(subId)) {
4140 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4141 }
4142 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4143 } finally {
4144 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004145 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004146 }
4147
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004149 public boolean isInEmergencySmsMode() {
4150 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 for (Phone phone : PhoneFactory.getPhones()) {
4154 if (phone.isInEmergencySmsMode()) {
4155 return true;
4156 }
4157 }
4158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 return false;
4162 }
4163
shilu366312e2019-12-17 09:28:10 -08004164 /**
4165 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4166 * @param subId The subscription to use to check the configuration.
4167 * @param c The callback that will be used to send the result.
4168 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004169 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004170 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4171 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004172 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004173 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004174
4175 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4176 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4177 "IMS not available on device.");
4178 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 final long token = Binder.clearCallingIdentity();
4180 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004181 int slotId = getSlotIndexOrException(subId);
4182 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004183
4184 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4185 if (controller != null) {
4186 ImsManager imsManager = controller.getImsManager(subId);
4187 if (imsManager != null) {
4188 imsManager.addRegistrationCallbackForSubscription(c, subId);
4189 } else {
4190 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4191 }
4192 } else {
4193 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4194 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 } catch (ImsException e) {
4196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 } finally {
4198 Binder.restoreCallingIdentity(token);
4199 }
4200 }
4201
shilu366312e2019-12-17 09:28:10 -08004202 /**
4203 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4204 * @param subId The subscription to use to check the configuration.
4205 * @param c The callback that will be used to send the result.
4206 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004208 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004209 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004210 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004211 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4212 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4213 }
Meng Wangafbc5852019-09-19 17:37:13 -07004214 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004215
Meng Wangafbc5852019-09-19 17:37:13 -07004216 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004217 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4218 if (controller != null) {
4219 ImsManager imsManager = controller.getImsManager(subId);
4220 if (imsManager != null) {
4221 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4222 } else {
4223 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4224 + "is inactive, ignoring unregister.");
4225 // If the ImsManager is not valid, just return, since the callback
4226 // will already have been removed internally.
4227 }
4228 }
Meng Wangafbc5852019-09-19 17:37:13 -07004229 } finally {
4230 Binder.restoreCallingIdentity(token);
4231 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 }
4233
Brad Ebingera34a6c22019-10-22 17:36:18 -07004234 /**
4235 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4236 */
4237 @Override
4238 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4239 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4240 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4241 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4242 "IMS not available on device.");
4243 }
4244 final long token = Binder.clearCallingIdentity();
4245 try {
4246 Phone phone = getPhone(subId);
4247 if (phone == null) {
4248 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4249 + subId + "'");
4250 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4251 }
4252 phone.getImsRegistrationState(regState -> {
4253 try {
4254 consumer.accept((regState == null)
4255 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4256 } catch (RemoteException e) {
4257 // Ignore if the remote process is no longer available to call back.
4258 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4259 }
4260 });
4261 } finally {
4262 Binder.restoreCallingIdentity(token);
4263 }
4264 }
4265
4266 /**
4267 * Get the transport type for the IMS service registration state.
4268 */
4269 @Override
4270 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004271 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004272 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004273 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4274 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4275 "IMS not available on device.");
4276 }
4277 final long token = Binder.clearCallingIdentity();
4278 try {
4279 Phone phone = getPhone(subId);
4280 if (phone == null) {
4281 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4282 + subId + "'");
4283 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4284 }
4285 phone.getImsRegistrationTech(regTech -> {
4286 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4287 int regTechConverted = (regTech == null)
4288 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4289 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4290 regTechConverted);
4291 try {
4292 consumer.accept(regTechConverted);
4293 } catch (RemoteException e) {
4294 // Ignore if the remote process is no longer available to call back.
4295 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4296 }
4297 });
4298 } finally {
4299 Binder.restoreCallingIdentity(token);
4300 }
4301 }
4302
shilu366312e2019-12-17 09:28:10 -08004303 /**
4304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4305 * @param subId The subscription to use to check the configuration.
4306 * @param c The callback that will be used to send the result.
4307 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004309 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4310 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004312 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004313 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4315 "IMS not available on device.");
4316 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long token = Binder.clearCallingIdentity();
4318 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004319 int slotId = getSlotIndexOrException(subId);
4320 verifyImsMmTelConfiguredOrThrow(slotId);
4321 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(token);
4326 }
4327 }
4328
shilu366312e2019-12-17 09:28:10 -08004329 /**
4330 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4331 * @param subId The subscription to use to check the configuration.
4332 * @param c The callback that will be used to send the result.
4333 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004335 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004336 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004337 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004338 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4339 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4340 }
Meng Wangafbc5852019-09-19 17:37:13 -07004341
4342 final long token = Binder.clearCallingIdentity();
4343 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004344 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004345 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004346 } catch (ImsException e) {
4347 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4348 + "is inactive, ignoring unregister.");
4349 // If the subscription is no longer active, just return, since the callback
4350 // will already have been removed internally.
4351 } finally {
4352 Binder.restoreCallingIdentity(token);
4353 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 }
4355
4356 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004357 public boolean isCapable(int subId, int capability, int regTech) {
4358 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 final long token = Binder.clearCallingIdentity();
4360 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004361 int slotId = getSlotIndexOrException(subId);
4362 verifyImsMmTelConfiguredOrThrow(slotId);
4363 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4364 } catch (com.android.ims.ImsException e) {
4365 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4366 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004368 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4369 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 } finally {
4371 Binder.restoreCallingIdentity(token);
4372 }
4373 }
4374
4375 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004376 public boolean isAvailable(int subId, int capability, int regTech) {
4377 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long token = Binder.clearCallingIdentity();
4379 try {
4380 Phone phone = getPhone(subId);
4381 if (phone == null) return false;
4382 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004383 } catch (com.android.ims.ImsException e) {
4384 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4385 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(token);
4388 }
4389 }
4390
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004391 /**
4392 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4393 * subscription.
4394 * @param subId The subscription to use to check the configuration.
4395 * @param callback The callback that will be used to send the result.
4396 * @param capability The MmTelFeature capability that will be used to send the result.
4397 * @param transportType The transport type of the MmTelFeature capability.
4398 */
4399 @Override
4400 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4401 int transportType) {
4402 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004403 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4404 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4405 "IMS not available on device.");
4406 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004407 final long token = Binder.clearCallingIdentity();
4408 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004409 int slotId = getSlotIndex(subId);
4410 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4411 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4412 + subId + "'");
4413 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4414 }
4415 verifyImsMmTelConfiguredOrThrow(slotId);
4416 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4417 transportType, aBoolean -> {
4418 try {
4419 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4420 } catch (RemoteException e) {
4421 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4422 + "running. Ignore");
4423 }
4424 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004427 } finally {
4428 Binder.restoreCallingIdentity(token);
4429 }
4430 }
4431
shilu366312e2019-12-17 09:28:10 -08004432 /**
4433 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4434 * @param subId The subscription to use to check the configuration.
4435 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 @Override
4437 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004438 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004439 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004440
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 final long token = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(token);
4450 }
4451 }
4452
4453 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004456 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
shilu366312e2019-12-17 09:28:10 -08004470 /**
4471 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4472 * @param subId The subscription to use to check the configuration.
4473 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004474 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004475 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004476 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004477 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 final long identity = Binder.clearCallingIdentity();
4479 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004481 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 } catch (ImsException e) {
4484 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
4488 }
4489
4490 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004491 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004493 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004497 // This setting doesn't require an active ImsService connection, so do not verify. The
4498 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004500 } catch (ImsException e) {
4501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
4505 }
4506
shilu366312e2019-12-17 09:28:10 -08004507 /**
4508 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4509 * @param subId The subscription to use to check the configuration.
4510 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004511 @Override
4512 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004513 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004514 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004515 final long identity = Binder.clearCallingIdentity();
4516 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004518 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004519 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (ImsException e) {
4521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
4527 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004528 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004530 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004533 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004534 // This setting doesn't require an active ImsService connection, so do not verify. The
4535 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004536 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (ImsException e) {
4538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
4542 }
4543
shilu366312e2019-12-17 09:28:10 -08004544 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004545 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4546 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4547 * @param subId The subscription to use to check the configuration.
4548 */
4549 @Override
4550 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004551 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004552 mApp, subId, "isCrossSimCallingEnabledByUser");
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004556 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004557 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004558 } catch (ImsException e) {
4559 throw new ServiceSpecificException(e.getCode());
4560 } finally {
4561 Binder.restoreCallingIdentity(identity);
4562 }
4563 }
4564
4565 /**
4566 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4567 * Requires MODIFY_PHONE_STATE permission.
4568 * @param subId The subscription to use to check the configuration.
4569 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4570 * false otherwise
4571 */
4572 @Override
4573 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4575 "setCrossSimCallingEnabled");
4576 final long identity = Binder.clearCallingIdentity();
4577 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004578 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004579 // This setting doesn't require an active ImsService connection, so do not verify. The
4580 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004581 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004582 } catch (ImsException e) {
4583 throw new ServiceSpecificException(e.getCode());
4584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
4589 /**
shilu366312e2019-12-17 09:28:10 -08004590 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4591 * @param subId The subscription to use to check the configuration.
4592 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004594
Brad Ebinger35c841c2018-10-01 10:40:55 -07004595 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004596 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004597 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 final long identity = Binder.clearCallingIdentity();
4599 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004601 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004602 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004603 } catch (ImsException e) {
4604 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
4608 }
4609
4610 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004611 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004613 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004614 final long identity = Binder.clearCallingIdentity();
4615 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004616 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004617 // This setting doesn't require an active ImsService connection, so do not verify. The
4618 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004619 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004620 } catch (ImsException e) {
4621 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
4625 }
4626
4627 @Override
4628 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4630 "setVoWiFiNonPersistent");
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004633 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004634 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004635 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (ImsException e) {
4637 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
shilu366312e2019-12-17 09:28:10 -08004643 /**
4644 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4645 * @param subId The subscription to use to check the configuration.
4646 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004647 @Override
4648 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004649 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004650 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004654 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004655 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (ImsException e) {
4657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004658 } finally {
4659 Binder.restoreCallingIdentity(identity);
4660 }
4661 }
4662
4663 @Override
4664 public void setVoWiFiModeSetting(int subId, int mode) {
4665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4666 "setVoWiFiModeSetting");
4667 final long identity = Binder.clearCallingIdentity();
4668 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004669 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004670 // This setting doesn't require an active ImsService connection, so do not verify. The
4671 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004672 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004673 } catch (ImsException e) {
4674 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004675 } finally {
4676 Binder.restoreCallingIdentity(identity);
4677 }
4678 }
4679
4680 @Override
4681 public int getVoWiFiRoamingModeSetting(int subId) {
4682 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4683 final long identity = Binder.clearCallingIdentity();
4684 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004685 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004686 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004687 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004688 } catch (ImsException e) {
4689 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
4693 }
4694
4695 @Override
4696 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4698 "setVoWiFiRoamingModeSetting");
4699 final long identity = Binder.clearCallingIdentity();
4700 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004701 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004702 // This setting doesn't require an active ImsService connection, so do not verify. The
4703 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004704 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004705 } catch (ImsException e) {
4706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004707 } finally {
4708 Binder.restoreCallingIdentity(identity);
4709 }
4710 }
4711
4712 @Override
4713 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4715 "setRttCapabilityEnabled");
4716 final long identity = Binder.clearCallingIdentity();
4717 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004718 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004719 // This setting doesn't require an active ImsService connection, so do not verify. The
4720 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004721 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004722 } catch (ImsException e) {
4723 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
4727 }
4728
shilu366312e2019-12-17 09:28:10 -08004729 /**
4730 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4731 * @param subId The subscription to use to check the configuration.
4732 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004733 @Override
4734 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004735 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004736 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004737 final long identity = Binder.clearCallingIdentity();
4738 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004739 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004740 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004741 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004742 } catch (ImsException e) {
4743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004744 } finally {
4745 Binder.restoreCallingIdentity(identity);
4746 }
4747 }
4748
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004749 @Override
4750 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4751 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004752
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004753 final long identity = Binder.clearCallingIdentity();
4754 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004755 if (!isImsAvailableOnDevice()) {
4756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4757 "IMS not available on device.");
4758 }
4759 int slotId = getSlotIndexOrException(subId);
4760 verifyImsMmTelConfiguredOrThrow(slotId);
4761 ImsManager.getInstance(mApp, slotId)
4762 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004763 } catch (ImsException e) {
4764 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
4768 }
4769
4770 @Override
4771 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4772 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004773
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004774 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4776 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004778 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004780 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004781 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004782 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4783 + "is inactive, ignoring unregister.");
4784 // If the subscription is no longer active, just return, since the callback will already
4785 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
4789 }
4790
joonhunshincffb7fc2021-11-28 07:32:01 +00004791 @Override
4792 public void registerFeatureProvisioningChangedCallback(int subId,
4793 IFeatureProvisioningCallback callback) {
4794 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4795 mApp, subId, "registerFeatureProvisioningChangedCallback");
4796
4797 final long identity = Binder.clearCallingIdentity();
4798 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4799 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4800 }
4801
joonhunshin91bc1952022-04-29 08:47:15 +00004802 try {
4803 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4804 if (controller == null) {
4805 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4806 "Device does not support IMS");
4807 }
4808 controller.addFeatureProvisioningChangedCallback(subId, callback);
4809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004812 }
4813
4814 @Override
4815 public void unregisterFeatureProvisioningChangedCallback(int subId,
4816 IFeatureProvisioningCallback callback) {
4817 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4818 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4819
4820 final long identity = Binder.clearCallingIdentity();
4821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4822 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4823 }
4824
joonhunshin91bc1952022-04-29 08:47:15 +00004825 try {
4826 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4827 if (controller == null) {
4828 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4829 return;
4830 }
4831 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004835 }
allenwtsu99c623b2020-01-03 18:24:23 +08004836
4837 private void checkModifyPhoneStatePermission(int subId, String message) {
4838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 message);
4840 }
4841
allenwtsu99c623b2020-01-03 18:24:23 +08004842 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004843 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004844 boolean isProvisioned) {
4845 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4846
4847 final long identity = Binder.clearCallingIdentity();
4848 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004849 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4850 if (controller == null) {
4851 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4852 return;
4853 }
4854 controller.setRcsProvisioningStatusForCapability(
4855 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004856 } finally {
4857 Binder.restoreCallingIdentity(identity);
4858 }
allenwtsu99c623b2020-01-03 18:24:23 +08004859 }
4860
4861
4862 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004863 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4864 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4865 mApp, subId, "getRcsProvisioningStatusForCapability");
4866
allenwtsu99c623b2020-01-03 18:24:23 +08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004869 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4870 if (controller == null) {
4871 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4872
4873 // device does not support IMS, this method will return true always.
4874 return true;
4875 }
4876 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004877 } finally {
4878 Binder.restoreCallingIdentity(identity);
4879 }
4880 }
4881
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004882 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004883 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4884 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004885 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004886
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004889 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4890 if (controller == null) {
4891 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4892 return;
4893 }
4894 controller.setImsProvisioningStatusForCapability(
4895 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 } finally {
4897 Binder.restoreCallingIdentity(identity);
4898 }
4899 }
4900
4901 @Override
4902 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004903 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4904 mApp, subId, "getProvisioningStatusForCapability");
4905
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004908 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4909 if (controller == null) {
4910 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911
joonhunshin91bc1952022-04-29 08:47:15 +00004912 // device does not support IMS, this method will return true always.
4913 return true;
4914 }
4915 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
4919 }
4920
4921 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004922 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4923 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4924 mApp, subId, "isProvisioningRequiredForCapability");
4925
4926 final long identity = Binder.clearCallingIdentity();
4927 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004928 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4929 if (controller == null) {
4930 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4931
4932 // device does not support IMS, this method will return false
4933 return false;
4934 }
4935 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004936 } finally {
4937 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 }
4940
4941 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004942 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4943 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4944 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945
joonhunshincffb7fc2021-11-28 07:32:01 +00004946 final long identity = Binder.clearCallingIdentity();
4947 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004948 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4949 if (controller == null) {
4950 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4951
4952 // device does not support IMS, this method will return false
4953 return false;
4954 }
4955 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 }
4960
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4964 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4965 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004966 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4967 mApp, subId, "getImsProvisioningInt");
4968
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4975 + subId + "' for key:" + key);
4976 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4977 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004978
joonhunshin91bc1952022-04-29 08:47:15 +00004979 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4980 if (controller == null) {
4981 loge("getImsProvisioningInt: Device does not support IMS");
4982
4983 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4984 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4985 }
4986 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004987 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4988 return retVal;
4989 }
4990
calvinpanb5a34062021-02-08 19:59:36 +08004991 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004992 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004993 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4994 + subId + "' for key:" + key);
4995 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
4999 }
5000
5001 @Override
5002 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005003 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5004 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5005 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005006 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5007 mApp, subId, "getImsProvisioningString");
5008
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005012 int slotId = getSlotIndex(subId);
5013 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5014 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5015 + subId + "' for key:" + key);
5016 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5017 }
calvinpanb5a34062021-02-08 19:59:36 +08005018 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005019 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005020 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5021 + subId + "' for key:" + key);
5022 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005023 } finally {
5024 Binder.restoreCallingIdentity(identity);
5025 }
5026 }
5027
5028 @Override
5029 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005030 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5031 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5032 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5034 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005035
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005039 int slotId = getSlotIndex(subId);
5040 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5041 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5042 + subId + "' for key:" + key);
5043 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5044 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005045
joonhunshin91bc1952022-04-29 08:47:15 +00005046 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5047 if (controller == null) {
5048 loge("setImsProvisioningInt: Device does not support IMS");
5049
5050 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5051 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5052 }
5053 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005054 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5055 return retVal;
5056 }
5057
calvinpanb5a34062021-02-08 19:59:36 +08005058 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5059 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005060 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005061 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005062 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
5066 }
5067
5068 @Override
5069 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005070 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5071 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5072 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5074 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005078 int slotId = getSlotIndex(subId);
5079 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5080 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5081 + subId + "' for key:" + key);
5082 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5083 }
calvinpanb5a34062021-02-08 19:59:36 +08005084 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5085 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005087 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005088 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
Brad Ebinger919631e2021-06-02 17:46:35 -07005094 /**
5095 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5096 * for the given slot ID or no ImsResolver instance has been created.
5097 * @param slotId The slot ID that the IMS service is created for.
5098 * @throws ImsException If there is no ImsService configured for this slot.
5099 */
5100 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5101 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5102 ImsFeature.FEATURE_MMTEL)) {
5103 throw new ImsException("This subscription does not support MMTEL over IMS",
5104 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5105 }
5106 }
5107
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005108 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005109 int slotId = SubscriptionManager.getSlotIndex(subId);
5110 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005111 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5112 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005113 }
5114 return slotId;
5115 }
5116
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005117 private int getSlotIndex(int subId) {
5118 int slotId = SubscriptionManager.getSlotIndex(subId);
5119 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5120 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5121 }
5122 return slotId;
5123 }
5124
Wink Saville36469e72014-06-11 15:17:00 -07005125 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005126 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005127 */
5128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005129 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5130 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005131 try {
5132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5133 } catch (SecurityException se) {
5134 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5135 throw new SecurityException("Package " + callingPackage + " does not belong to "
5136 + Binder.getCallingUid());
5137 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005138 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005139 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005140 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005141 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005142 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005143 mApp, subId, callingPackage, callingFeatureId,
5144 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005145 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5146 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148 final long identity = Binder.clearCallingIdentity();
5149 try {
5150 final Phone phone = getPhone(subId);
5151 if (phone != null) {
5152 return phone.getServiceState().getDataNetworkType();
5153 } else {
5154 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5155 }
5156 } finally {
5157 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005159 }
5160
5161 /**
5162 * Returns the data network type
5163 */
5164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005165 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005166 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5167 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005168 }
5169
5170 /**
5171 * Returns the data network type for a subId
5172 */
5173 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005174 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5175 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005176 String functionName = "getDataNetworkTypeForSubscriber";
5177 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5178 mApp, functionName)) {
5179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5180 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5181 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5182 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005183 }
5184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 final Phone phone = getPhone(subId);
5188 if (phone != null) {
5189 return phone.getServiceState().getDataNetworkType();
5190 } else {
5191 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5192 }
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005196 }
5197
5198 /**
Wink Saville36469e72014-06-11 15:17:00 -07005199 * Returns the Voice network type for a subId
5200 */
5201 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005202 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5203 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005204 String functionName = "getVoiceNetworkTypeForSubscriber";
5205 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5206 mApp, functionName)) {
5207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5208 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5209 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5210 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005211 }
5212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 final Phone phone = getPhone(subId);
5216 if (phone != null) {
5217 return phone.getServiceState().getVoiceNetworkType();
5218 } else {
5219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5220 }
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005223 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005224 }
5225
5226 /**
5227 * @return true if a ICC card is present
5228 */
5229 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005230 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005231 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5232 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005233 }
5234
5235 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005236 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005237 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005238 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005239 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 final long identity = Binder.clearCallingIdentity();
5241 try {
5242 final Phone phone = PhoneFactory.getPhone(slotIndex);
5243 if (phone != null) {
5244 return phone.getIccCard().hasIccCard();
5245 } else {
5246 return false;
5247 }
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005251 }
5252
5253 /**
5254 * Return if the current radio is LTE on CDMA. This
5255 * is a tri-state return value as for a period of time
5256 * the mode may be unknown.
5257 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005258 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005259 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005260 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005261 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005263 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5264 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5265 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005266 }
5267
Sanket Padawe356d7632015-06-22 14:03:32 -07005268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005269 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5270 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005271 try {
5272 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5273 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005274 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5275 }
5276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 final Phone phone = getPhone(subId);
5280 if (phone == null) {
5281 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5282 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005283 return TelephonyProperties.lte_on_cdma_device()
5284 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 }
5286 } finally {
5287 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005288 }
Wink Saville36469e72014-06-11 15:17:00 -07005289 }
5290
Wink Saville36469e72014-06-11 15:17:00 -07005291 /**
5292 * {@hide}
5293 * Returns Default subId, 0 in the case of single standby.
5294 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005295 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005296 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005297 }
5298
Shishir Agrawala9f32182016-04-12 12:00:16 -07005299 private int getSlotForDefaultSubscription() {
5300 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5301 }
5302
Wink Savilleb564aae2014-10-23 10:18:09 -07005303 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005304 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005305 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005306
Pengquan Menge92a50d2018-09-21 15:54:48 -07005307 private boolean isActiveSubscription(int subId) {
5308 return mSubscriptionController.isActiveSubId(subId);
5309 }
5310
Ihab Awadf2177b72013-11-25 13:33:23 -08005311 /**
5312 * @see android.telephony.TelephonyManager.WifiCallingChoices
5313 */
5314 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 final long identity = Binder.clearCallingIdentity();
5316 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005317 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5319 getWhenToMakeWifiCallsDefaultPreference());
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005323 }
5324
5325 /**
5326 * @see android.telephony.TelephonyManager.WifiCallingChoices
5327 */
5328 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005332 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
5336 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005337 }
5338
Sailesh Nepald1e68152013-12-12 19:08:02 -08005339 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005340 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005341 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005342 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005343
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005344 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5345 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5346 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005347 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005348 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5349 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005350 }
5351 return PhoneFactory.getPhone(phoneId);
5352 }
5353
Shishir Agrawal566b7612013-10-28 14:41:00 -07005354 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005355 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005356 @NonNull IccLogicalChannelRequest request) {
5357 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5358 /*message=*/ "iccOpenLogicalChannel");
5359
5360 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5361 // Verify that the callingPackage in the request belongs to the calling UID
5362 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5363
5364 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005365 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005366
Rambo Wanga1782702021-11-10 20:15:19 -08005367 private Phone getPhoneFromValidIccLogicalChannelRequest(
5368 @NonNull IccLogicalChannelRequest request, String message) {
5369 Phone phone;
5370 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5372 mApp, request.subId, message);
5373 phone = getPhoneFromSubId(request.subId);
5374 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5375 enforceModifyPermission();
5376 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5377 } else {
5378 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005379 }
Rambo Wanga1782702021-11-10 20:15:19 -08005380 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005381 }
5382
5383 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005384 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 final long identity = Binder.clearCallingIdentity();
5386 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005387 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5390 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005391 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5392 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 loge("The calling package is not allowed to access ISD-R.");
5394 throw new SecurityException(
5395 "The calling package is not allowed to access ISD-R.");
5396 }
Derek Tan740e1672017-06-27 14:56:27 -07005397 }
Derek Tan740e1672017-06-27 14:56:27 -07005398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005400 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5401 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 return response;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005406 }
5407
5408 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005409 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5410 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5411 /*message=*/"iccCloseLogicalChannel");
5412
5413 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5414
5415 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005416 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005417
Rambo Wanga1782702021-11-10 20:15:19 -08005418 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5419 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005420 // before this feature is enabled, this API should only return false if
5421 // the operation fails instead of throwing runtime exception for
5422 // backward-compatibility.
5423 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5424 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005427 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005428 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 }
Chen Xue9d737e2022-01-01 23:41:31 -08005430 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005431 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005432 Boolean success = false;
5433 if (result instanceof RuntimeException) {
5434 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005435 if (shouldThrowExceptionOnFailure) {
5436 throw (RuntimeException) result;
5437 } else {
5438 return false;
5439 }
Chen Xue9d737e2022-01-01 23:41:31 -08005440 } else if (result instanceof Boolean) {
5441 success = (Boolean) result;
5442 } else {
5443 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5444 }
Rambo Wanga1782702021-11-10 20:15:19 -08005445 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 return success;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
5451
5452 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005453 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005454 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005457 if (DBG) {
5458 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5459 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5460 + p3 + " data=" + data);
5461 }
5462 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5463 command, p1, p2, p3, data);
5464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005465
Jordan Liu4c733742019-02-28 12:03:40 -08005466 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005467 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5468 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005469 enforceModifyPermission();
5470 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005471 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5472 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5473 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005474 }
5475 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005476 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5477 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005478 }
5479
5480 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5481 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005484 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 return "";
5486 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005489 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5490 null /* workSource */);
5491 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 // Append the returned status code to the end of the response payload.
5494 String s = Integer.toHexString(
5495 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5496 if (response.payload != null) {
5497 s = IccUtils.bytesToHexString(response.payload) + s;
5498 }
5499 return s;
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005503 }
Jake Hambye994d462014-02-03 13:10:13 -08005504
Evan Charltonc66da362014-05-16 14:06:40 -07005505 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005506 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5507 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5509 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005511 if (DBG) {
5512 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5513 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5514 }
5515 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5516 cla, command, p1, p2, p3, data);
5517 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005518
Jordan Liu4c733742019-02-28 12:03:40 -08005519 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005520 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5521 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005522 enforceModifyPermission();
5523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5524 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005525 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5526 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5527 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005528 }
5529
5530 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005531 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5532 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005533 }
5534
5535 // open APDU basic channel assuming the caller has sufficient permissions
5536 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5537 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5541 && TextUtils.equals(ISDR_AID, data)) {
5542 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005543 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5544 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 if (bestComponent == null
5546 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5547 loge("The calling package is not allowed to select ISD-R.");
5548 throw new SecurityException(
5549 "The calling package is not allowed to select ISD-R.");
5550 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005551 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005554 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5555 null /* workSource */);
5556 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 // Append the returned status code to the end of the response payload.
5559 String s = Integer.toHexString(
5560 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5561 if (response.payload != null) {
5562 s = IccUtils.bytesToHexString(response.payload) + s;
5563 }
5564 return s;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005567 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005568 }
5569
5570 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005571 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005572 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5574 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576 final long identity = Binder.clearCallingIdentity();
5577 try {
5578 if (DBG) {
5579 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5580 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5581 }
5582
5583 IccIoResult response =
5584 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5585 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5586 subId);
5587
5588 if (DBG) {
5589 log("Exchange SIM_IO [R]" + response);
5590 }
5591
5592 byte[] result = null;
5593 int length = 2;
5594 if (response.payload != null) {
5595 length = 2 + response.payload.length;
5596 result = new byte[length];
5597 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5598 } else {
5599 result = new byte[length];
5600 }
5601
5602 result[length - 1] = (byte) response.sw2;
5603 result[length - 2] = (byte) response.sw1;
5604 return result;
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005607 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005608 }
5609
Nathan Haroldb3014052017-01-25 15:57:32 -08005610 /**
5611 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5612 * on a particular subscription
5613 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005614 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5615 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005617 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005618 return null;
5619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 if (appType != TelephonyManager.APPTYPE_USIM
5624 && appType != TelephonyManager.APPTYPE_SIM) {
5625 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5626 return null;
5627 }
5628 Object response = sendRequest(
5629 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5630 if (response instanceof String[]) {
5631 return (String[]) response;
5632 }
yincheng zhao2737e882019-09-06 17:06:54 -07005633 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005635 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 } finally {
5637 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005638 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005639 }
5640
yincheng zhao2737e882019-09-06 17:06:54 -07005641 /**
5642 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5643 * subscription.
5644 *
5645 * @param subId the id of the subscription.
5646 * @param appType the uicc app type, must be USIM or SIM.
5647 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5648 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005649 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005650 * @return number of fplmns that is successfully written to the SIM.
5651 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005652 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5653 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5655 mApp, subId, "setForbiddenPlmns");
5656
yincheng zhao2737e882019-09-06 17:06:54 -07005657 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5658 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5659 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5660 }
5661 if (fplmns == null) {
5662 throw new IllegalArgumentException("Fplmn List provided is null");
5663 }
5664 for (String fplmn : fplmns) {
5665 if (!CellIdentity.isValidPlmn(fplmn)) {
5666 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5667 }
5668 }
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 Object response = sendRequest(
5672 CMD_SET_FORBIDDEN_PLMNS,
5673 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5674 subId);
5675 return (int) response;
5676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
5679 }
5680
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005681 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005682 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5684 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 final long identity = Binder.clearCallingIdentity();
5687 try {
5688 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5689 if (response.payload == null) {
5690 return "";
5691 }
Evan Charltonc66da362014-05-16 14:06:40 -07005692
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 // Append the returned status code to the end of the response payload.
5694 String s = Integer.toHexString(
5695 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5696 s = IccUtils.bytesToHexString(response.payload) + s;
5697 return s;
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Evan Charltonc66da362014-05-16 14:06:40 -07005701 }
5702
Jake Hambye994d462014-02-03 13:10:13 -08005703 /**
5704 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5705 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5706 *
5707 * @param itemID the ID of the item to read
5708 * @return the NV item as a String, or null on error.
5709 */
5710 @Override
5711 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005712 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5714 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005719 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5721 return value;
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Jake Hambye994d462014-02-03 13:10:13 -08005725 }
5726
5727 /**
5728 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5729 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5730 *
5731 * @param itemID the ID of the item to read
5732 * @param itemValue the value to write, as a String
5733 * @return true on success; false on any failure
5734 */
5735 @Override
5736 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005737 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5739 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
5743 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5744 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005745 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5747 return success;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Jake Hambye994d462014-02-03 13:10:13 -08005751 }
5752
5753 /**
5754 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5755 * Used for device configuration by some CDMA operators.
5756 *
5757 * @param preferredRoamingList byte array containing the new PRL
5758 * @return true on success; false on any failure
5759 */
5760 @Override
5761 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5763 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5768 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5769 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5770 return success;
5771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Jake Hambye994d462014-02-03 13:10:13 -08005774 }
5775
5776 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005777 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005778 * Used for device configuration by some CDMA operators.
5779 *
chen xu6dac5ab2018-10-26 17:39:23 -07005780 * @param slotIndex - device slot.
5781 *
Jake Hambye994d462014-02-03 13:10:13 -08005782 * @return true on success; false on any failure
5783 */
5784 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005785 public boolean resetModemConfig(int slotIndex) {
5786 Phone phone = PhoneFactory.getPhone(slotIndex);
5787 if (phone != null) {
5788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5789 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
chen xu6dac5ab2018-10-26 17:39:23 -07005791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5794 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5795 return success;
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
5798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 }
chen xu6dac5ab2018-10-26 17:39:23 -07005800 return false;
5801 }
5802
5803 /**
5804 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5805 *
5806 * @param slotIndex - device slot.
5807 *
5808 * @return true on success; false on any failure
5809 */
5810 @Override
5811 public boolean rebootModem(int slotIndex) {
5812 Phone phone = PhoneFactory.getPhone(slotIndex);
5813 if (phone != null) {
5814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5815 mApp, phone.getSubId(), "rebootModem");
5816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
5819 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5820 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5821 return success;
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
5825 }
5826 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005827 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005828
Brad Ebinger51f743a2017-01-23 13:50:20 -08005829 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005830 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5831 * {@link #disableIms(int)}.
5832 * @param slotIndex device slot.
5833 */
5834 public void resetIms(int slotIndex) {
5835 enforceModifyPermission();
5836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 if (mImsResolver == null) {
5840 // may happen if the does not support IMS.
5841 return;
5842 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005843 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
5847 }
5848
5849 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005850 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5851 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005852 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005853 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005854 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005859 // may happen if the device does not support IMS.
5860 return;
5861 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005866 }
5867
5868 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005869 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5870 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005871 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005872 public void disableIms(int slotId) {
5873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005878 // may happen if the device does not support IMS.
5879 return;
5880 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005881 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005885 }
5886
5887 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005888 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5889 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005890 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005891 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005892 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005893 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894
5895 final long identity = Binder.clearCallingIdentity();
5896 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005897 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005898 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5899 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005900 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005901 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005905 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005906 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005907 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5908 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005909 @Override
5910 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005911 enforceModifyPermission();
5912
5913 final long identity = Binder.clearCallingIdentity();
5914 try {
5915 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005916 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
5920 }
5921
5922 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005923 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005924 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005925 */
5926 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928
5929 final long identity = Binder.clearCallingIdentity();
5930 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005932 // may happen if the device does not support IMS.
5933 return null;
5934 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005939 }
5940
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005941 /**
5942 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005943 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005944 */
5945 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947
5948 final long identity = Binder.clearCallingIdentity();
5949 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005950 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005951 // may happen if the device does not support IMS.
5952 return null;
5953 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005954 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005958 }
5959
Brad Ebinger884c07b2018-02-15 16:17:40 -08005960 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005961 * Sets the ImsService Package Name that Telephony will bind to.
5962 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005963 * @param slotIndex the slot ID that the ImsService should bind for.
5964 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005965 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005966 * @param featureTypes An integer array of feature types associated with a packageName.
5967 * @param packageName The name of the package that the current configuration will be replaced
5968 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005969 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5972 int[] featureTypes, String packageName) {
5973 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5974 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5976 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005977 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979 final long identity = Binder.clearCallingIdentity();
5980 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005981 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005982 // may happen if the device does not support IMS.
5983 return false;
5984 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005985 Map<Integer, String> featureConfig = new HashMap<>();
5986 for (int featureType : featureTypes) {
5987 featureConfig.put(featureType, packageName);
5988 }
5989 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5990 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005994 }
5995
5996 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005997 * Clears any carrier ImsService overrides for the slot index specified that were previously
5998 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5999 *
6000 * This should only be used for testing.
6001 *
6002 * @param slotIndex the slot ID that the ImsService should bind for.
6003 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6004 */
6005 @Override
6006 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6007 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6009 "clearCarrierImsServiceOverride");
6010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6011 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6012 "clearCarrierImsServiceOverride");
6013
6014 final long identity = Binder.clearCallingIdentity();
6015 try {
6016 if (mImsResolver == null) {
6017 // may happen if the device does not support IMS.
6018 return false;
6019 }
6020 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
6024 }
6025
6026 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006027 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006028 *
6029 * @param slotId The slot that the ImsService is associated with.
6030 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6031 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006033 * @return the package name of the ImsService configuration.
6034 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006035 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6036 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006037 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006038 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006039 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6041 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 final long identity = Binder.clearCallingIdentity();
6044 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006046 // may happen if the device does not support IMS.
6047 return "";
6048 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006049 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6051 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006055 }
6056
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006057 /**
6058 * Get the MmTelFeature state associated with the requested subscription id.
6059 * @param subId The subscription that the MmTelFeature is associated with.
6060 * @param callback A callback with an integer containing the
6061 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6062 */
6063 @Override
6064 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6065 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006066 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6067 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6068 "IMS not available on device.");
6069 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006070 final long token = Binder.clearCallingIdentity();
6071 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006072 int slotId = getSlotIndex(subId);
6073 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6074 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6075 + subId + "'");
6076 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6077 }
6078 verifyImsMmTelConfiguredOrThrow(slotId);
6079 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6080 try {
6081 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6082 } catch (RemoteException e) {
6083 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6084 + "Ignore");
6085 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006086 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006087 } catch (ImsException e) {
6088 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006089 } finally {
6090 Binder.restoreCallingIdentity(token);
6091 }
6092 }
6093
Daniel Brightbb5840b2021-01-12 15:48:18 -08006094 /**
6095 * Sets the ims registration state on all valid {@link Phone}s.
6096 */
6097 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006098 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006102 // NOTE: Before S, this method only set the default phone.
6103 for (final Phone phone : PhoneFactory.getPhones()) {
6104 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6105 phone.setImsRegistrationState(registered);
6106 }
6107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
Wink Saville36469e72014-06-11 15:17:00 -07006111 }
6112
6113 /**
Stuart Scott54788802015-03-30 13:18:01 -07006114 * Set the network selection mode to automatic.
6115 *
6116 */
6117 @Override
6118 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6120 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
shilufc958392020-01-20 11:36:01 -08006124 if (!isActiveSubscription(subId)) {
6125 return;
6126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006128 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6129 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
Stuart Scott54788802015-03-30 13:18:01 -07006133 }
6134
Jack Yud10cdd42020-09-28 20:28:01 -07006135 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006136 * Ask the radio to connect to the input network and change selection mode to manual.
6137 *
6138 * @param subId the id of the subscription.
6139 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6140 * the operator to attach to.
6141 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6142 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6143 * normal network selection next time.
6144 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006145 */
6146 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006147 public boolean setNetworkSelectionModeManual(
6148 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6150 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006151
6152 if (!isActiveSubscription(subId)) {
6153 return false;
6154 }
6155
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 final long identity = Binder.clearCallingIdentity();
6157 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006158 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006160 if (DBG) {
6161 log("setNetworkSelectionModeManual: subId: " + subId
6162 + " operator: " + operatorInfo);
6163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006168 }
shilu84f6e8b2019-12-19 13:58:01 -08006169 /**
6170 * Get the manual network selection
6171 *
6172 * @param subId the id of the subscription.
6173 *
6174 * @return the previously saved user selected PLMN
6175 */
6176 @Override
6177 public String getManualNetworkSelectionPlmn(int subId) {
6178 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006179 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006180 mApp, subId, "getManualNetworkSelectionPlmn");
6181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006185 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006186 }
6187
6188 final Phone phone = getPhone(subId);
6189 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006190 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006191 }
6192 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6193 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6194 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
6198 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006199
6200 /**
6201 * Scans for available networks.
6202 */
6203 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006204 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6205 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006206 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6207 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006208 LocationAccessPolicy.LocationPermissionResult locationResult =
6209 LocationAccessPolicy.checkLocationPermission(mApp,
6210 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6211 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006212 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006213 .setCallingPid(Binder.getCallingPid())
6214 .setCallingUid(Binder.getCallingUid())
6215 .setMethod("getCellNetworkScanResults")
6216 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006217 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6218 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006219 .build());
6220 switch (locationResult) {
6221 case DENIED_HARD:
6222 throw new SecurityException("Not allowed to access scan results -- location");
6223 case DENIED_SOFT:
6224 return null;
6225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
Pengquan Menga1bb6272018-09-06 09:59:22 -07006227 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006228 try {
6229 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006230 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006235 }
6236
6237 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006238 * Get the call forwarding info, given the call forwarding reason.
6239 */
6240 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006241 public void getCallForwarding(int subId, int callForwardingReason,
6242 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006243 enforceReadPrivilegedPermission("getCallForwarding");
6244 long identity = Binder.clearCallingIdentity();
6245 try {
6246 if (DBG) {
6247 log("getCallForwarding: subId " + subId
6248 + " callForwardingReason" + callForwardingReason);
6249 }
Hall Liu27d24262020-09-18 19:04:59 -07006250
6251 Phone phone = getPhone(subId);
6252 if (phone == null) {
6253 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006254 callback.onError(
6255 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006256 } catch (RemoteException e) {
6257 // ignore
6258 }
6259 return;
6260 }
6261
6262 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6263 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6264 @Override
6265 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6266 try {
6267 callback.onCallForwardingInfoAvailable(info);
6268 } catch (RemoteException e) {
6269 // ignore
6270 }
6271 }
6272
6273 @Override
6274 public void onError(int error) {
6275 try {
6276 callback.onError(error);
6277 } catch (RemoteException e) {
6278 // ignore
6279 }
6280 }
6281 });
6282 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
6286 }
6287
6288 /**
6289 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6290 * reason, the number to forward, and the timeout before the forwarding is attempted.
6291 */
6292 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006293 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6294 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006295 enforceModifyPermission();
6296 long identity = Binder.clearCallingIdentity();
6297 try {
6298 if (DBG) {
6299 log("setCallForwarding: subId " + subId
6300 + " callForwardingInfo" + callForwardingInfo);
6301 }
Hall Liu27d24262020-09-18 19:04:59 -07006302
6303 Phone phone = getPhone(subId);
6304 if (phone == null) {
6305 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006306 callback.accept(
6307 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006308 } catch (RemoteException e) {
6309 // ignore
6310 }
6311 return;
6312 }
6313
6314 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6315 FunctionalUtils.ignoreRemoteException(callback::accept));
6316
6317 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006318 } finally {
6319 Binder.restoreCallingIdentity(identity);
6320 }
6321 }
6322
6323 /**
Hall Liu27d24262020-09-18 19:04:59 -07006324 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006325 */
6326 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006327 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006328 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006329 long identity = Binder.clearCallingIdentity();
6330 try {
Hall Liu27d24262020-09-18 19:04:59 -07006331 Phone phone = getPhone(subId);
6332 if (phone == null) {
6333 try {
6334 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6335 } catch (RemoteException e) {
6336 // ignore
6337 }
6338 return;
6339 }
SongFerngWang0e767992021-03-31 22:08:45 +08006340 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6341 PersistableBundle c = configManager.getConfigForSubId(subId);
6342 boolean requireUssd = c.getBoolean(
6343 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006344
Shuo Qian4a594052020-01-23 11:59:30 -08006345 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006346 if (requireUssd) {
6347 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6348 getSubscriptionCarrierId(subId));
6349 String newUssdCommand = "";
6350 try {
6351 newUssdCommand = carrierXmlParser.getFeature(
6352 CarrierXmlParser.FEATURE_CALL_WAITING)
6353 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6354 } catch (NullPointerException e) {
6355 loge("Failed to generate USSD number" + e);
6356 }
6357 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6358 mMainThreadHandler, callback, carrierXmlParser,
6359 CarrierXmlParser.SsEntry.SSAction.QUERY);
6360 final String ussdCommand = newUssdCommand;
6361 Executors.newSingleThreadExecutor().execute(() -> {
6362 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6363 });
6364 } else {
6365 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6366 callback::accept);
6367 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6368 }
Shuo Qian4a594052020-01-23 11:59:30 -08006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
6371 }
6372 }
6373
6374 /**
Hall Liu27d24262020-09-18 19:04:59 -07006375 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006376 */
6377 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006378 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006379 enforceModifyPermission();
6380 long identity = Binder.clearCallingIdentity();
6381 try {
Hall Liu27d24262020-09-18 19:04:59 -07006382 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6383
6384 Phone phone = getPhone(subId);
6385 if (phone == null) {
6386 try {
6387 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6388 } catch (RemoteException e) {
6389 // ignore
6390 }
6391 return;
6392 }
6393
SongFerngWang0e767992021-03-31 22:08:45 +08006394 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6395 PersistableBundle c = configManager.getConfigForSubId(subId);
6396 boolean requireUssd = c.getBoolean(
6397 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006398
SongFerngWang0e767992021-03-31 22:08:45 +08006399 if (DBG) log("getCallWaitingStatus: subId " + subId);
6400 if (requireUssd) {
6401 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6402 getSubscriptionCarrierId(subId));
6403 CarrierXmlParser.SsEntry.SSAction ssAction =
6404 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6405 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6406 String newUssdCommand = "";
6407 try {
6408 newUssdCommand = carrierXmlParser.getFeature(
6409 CarrierXmlParser.FEATURE_CALL_WAITING)
6410 .makeCommand(ssAction, null);
6411 } catch (NullPointerException e) {
6412 loge("Failed to generate USSD number" + e);
6413 }
6414 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6415 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6416 final String ussdCommand = newUssdCommand;
6417 Executors.newSingleThreadExecutor().execute(() -> {
6418 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6419 });
6420 } else {
6421 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6422 FunctionalUtils.ignoreRemoteException(callback::accept));
6423
6424 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6425 }
Shuo Qian4a594052020-01-23 11:59:30 -08006426 } finally {
6427 Binder.restoreCallingIdentity(identity);
6428 }
6429 }
6430
6431 /**
yinxub1bed742017-04-17 11:45:04 -07006432 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006433 *
yinxub1bed742017-04-17 11:45:04 -07006434 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006435 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6436 * location related information which will be sent if the caller already possess
6437 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006438 * @param request contains the radio access networks with bands/channels to scan
6439 * @param messenger callback messenger for scan results or errors
6440 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006441 * @return the id of the requested scan which can be used to stop the scan.
6442 */
6443 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006444 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6445 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006446 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6448 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006449 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006450 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6451 if (!renounceFineLocationAccess) {
6452 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6453 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6454 .setCallingPackage(callingPackage)
6455 .setCallingFeatureId(callingFeatureId)
6456 .setCallingPid(Binder.getCallingPid())
6457 .setCallingUid(Binder.getCallingUid())
6458 .setMethod("requestNetworkScan")
6459 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6460 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6461 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6462 .build());
6463 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006464 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006465 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6466 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006467 if (e != null) {
6468 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6469 throw e;
6470 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006471 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006472 return TelephonyScanManager.INVALID_SCAN_ID;
6473 }
6474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 }
Hall Liu912dfd32019-04-25 14:02:26 -07006476 int callingUid = Binder.getCallingUid();
6477 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006481 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006482 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
yinxu504e1392017-04-12 16:03:22 -07006486 }
6487
Hall Liub2ac8ef2019-02-28 15:56:23 -08006488 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006489 NetworkScanRequest request, int subId, String callingPackage) {
6490 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006491 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6492 boolean hasNetworkScanPermission =
6493 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6494 == PERMISSION_GRANTED;
6495
6496 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6497 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6498 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006499 }
6500
6501 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6502 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006503 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6504 return new SecurityException("Specific channels must not be"
6505 + " scanned without location access.");
6506 }
6507 }
6508 }
6509
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 return null;
6511 }
6512
yinxu504e1392017-04-12 16:03:22 -07006513 /**
6514 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006515 *
6516 * @param subId id of the subscription
6517 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006518 */
6519 @Override
6520 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6522 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523
Hall Liu912dfd32019-04-25 14:02:26 -07006524 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 final long identity = Binder.clearCallingIdentity();
6526 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006527 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
yinxu504e1392017-04-12 16:03:22 -07006531 }
6532
6533 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006534 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006535 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006536 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006537 */
6538 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006539 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006540 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006541 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006542 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 if (DBG) log("getAllowedNetworkTypesBitmask");
6547 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6548 int networkTypesBitmask = (result != null ? result[0] : -1);
6549 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6550 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006554 }
6555
6556 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006557 * Get the allowed network types for certain reason.
6558 *
6559 * @param subId the id of the subscription.
6560 * @param reason the reason the allowed network type change is taking place
6561 * @return the allowed network types.
6562 */
6563 @Override
6564 public long getAllowedNetworkTypesForReason(int subId,
6565 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006566 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006567 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
6573 }
6574 }
6575
6576 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006577 * Enable/Disable E-UTRA-NR Dual Connectivity
6578 * @param subId subscription id of the sim card
6579 * @param nrDualConnectivityState expected NR dual connectivity state
6580 * This can be passed following states
6581 * <ol>
6582 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6583 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6584 * <li>Disable NR dual connectivity and force secondary cell to be released
6585 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6586 * </ol>
6587 * @return operation result.
6588 */
6589 @Override
6590 public int setNrDualConnectivityState(int subId,
6591 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6593 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006594 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006595 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6596 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6597 }
6598
Sooraj Sasindran37444802020-08-11 10:40:43 -07006599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6600 final long identity = Binder.clearCallingIdentity();
6601 try {
6602 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6603 nrDualConnectivityState, subId,
6604 workSource);
6605 if (DBG) log("enableNRDualConnectivity result: " + result);
6606 return result;
6607 } finally {
6608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
6611
6612 /**
6613 * Is E-UTRA-NR Dual Connectivity enabled
6614 * @return true if dual connectivity is enabled else false
6615 */
6616 @Override
6617 public boolean isNrDualConnectivityEnabled(int subId) {
6618 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006619 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006620 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006621 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006622 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6623 return false;
6624 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006625 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
6628 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6629 null, subId, workSource);
6630 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6631 return isEnabled;
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
6634 }
6635 }
6636
6637 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006638 * Set the allowed network types of the device and
6639 * provide the reason triggering the allowed network change.
6640 *
6641 * @param subId the id of the subscription.
6642 * @param reason the reason the allowed network type change is taking place
6643 * @param allowedNetworkTypes the allowed network types.
6644 * @return true on success; false on any failure.
6645 */
6646 @Override
6647 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006648 @TelephonyManager.AllowedNetworkTypesReason int reason,
6649 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6651 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006652 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006653 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6654 return false;
6655 }
6656 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6657 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006658 return false;
6659 }
6660
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006661 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6662 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6663
6664
6665 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6666 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6667 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006668 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006669
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006670 final long identity = Binder.clearCallingIdentity();
6671 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006672 Boolean success = (Boolean) sendRequest(
6673 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6674 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6675
6676 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6677 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006678 } finally {
6679 Binder.restoreCallingIdentity(identity);
6680 }
6681 }
6682
6683 /**
Miaoa84611c2019-03-15 09:21:10 +08006684 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006685 *
Miaoa84611c2019-03-15 09:21:10 +08006686 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006687 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006688 * @hide
6689 */
6690 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006691 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006694 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 try {
Miaoa84611c2019-03-15 09:21:10 +08006696 if (phone != null) {
6697 return phone.hasMatchedTetherApnSetting();
6698 } else {
6699 return false;
6700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 } finally {
6702 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006703 }
Junda Liu475951f2014-11-07 16:45:03 -08006704 }
6705
6706 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006707 * Get the user enabled state of Mobile Data.
6708 *
6709 * TODO: remove and use isUserDataEnabled.
6710 * This can't be removed now because some vendor codes
6711 * calls through ITelephony directly while they should
6712 * use TelephonyManager.
6713 *
6714 * @return true on enabled
6715 */
6716 @Override
6717 public boolean getDataEnabled(int subId) {
6718 return isUserDataEnabled(subId);
6719 }
6720
6721 /**
6722 * Get whether mobile data is enabled per user setting.
6723 *
6724 * There are other factors deciding whether mobile data is actually enabled, but they are
6725 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006726 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006727 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6728 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006729 *
6730 * @return {@code true} if data is enabled else {@code false}
6731 */
6732 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006733 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006735 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006736 try {
6737 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6738 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006739 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006740 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6741 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006742 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006744 mApp, subId, functionName);
6745
Robert Greenwalt646120a2014-05-23 11:54:03 -07006746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
6750 int phoneId = mSubscriptionController.getPhoneId(subId);
6751 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6752 Phone phone = PhoneFactory.getPhone(phoneId);
6753 if (phone != null) {
6754 boolean retVal = phone.isUserDataEnabled();
6755 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6756 return retVal;
6757 } else {
6758 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6759 return false;
6760 }
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006763 }
6764 }
6765
6766 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006767 * Checks if the device is capable of mobile data by considering whether whether the
6768 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6769 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006770 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006771 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006772 */
6773 @Override
6774 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006775 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006776 try {
6777 try {
6778 mApp.enforceCallingOrSelfPermission(
6779 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006780 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006781 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006782 try {
6783 mApp.enforceCallingOrSelfPermission(
6784 android.Manifest.permission.READ_PHONE_STATE,
6785 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006786 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 mApp.enforceCallingOrSelfPermission(
6788 permission.READ_BASIC_PHONE_STATE, functionName);
6789 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006790 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006791 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006792 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006798 Phone phone = PhoneFactory.getPhone(phoneId);
6799 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006800 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006801 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006802 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 return retVal;
6804 } else {
6805 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6806 return false;
6807 }
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006810 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006811 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006812
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006813 /**
6814 * Check if data is enabled for a specific reason
6815 * @param subId Subscription index
6816 * @param reason the reason the data enable change is taking place
6817 * @return {@code true} if the overall data is enabled; {@code false} if not.
6818 */
6819 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006820 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006821 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006822 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006823 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006824 try {
6825 mApp.enforceCallingOrSelfPermission(
6826 android.Manifest.permission.ACCESS_NETWORK_STATE,
6827 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006828 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006829 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6830 functionName);
6831 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006832 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006833 try {
6834 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006835 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006836 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006838 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006839 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006840 }
6841
6842
6843 final long identity = Binder.clearCallingIdentity();
6844 try {
6845 int phoneId = mSubscriptionController.getPhoneId(subId);
6846 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006847 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006848 + " reason=" + reason);
6849 }
6850 Phone phone = PhoneFactory.getPhone(phoneId);
6851 if (phone != null) {
6852 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006853 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006854 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006855 return retVal;
6856 } else {
6857 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006858 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006859 + subId + " retVal=false");
6860 }
6861 return false;
6862 }
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
6865 }
6866 }
6867
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006868 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006869 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006870 // No permission needed; this only lets the caller inspect their own status.
6871 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006872 }
Junda Liu29340342014-07-10 15:23:27 -07006873
6874 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006875 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006876 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006877 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6878 }
6879
6880 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6881 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006882 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006883 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006884 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6885 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006886 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6887 if (cpt == null) {
6888 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006889 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6890 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006891 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006892 }
6893
6894 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006895 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006896 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006897 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006898 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006899 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006900 Phone phone = getPhone(subId);
6901 if (phone == null) {
6902 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6903 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6904 }
6905 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6906 if (cpt == null) {
6907 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6909 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006910 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006911 }
6912
6913 @Override
6914 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006915 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006916 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6917 }
6918
6919 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006922 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006923 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006924 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6925 Phone phone = PhoneFactory.getPhone(phoneId);
6926 if (phone == null) {
6927 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006928 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006929 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6930 if (cpt == null) {
6931 continue;
6932 }
6933 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006934 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6935 break;
6936 }
6937 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 return result;
Junda Liu29340342014-07-10 15:23:27 -07006939 }
Derek Tan89e89d42014-07-08 17:00:10 -07006940
6941 @Override
Junda Liue64de782015-04-16 17:19:16 -07006942 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006943 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006944 Phone phone = PhoneFactory.getPhone(phoneId);
6945 if (phone == null) {
6946 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006947 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006948 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6949 if (cpt == null) {
6950 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006951 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006952 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006953 }
6954
Amith Yamasani6e118872016-02-19 12:53:51 -08006955 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006956 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006957 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006958 Phone phone = PhoneFactory.getPhone(phoneId);
6959 if (phone == null) {
6960 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006961 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006962 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6963 if (cpt == null) {
6964 return Collections.emptyList();
6965 }
6966 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006967 }
6968
chen xuf7e9fe82019-05-09 19:31:02 -07006969 @Override
6970 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006971 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006972 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006973 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006974 try {
6975 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6976 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6977 }
6978 } finally {
6979 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006980 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006981 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006982 }
6983
Rambo Wang6812ffb2022-03-15 16:54:17 -07006984 @Override
6985 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6986 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6987
6988 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6989 if (phone == null) {
6990 return null;
6991 }
6992 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6993 if (cpt == null) {
6994 return null;
6995 }
6996 return cpt.getCarrierServicePackageName();
6997 }
6998
Wink Savilleb564aae2014-10-23 10:18:09 -07006999 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007000 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007001 UiccPort port = phone == null ? null : phone.getUiccPort();
7002 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007003 return null;
7004 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007005 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007006 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007007 return null;
7008 }
7009 return iccId;
7010 }
7011
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007012 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007013 public void setCallComposerStatus(int subId, int status) {
7014 enforceModifyPermission();
7015
7016 final long identity = Binder.clearCallingIdentity();
7017 try {
7018 Phone phone = getPhone(subId);
7019 if (phone != null) {
7020 Phone defaultPhone = phone.getImsPhone();
7021 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7022 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7023 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007024 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7025 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007026 }
7027 }
Shuo Qian284ae752020-12-22 19:10:14 -08007028 } catch (ImsException e) {
7029 throw new ServiceSpecificException(e.getCode());
7030 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007031 Binder.restoreCallingIdentity(identity);
7032 }
7033 }
7034
7035 @Override
7036 public int getCallComposerStatus(int subId) {
7037 enforceReadPrivilegedPermission("getCallComposerStatus");
7038
7039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 Phone phone = getPhone(subId);
7042 if (phone != null) {
7043 Phone defaultPhone = phone.getImsPhone();
7044 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7045 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7046 return imsPhone.getCallComposerStatus();
7047 }
7048 }
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
7052 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7053 }
7054
7055 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007056 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7057 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007058 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007059 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 final String iccId = getIccId(subId);
7064 final Phone phone = getPhone(subId);
7065 if (phone == null) {
7066 return false;
7067 }
7068 final String subscriberId = phone.getSubscriberId();
7069
7070 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007071 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 + subscriberId + " to " + number);
7073 }
7074
7075 if (TextUtils.isEmpty(iccId)) {
7076 return false;
7077 }
7078
7079 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7080
7081 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7082 if (alphaTag == null) {
7083 editor.remove(alphaTagPrefKey);
7084 } else {
7085 editor.putString(alphaTagPrefKey, alphaTag);
7086 }
7087
7088 // Record both the line number and IMSI for this ICCID, since we need to
7089 // track all merged IMSIs based on line number
7090 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7091 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7092 if (number == null) {
7093 editor.remove(numberPrefKey);
7094 editor.remove(subscriberPrefKey);
7095 } else {
7096 editor.putString(numberPrefKey, number);
7097 editor.putString(subscriberPrefKey, subscriberId);
7098 }
7099
7100 editor.commit();
7101 return true;
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007104 }
Derek Tan7226c842014-07-02 17:42:23 -07007105 }
7106
7107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007108 public String getLine1NumberForDisplay(int subId, String callingPackage,
7109 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007110 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007112 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007113 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007114 return null;
7115 }
Derek Tan97ebb422014-09-05 16:55:38 -07007116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 final long identity = Binder.clearCallingIdentity();
7118 try {
7119 String iccId = getIccId(subId);
7120 if (iccId != null) {
7121 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7122 if (DBG_MERGE) {
7123 log("getLine1NumberForDisplay returning "
7124 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7125 }
7126 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7129 return null;
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007132 }
Derek Tan7226c842014-07-02 17:42:23 -07007133 }
7134
7135 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007136 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7137 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007139 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007140 return null;
7141 }
Derek Tan97ebb422014-09-05 16:55:38 -07007142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 final long identity = Binder.clearCallingIdentity();
7144 try {
7145 String iccId = getIccId(subId);
7146 if (iccId != null) {
7147 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7148 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7149 }
7150 return null;
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007153 }
Derek Tan7226c842014-07-02 17:42:23 -07007154 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007155
7156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007157 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7158 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007159 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7160 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007162 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007164 return null;
7165 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007166
Jordan Liub49b04b2019-05-06 14:45:15 -07007167 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7168 // the process, where TelephonyManager was instantiated.
7169 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007170 final long identity = Binder.clearCallingIdentity();
7171 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007172 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 final TelephonyManager tele = TelephonyManager.from(context);
7174 final SubscriptionManager sub = SubscriptionManager.from(context);
7175
7176 // Figure out what subscribers are currently active
7177 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
Jordan Liub49b04b2019-05-06 14:45:15 -07007179 // Only consider subs which match the current subId
7180 // This logic can be simplified. See b/131189269 for progress.
7181 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007182 activeSubscriberIds.add(tele.getSubscriberId(subId));
7183 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184
7185 // First pass, find a number override for an active subscriber
7186 String mergeNumber = null;
7187 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7188 for (String key : prefs.keySet()) {
7189 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7190 final String subscriberId = (String) prefs.get(key);
7191 if (activeSubscriberIds.contains(subscriberId)) {
7192 final String iccId = key.substring(
7193 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7194 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7195 mergeNumber = (String) prefs.get(numberKey);
7196 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007197 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 + " for active subscriber " + subscriberId);
7199 }
7200 if (!TextUtils.isEmpty(mergeNumber)) {
7201 break;
7202 }
7203 }
7204 }
7205 }
7206
7207 // Shortcut when no active merged subscribers
7208 if (TextUtils.isEmpty(mergeNumber)) {
7209 return null;
7210 }
7211
7212 // Second pass, find all subscribers under that line override
7213 final ArraySet<String> result = new ArraySet<>();
7214 for (String key : prefs.keySet()) {
7215 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7216 final String number = (String) prefs.get(key);
7217 if (mergeNumber.equals(number)) {
7218 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7219 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7220 final String subscriberId = (String) prefs.get(subscriberKey);
7221 if (!TextUtils.isEmpty(subscriberId)) {
7222 result.add(subscriberId);
7223 }
7224 }
7225 }
7226 }
7227
7228 final String[] resultArray = result.toArray(new String[result.size()]);
7229 Arrays.sort(resultArray);
7230 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007231 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7233 }
7234 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007237 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007238 }
7239
7240 @Override
zoey chen38003472019-12-13 17:16:31 +08007241 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7242 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007243
7244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 final TelephonyManager telephonyManager = mApp.getSystemService(
7247 TelephonyManager.class);
7248 String subscriberId = telephonyManager.getSubscriberId(subId);
7249 if (subscriberId == null) {
7250 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007251 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007252 + subId);
7253 }
7254 return null;
7255 }
7256
7257 final SubscriptionInfo info = SubscriptionController.getInstance()
7258 .getSubscriptionInfo(subId);
7259 final ParcelUuid groupUuid = info.getGroupUuid();
7260 // If it doesn't belong to any group, return just subscriberId of itself.
7261 if (groupUuid == null) {
7262 return new String[]{subscriberId};
7263 }
7264
7265 // Get all subscriberIds from the group.
7266 final List<String> mergedSubscriberIds = new ArrayList<>();
7267 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007268 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007269 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007270 for (SubscriptionInfo subInfo : groupInfos) {
7271 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7272 if (subscriberId != null) {
7273 mergedSubscriberIds.add(subscriberId);
7274 }
7275 }
7276
7277 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280
7281 }
7282 }
7283
7284 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007285 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007286 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007287 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288
7289 final long identity = Binder.clearCallingIdentity();
7290 try {
7291 final Phone phone = getPhone(subId);
7292 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007296 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007297
7298 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007299 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007300 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7301 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007302 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7303 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 final Phone phone = getPhone(subId);
7308 if (phone == null) {
7309 return false;
7310 }
7311 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7312 cdmaNonRoamingList);
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007315 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007316 }
7317
7318 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007319 @Deprecated
7320 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7321 enforceModifyPermission();
7322
7323 int returnValue = 0;
7324 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007325 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007326 if(result.exception == null) {
7327 if (result.result != null) {
7328 byte[] responseData = (byte[])(result.result);
7329 if(responseData.length > oemResp.length) {
7330 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7331 responseData.length + "bytes. Buffer Size is " +
7332 oemResp.length + "bytes.");
7333 }
7334 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7335 returnValue = responseData.length;
7336 }
7337 } else {
7338 CommandException ex = (CommandException) result.exception;
7339 returnValue = ex.getCommandError().ordinal();
7340 if(returnValue > 0) returnValue *= -1;
7341 }
7342 } catch (RuntimeException e) {
7343 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7344 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7345 if(returnValue > 0) returnValue *= -1;
7346 }
7347
7348 return returnValue;
7349 }
7350
7351 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007352 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007353 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007354 try {
7355 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007356 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007357 mApp, phone.getSubId(), "getRadioAccessFamily");
7358 } catch (SecurityException e) {
7359 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7360 throw e;
7361 }
chen xub97461a2018-10-26 14:17:57 -07007362 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007363 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007364 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
chen xub97461a2018-10-26 14:17:57 -07007368 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007369 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007370 mApp, phone.getSubId(), "getRadioAccessFamily");
7371 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
chen xub97461a2018-10-26 14:17:57 -07007375 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007376 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007377
7378 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007379 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007380 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007381 try {
7382 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7383 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007384 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007385 }
7386 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007387 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007388 }
7389 RoleManager rm = mApp.getSystemService(RoleManager.class);
7390 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7391 if (!dialerRoleHolders.contains(callingPackage)) {
7392 throw new SecurityException("App must be the dialer role holder to"
7393 + " upload a call composer pic");
7394 }
7395
7396 Executors.newSingleThreadExecutor().execute(() -> {
7397 ByteArrayOutputStream output = new ByteArrayOutputStream(
7398 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7399 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7400 boolean readUntilEnd = false;
7401 int totalBytesRead = 0;
7402 byte[] buffer = new byte[16 * 1024];
7403 while (true) {
7404 int numRead;
7405 try {
7406 numRead = input.read(buffer);
7407 } catch (IOException e) {
7408 try {
7409 fd.checkError();
7410 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7411 null);
7412 } catch (IOException e1) {
7413 // This means that the other side closed explicitly with an error. If this
7414 // happens, log and ignore.
7415 loge("Remote end of call composer picture pipe closed: " + e1);
7416 }
7417 break;
7418 }
7419 if (numRead == -1) {
7420 readUntilEnd = true;
7421 break;
7422 }
7423 totalBytesRead += numRead;
7424 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7425 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7426 try {
7427 input.close();
7428 } catch (IOException e) {
7429 // ignore
7430 }
7431 break;
7432 }
7433 output.write(buffer, 0, numRead);
7434 }
7435 // Generally, the remote end will close the file descriptors. The only case where we
7436 // close is above, where the picture size is too big.
7437
7438 try {
7439 fd.checkError();
7440 } catch (IOException e) {
7441 loge("Remote end for call composer closed with an error: " + e);
7442 return;
7443 }
7444
Hall Liuaa4211e2021-01-20 15:43:39 -08007445 if (!readUntilEnd) {
7446 loge("Did not finish reading entire image; aborting");
7447 return;
7448 }
Hall Liu82694d52020-12-11 18:22:04 -08007449
Hall Liuaa4211e2021-01-20 15:43:39 -08007450 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7451 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7452 new CallComposerPictureTransfer.Factory() {},
7453 imageData,
7454 (result) -> {
7455 if (result.first != null) {
7456 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7457 Bundle outputResult = new Bundle();
7458 outputResult.putParcelable(
7459 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7460 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7461 outputResult);
7462 } else {
7463 callback.send(result.second, null);
7464 }
7465 }
7466 );
Hall Liu82694d52020-12-11 18:22:04 -08007467 });
7468 }
7469
7470 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007471 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007472 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474
7475 final long identity = Binder.clearCallingIdentity();
7476 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007477 ImsManager.getInstance(defaultPhone.getContext(),
7478 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007482 }
7483
7484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007486 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7488 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007489 return false;
7490 }
Svet Ganovb320e182015-04-16 12:30:10 -07007491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 // Check the user preference and the system-level IMS setting. Even if the user has
7495 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7496 // In the long run, we may instead need to check if there exists a connection service
7497 // which can support video calling.
7498 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007499 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 return imsManager.isVtEnabledByPlatform()
7501 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7502 && imsManager.isVtEnabledByUser();
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007506 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007507
Andrew Leea1239f22015-03-02 17:44:07 -08007508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007509 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7510 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007512 mApp, subId, callingPackage, callingFeatureId,
7513 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 return false;
7515 }
7516
7517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 CarrierConfigManager configManager =
7520 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Andrew Leea1239f22015-03-02 17:44:07 -08007526 }
7527
7528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007529 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007531 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 return false;
7533 }
7534
7535 final long identity = Binder.clearCallingIdentity();
7536 try {
7537 CarrierConfigManager configManager =
7538 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7541 } finally {
7542 Binder.restoreCallingIdentity(identity);
7543 }
Andrew Leea1239f22015-03-02 17:44:07 -08007544 }
7545
Andrew Lee9431b832015-03-09 18:46:45 -07007546 @Override
7547 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007548 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007549 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007550 }
7551
7552 @Override
7553 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 final long identity = Binder.clearCallingIdentity();
7555 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007556 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 } finally {
7558 Binder.restoreCallingIdentity(identity);
7559 }
Andrew Lee9431b832015-03-09 18:46:45 -07007560 }
7561
Hall Liuf6668912018-10-31 17:05:23 -07007562 /**
7563 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7564 * support for the feature and device firmware support.
7565 *
7566 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7567 */
7568 @Override
7569 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 final Phone phone = getPhone(subscriptionId);
7572 if (phone == null) {
7573 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7574 return false;
7575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007576 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007577 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7579 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007580 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 return isCarrierSupported && isDeviceSupported;
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
Hall Liu98187582018-01-22 19:15:32 -08007585 }
7586
Hall Liuf6668912018-10-31 17:05:23 -07007587 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007588 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7589 * RTT setting, will return true if the device and carrier both support RTT.
7590 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007591 */
7592 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007595 boolean isRttSupported = isRttSupported(subscriptionId);
7596 boolean isUserRttSettingOn = Settings.Secure.getInt(
7597 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7598 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7599 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7600 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007604 }
7605
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007606 @Deprecated
7607 @Override
7608 public String getDeviceId(String callingPackage) {
7609 return getDeviceIdWithFeature(callingPackage, null);
7610 }
7611
Sanket Padawe7310cc72015-01-14 09:53:20 -08007612 /**
7613 * Returns the unique device ID of phone, for example, the IMEI for
7614 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7615 *
7616 * <p>Requires Permission:
7617 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7618 */
7619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007621 try {
7622 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7623 } catch (SecurityException se) {
7624 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7625 throw new SecurityException("Package " + callingPackage + " does not belong to "
7626 + Binder.getCallingUid());
7627 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007628 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007629 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007630 return null;
7631 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007632 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007633 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007634 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007635 return null;
7636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637
7638 final long identity = Binder.clearCallingIdentity();
7639 try {
7640 return phone.getDeviceId();
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
7643 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007644 }
7645
Ping Sunc67b7c22016-03-02 19:16:45 +08007646 /**
7647 * {@hide}
7648 * Returns the IMS Registration Status on a particular subid
7649 *
7650 * @param subId
7651 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007652 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007653 Phone phone = getPhone(subId);
7654 if (phone != null) {
7655 return phone.isImsRegistered();
7656 } else {
7657 return false;
7658 }
7659 }
7660
Santos Cordon7a1885b2015-02-03 11:15:19 -08007661 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007662 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007663 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007666 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7667 }
7668 final long identity = Binder.clearCallingIdentity();
7669 try {
7670 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
7673 }
7674 }
7675
7676 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007677 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007678 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007679 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007680 mApp,
7681 subscriptionId,
7682 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007683 final long identity = Binder.clearCallingIdentity();
7684 try {
7685 Phone phone = getPhone(subscriptionId);
7686 if (phone == null) {
7687 return null;
7688 }
7689 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
7692 }
7693 }
7694
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007695 /**
7696 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007697 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007698 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 Phone phone = getPhone(subId);
7702 if (phone != null) {
7703 return phone.isWifiCallingEnabled();
7704 } else {
7705 return false;
7706 }
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007710 }
7711
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007712 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007713 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007714 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007715 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 final long identity = Binder.clearCallingIdentity();
7717 try {
7718 Phone phone = getPhone(subId);
7719 if (phone != null) {
7720 return phone.isVideoEnabled();
7721 } else {
7722 return false;
7723 }
7724 } finally {
7725 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007726 }
7727 }
7728
7729 /**
7730 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7731 * defined in {@link ImsRegistrationImplBase}.
7732 */
7733 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734 final long identity = Binder.clearCallingIdentity();
7735 try {
7736 Phone phone = getPhone(subId);
7737 if (phone != null) {
7738 return phone.getImsRegistrationTech();
7739 } else {
7740 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007744 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007745 }
7746
Stuart Scott8eef64f2015-04-08 15:13:54 -07007747 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007748 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007749 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007750 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7751 return;
7752 }
Kai Shif70f46f2021-03-03 13:59:46 -08007753 Phone defaultPhone = getDefaultPhone();
7754 if (defaultPhone != null) {
7755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7756 mApp, getDefaultPhone().getSubId(), "factoryReset");
7757 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007758 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007759
Svet Ganovcc087f82015-05-12 20:35:54 -07007760 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007761 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7762 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007763 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007764 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007765 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007766 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007767 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007769 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007770 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007771 // There has been issues when Sms raw table somehow stores orphan
7772 // fragments. They lead to garbled message when new fragments come
7773 // in and combined with those stale ones. In case this happens again,
7774 // user can reset all network settings which will clean up this table.
7775 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007776 // Clean up IMS settings as well here.
7777 int slotId = getSlotIndex(subId);
7778 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7779 ImsManager.getInstance(mApp, slotId).factoryReset();
7780 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007781
Kai Shif70f46f2021-03-03 13:59:46 -08007782 if (defaultPhone == null) {
7783 return;
7784 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007785 // Erase modem config if erase modem on network setting is enabled.
7786 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7787 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7788 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007789 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007790 }
Kai Shif70f46f2021-03-03 13:59:46 -08007791
7792 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007793 } finally {
7794 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007795 }
7796 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007797
SongFerngWangfd89b102021-05-27 22:44:54 +08007798 @VisibleForTesting
7799 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7800 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7801 return;
7802 }
7803 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7804 RILConstants.PREFERRED_NETWORK_MODE);
7805 SubscriptionManager.setSubscriptionProperty(subId,
7806 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7807 "user=" + defaultNetworkType);
7808 phone.loadAllowedNetworksFromSubscriptionDatabase();
7809 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7810 defaultNetworkType, null);
7811 }
7812
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007813 private void cleanUpSmsRawTable(Context context) {
7814 ContentResolver resolver = context.getContentResolver();
7815 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7816 resolver.delete(uri, null, null);
7817 }
7818
Narayan Kamath1c496c22015-04-16 14:40:19 +01007819 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007820 public String getSimLocaleForSubscriber(int subId) {
7821 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7822 final Phone phone = getPhone(subId);
7823 if (phone == null) {
7824 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007825 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 final long identity = Binder.clearCallingIdentity();
7828 try {
chen xu5d3637b2019-01-21 23:31:38 -08007829 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007830 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007831 if (info == null) {
7832 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7833 return null;
7834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 // Try and fetch the locale from the carrier properties or from the SIM language
7836 // preferences (EF-PL and EF-LI)...
7837 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007839 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7840 if (localeFromDefaultSim != null) {
7841 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7842 if (DBG) log("Using locale from subId: " + subId + " locale: "
7843 + localeFromDefaultSim);
7844 return localeFromDefaultSim.toLanguageTag();
7845 } else {
7846 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 }
7848 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 // The SIM language preferences only store a language (e.g. fr = French), not an
7851 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7852 // the SIM and carrier preferences does not include a country we add the country
7853 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007854 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007855 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007856 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 return mccLocale.toLanguageTag();
7858 }
7859
7860 if (DBG) log("No locale found - returning null");
7861 return null;
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
7864 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007865 }
7866
7867 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007868 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007869 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007870 }
7871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 /**
7873 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7874 */
7875 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007876 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007877 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007878 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007879
Gary Jian3aa9a762022-01-24 16:41:19 +08007880 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7881 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007882
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007883 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007884 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7885 * representing the state of the modem.
7886 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007887 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7888 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007889 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007890 */
7891 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007892 public void requestModemActivityInfo(ResultReceiver result) {
7893 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007898 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899 } finally {
7900 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007901 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007902 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007903
Siddharth Rayb8114062018-06-17 15:02:38 -07007904 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7905 // less than total activity duration.
7906 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7907 if (info == null) {
7908 return false;
7909 }
7910 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007911 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7912 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7913
Siddharth Rayb8114062018-06-17 15:02:38 -07007914 return (info.isValid()
7915 && (info.getSleepTimeMillis() <= activityDurationMs)
7916 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007917 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007918 && (totalTxTimeMs <= activityDurationMs));
7919 }
7920
Gary Jian3aa9a762022-01-24 16:41:19 +08007921 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7922 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7923 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7924 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7925
7926 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7927 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7928 }
7929
7930 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7931 mLastModemActivityInfo.setReceiveTimeMillis(
7932 rat,
7933 freq,
7934 info.getReceiveTimeMillis(rat, freq)
7935 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7936 }
7937
7938 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7939 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7940 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7941 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7942
7943 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7944 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7945 }
7946 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7947 mLastModemActivityInfo.setReceiveTimeMillis(
7948 rat,
7949 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7950 }
7951
7952 /**
7953 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7954 * @param info recent ModemActivityInfo
7955 */
7956 private void mergeModemActivityInfo(ModemActivityInfo info) {
7957 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7958 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7959 boolean matched;
7960 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7961 matched = false;
7962 int rat = info.getSpecificInfoRat(i);
7963 int freq = info.getSpecificInfoFrequencyRange(i);
7964 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7965 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7966 //if it already exists
7967 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7968 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7969 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7970 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7971 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7972 updateLastModemActivityInfo(info, rat, freq);
7973 matched = true;
7974 }
7975 } else {
7976 updateLastModemActivityInfo(info, rat);
7977 matched = true;
7978 }
7979 }
7980 }
7981
7982 if (!matched) {
7983 mDeltaSpecificInfo =
7984 new ActivityStatsTechSpecificInfo(
7985 rat,
7986 freq,
7987 info.getTransmitTimeMillis(rat, freq),
7988 (int) info.getReceiveTimeMillis(rat, freq));
7989 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7990 }
7991 }
7992 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7993 mLastModemActivitySpecificInfo =
7994 new ActivityStatsTechSpecificInfo[merged.size()];
7995 merged.toArray(mLastModemActivitySpecificInfo);
7996
7997 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7998 mLastModemActivityInfo.setSleepTimeMillis(
7999 info.getSleepTimeMillis()
8000 + mLastModemActivityInfo.getSleepTimeMillis());
8001 mLastModemActivityInfo.setIdleTimeMillis(
8002 info.getIdleTimeMillis()
8003 + mLastModemActivityInfo.getIdleTimeMillis());
8004 }
8005
Jack Yu85bd38a2015-11-09 11:34:32 -08008006 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008007 * Returns the service state information on specified subscription.
8008 */
8009 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008010 public ServiceState getServiceStateForSubscriber(int subId,
8011 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8012 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008014 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008015 return null;
8016 }
8017
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008018 boolean hasFinePermission = false;
8019 boolean hasCoarsePermission = false;
8020 if (!renounceFineLocationAccess) {
8021 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8022 LocationAccessPolicy.checkLocationPermission(mApp,
8023 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8024 .setCallingPackage(callingPackage)
8025 .setCallingFeatureId(callingFeatureId)
8026 .setCallingPid(Binder.getCallingPid())
8027 .setCallingUid(Binder.getCallingUid())
8028 .setMethod("getServiceStateForSubscriber")
8029 .setLogAsInfo(true)
8030 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8031 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8032 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8033 .build());
8034 hasFinePermission =
8035 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8036 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008037
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008038 if (!renounceCoarseLocationAccess) {
8039 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8040 LocationAccessPolicy.checkLocationPermission(mApp,
8041 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8042 .setCallingPackage(callingPackage)
8043 .setCallingFeatureId(callingFeatureId)
8044 .setCallingPid(Binder.getCallingPid())
8045 .setCallingUid(Binder.getCallingUid())
8046 .setMethod("getServiceStateForSubscriber")
8047 .setLogAsInfo(true)
8048 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8049 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8050 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8051 .build());
8052 hasCoarsePermission =
8053 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8054 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008055
Jack Yu479f40e2020-10-27 21:29:25 -07008056 final Phone phone = getPhone(subId);
8057 if (phone == null) {
8058 return null;
8059 }
8060
Jordan Liu0f2bc442020-11-18 16:47:37 -08008061 final long identity = Binder.clearCallingIdentity();
8062
Jack Yu479f40e2020-10-27 21:29:25 -07008063 boolean isCallingPackageDataService = phone.getDataServicePackages()
8064 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008066 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8067 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8068 Rlog.d(LOG_TAG,
8069 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8070 return null;
8071 }
8072
Hall Liuf19c44f2018-11-27 14:38:17 -08008073 ServiceState ss = phone.getServiceState();
8074
8075 // Scrub out the location info in ServiceState depending on what level of access
8076 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008077 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008078 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8079 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 } finally {
8081 Binder.restoreCallingIdentity(identity);
8082 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008083 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008084
8085 /**
8086 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8087 *
8088 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8089 * voicemail ringtone.
8090 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8091 * PhoneAccount.
8092 */
8093 @Override
8094 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8098 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008099 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
8105 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008106 }
8107
8108 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008109 * Sets the per-account voicemail ringtone.
8110 *
8111 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8112 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8113 *
8114 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8115 * voicemail ringtone.
8116 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8117 * PhoneAccount.
8118 */
8119 @Override
8120 public void setVoicemailRingtoneUri(String callingPackage,
8121 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008122 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008123 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008124 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8125 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8127 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8128 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008129 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8134 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008135 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 }
8137 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8138 } finally {
8139 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008140 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008141 }
8142
8143 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008144 * Returns whether vibration is set for voicemail notification in Phone settings.
8145 *
8146 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8147 * voicemail vibration setting.
8148 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8149 */
8150 @Override
8151 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8155 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008156 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008159 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008163 }
8164
Youhan Wange64578a2016-05-02 15:32:42 -07008165 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 * Sets the per-account voicemail vibration.
8167 *
8168 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8169 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8170 *
8171 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8172 * voicemail vibration setting.
8173 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8174 * specific PhoneAccount.
8175 */
8176 @Override
8177 public void setVoicemailVibrationEnabled(String callingPackage,
8178 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008179 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008180 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008181 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8182 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8184 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8185 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008186 }
8187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188 final long identity = Binder.clearCallingIdentity();
8189 try {
8190 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8191 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008192 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 }
8194 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8195 } finally {
8196 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008197 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008198 }
8199
8200 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008201 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8202 *
8203 * @throws SecurityException if the caller does not have the required permission
8204 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008205 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008206 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008207 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008208 }
8209
8210 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008211 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8212 * permission.
8213 *
8214 * @throws SecurityException if the caller does not have the required permission
8215 */
8216 private void enforceSendSmsPermission() {
8217 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8218 }
8219
8220 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008221 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008222 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008223 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008224 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008225 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 final long identity = Binder.clearCallingIdentity();
8227 try {
8228 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008229 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 if (componentName == null) {
8231 throw new SecurityException(
8232 "Caller not current active visual voicemail package[null]");
8233 }
8234 String vvmPackage = componentName.getPackageName();
8235 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008236 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 }
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008240 }
8241 }
8242
8243 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008244 * Return the application ID for the app type.
8245 *
8246 * @param subId the subscription ID that this request applies to.
8247 * @param appType the uicc app type.
8248 * @return Application ID for specificied app type, or null if no uicc.
8249 */
8250 @Override
8251 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008252 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008253 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254
8255 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008256 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008257 if (phone == null) {
8258 return null;
8259 }
8260 String aid = null;
8261 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008262 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 .getApplicationByType(appType).getAid();
8264 } catch (Exception e) {
8265 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8266 }
8267 return aid;
8268 } finally {
8269 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008270 }
Youhan Wange64578a2016-05-02 15:32:42 -07008271 }
8272
Youhan Wang4001d252016-05-11 10:29:41 -07008273 /**
8274 * Return the Electronic Serial Number.
8275 *
8276 * @param subId the subscription ID that this request applies to.
8277 * @return ESN or null if error.
8278 */
8279 @Override
8280 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008281 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008282 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008285 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008286 if (phone == null) {
8287 return null;
8288 }
8289 String esn = null;
8290 try {
8291 esn = phone.getEsn();
8292 } catch (Exception e) {
8293 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8294 }
8295 return esn;
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008298 }
Youhan Wang4001d252016-05-11 10:29:41 -07008299 }
8300
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008301 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008302 * Return the Preferred Roaming List Version.
8303 *
8304 * @param subId the subscription ID that this request applies to.
8305 * @return PRLVersion or null if error.
8306 */
8307 @Override
8308 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008309 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008310 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311
8312 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008313 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 if (phone == null) {
8315 return null;
8316 }
8317 String cdmaPrlVersion = null;
8318 try {
8319 cdmaPrlVersion = phone.getCdmaPrlVersion();
8320 } catch (Exception e) {
8321 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8322 }
8323 return cdmaPrlVersion;
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008326 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008327 }
8328
8329 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008330 * Get snapshot of Telephony histograms
8331 * @return List of Telephony histograms
8332 * @hide
8333 */
8334 @Override
8335 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8337 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338
8339 final long identity = Binder.clearCallingIdentity();
8340 try {
8341 return RIL.getTelephonyRILTimingHistograms();
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008345 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008346
8347 /**
8348 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008349 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8350 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008351 * Require system privileges. In the future we may add this to carrier APIs.
8352 *
Michele Berionne482f8202018-11-27 18:57:59 -08008353 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008354 */
8355 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008356 @TelephonyManager.SetCarrierRestrictionResult
8357 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008358 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008360
Michele Berionne482f8202018-11-27 18:57:59 -08008361 if (carrierRestrictionRules == null) {
8362 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008363 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365 final long identity = Binder.clearCallingIdentity();
8366 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008367 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008368 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008372 }
8373
8374 /**
8375 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008376 * Get the allowed carrier list and the excluded carrier list, including the priority between
8377 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008378 * Require system privileges. In the future we may add this to carrier APIs.
8379 *
Michele Berionne482f8202018-11-27 18:57:59 -08008380 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008381 */
8382 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008383 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008384 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008389 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8390 if (response instanceof CarrierRestrictionRules) {
8391 return (CarrierRestrictionRules) response;
8392 }
8393 // Response is an Exception of some kind,
8394 // which is signalled to the user as a NULL retval
8395 return null;
8396 } catch (Exception e) {
8397 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8398 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399 } finally {
8400 Binder.restoreCallingIdentity(identity);
8401 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008402 }
8403
fionaxu59545b42016-05-25 15:53:37 -07008404 /**
fionaxu59545b42016-05-25 15:53:37 -07008405 * Action set from carrier signalling broadcast receivers to enable/disable radio
8406 * @param subId the subscription ID that this action applies to.
8407 * @param enabled control enable or disable radio.
8408 * {@hide}
8409 */
8410 @Override
8411 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8412 enforceModifyPermission();
8413 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414
8415 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008416 if (phone == null) {
8417 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8418 return;
8419 }
8420 try {
8421 phone.carrierActionSetRadioEnabled(enabled);
8422 } catch (Exception e) {
8423 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 } finally {
8425 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008426 }
8427 }
8428
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008429 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008430 * Enable or disable Voice over NR (VoNR)
8431 * @param subId the subscription ID that this action applies to.
8432 * @param enabled enable or disable VoNR.
8433 * @return operation result.
8434 */
8435 @Override
8436 public int setVoNrEnabled(int subId, boolean enabled) {
8437 enforceModifyPermission();
8438 final Phone phone = getPhone(subId);
8439
8440 final long identity = Binder.clearCallingIdentity();
8441 if (phone == null) {
8442 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8443 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8444 }
8445
8446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8447 try {
8448 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8449 workSource);
8450 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008451
8452 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8453 if (DBG) {
8454 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8455 }
8456 SubscriptionManager.setSubscriptionProperty(
8457 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8458 (enabled ? "1" : "0"));
8459 }
8460
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008461 return result;
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
8466
8467 /**
8468 * Is voice over NR enabled
8469 * @return true if VoNR is enabled else false
8470 */
8471 @Override
8472 public boolean isVoNrEnabled(int subId) {
8473 enforceReadPrivilegedPermission("isVoNrEnabled");
8474 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8478 null, subId, workSource);
8479 if (DBG) log("isVoNrEnabled: " + isEnabled);
8480 return isEnabled;
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
8483 }
8484 }
8485
8486 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008487 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8488 * network status based on which carrier apps could apply actions accordingly,
8489 * enable/disable default url handler for example.
8490 *
8491 * @param subId the subscription ID that this action applies to.
8492 * @param report control start/stop reporting the default network status.
8493 * {@hide}
8494 */
8495 @Override
8496 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8497 enforceModifyPermission();
8498 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008499
8500 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008501 if (phone == null) {
8502 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8503 return;
8504 }
8505 try {
8506 phone.carrierActionReportDefaultNetworkStatus(report);
8507 } catch (Exception e) {
8508 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509 } finally {
8510 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008511 }
8512 }
8513
8514 /**
fionaxud9622282017-07-17 17:51:30 -07008515 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8516 * @param subId the subscription ID that this action applies to.
8517 * {@hide}
8518 */
8519 @Override
8520 public void carrierActionResetAll(int subId) {
8521 enforceModifyPermission();
8522 final Phone phone = getPhone(subId);
8523 if (phone == null) {
8524 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8525 return;
8526 }
8527 try {
8528 phone.carrierActionResetAll();
8529 } catch (Exception e) {
8530 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8531 }
8532 }
8533
8534 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008535 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8536 * bug report is being generated.
8537 */
8538 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008539 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008540 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8541 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008542 writer.println("Permission Denial: can't dump Phone from pid="
8543 + Binder.getCallingPid()
8544 + ", uid=" + Binder.getCallingUid()
8545 + "without permission "
8546 + android.Manifest.permission.DUMP);
8547 return;
8548 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008549 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008550 }
Jack Yueb89b242016-06-22 13:27:47 -07008551
Brad Ebingerdac2f002018-04-03 15:17:52 -07008552 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008553 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8554 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8555 @NonNull String[] args) {
8556 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8557 this, in.getFileDescriptor(), out.getFileDescriptor(),
8558 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008559 }
8560
Jack Yueb89b242016-06-22 13:27:47 -07008561 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008562 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008563 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008564 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008565 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008566 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008567 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008568 */
8569 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008570 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008571 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008572 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8573 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8574 try {
8575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008576 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008577 } catch (SecurityException se) {
8578 enforceModifyPermission();
8579 }
8580 } else {
8581 enforceModifyPermission();
8582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583
8584 final long identity = Binder.clearCallingIdentity();
8585 try {
8586 Phone phone = getPhone(subId);
8587 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008588 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8589 phone.carrierActionSetMeteredApnsEnabled(enabled);
8590 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008591 phone.getDataSettingsManager().setDataEnabled(
8592 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594 }
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008597 }
8598 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008599
8600 /**
8601 * Get Client request stats
8602 * @return List of Client Request Stats
8603 * @hide
8604 */
8605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008606 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8607 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008608 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008609 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008610 return null;
8611 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008612 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 if (phone != null) {
8617 return phone.getClientRequestStats();
8618 }
8619
8620 return null;
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008624 }
8625
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008626 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008627 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008628 if (uid == Process.ROOT_UID && packageName == null) {
8629 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8630 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8631 // exception. ROOT_UID seems not to have a valid package name returned by
8632 // PackageManager, so just fake it here to avoid issues when running telephony shell
8633 // commands that plumb through the RIL as root, like so:
8634 // $ adb root
8635 // $ adb shell cmd phone ...
8636 packageName = "root";
8637 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008638 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008639 }
Jack Yueb4124c2017-02-16 15:32:43 -08008640
8641 /**
Grace Chen70990072017-03-24 17:21:30 -07008642 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008643 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008644 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008645 * @param state State of SIM (power down, power up, pass through)
8646 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8647 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8648 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008649 *
8650 **/
8651 @Override
Grace Chen70990072017-03-24 17:21:30 -07008652 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008653 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008654 Phone phone = PhoneFactory.getPhone(slotIndex);
8655
vagdeviaf9a5b92018-08-15 16:01:53 -07008656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008661 phone.setSimPowerState(state, null, workSource);
8662 }
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
8666 }
8667
8668 /**
8669 * Set SIM card power state.
8670 *
8671 * @param slotIndex SIM slot id.
8672 * @param state State of SIM (power down, power up, pass through)
8673 * @param callback callback to trigger after success or failure
8674 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8675 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8676 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8677 *
8678 **/
8679 @Override
8680 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8681 IIntegerConsumer callback) {
8682 enforceModifyPermission();
8683 Phone phone = PhoneFactory.getPhone(slotIndex);
8684
8685 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
8689 if (phone != null) {
8690 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8691 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008692 }
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008695 }
8696 }
Shuo Qiandd210312017-04-12 22:11:33 +00008697
Tyler Gunn65d45c22017-06-05 11:22:26 -07008698 private boolean isUssdApiAllowed(int subId) {
8699 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008700 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008701 if (configManager == null) {
8702 return false;
8703 }
8704 PersistableBundle pb = configManager.getConfigForSubId(subId);
8705 if (pb == null) {
8706 return false;
8707 }
8708 return pb.getBoolean(
8709 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8710 }
8711
Shuo Qiandd210312017-04-12 22:11:33 +00008712 /**
8713 * Check if phone is in emergency callback mode
8714 * @return true if phone is in emergency callback mode
8715 * @param subId sub id
8716 */
goneil9c5f4872017-12-05 14:07:56 -08008717 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008718 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008719 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008720 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008721
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
8724 if (phone != null) {
8725 return phone.isInEcm();
8726 } else {
8727 return false;
8728 }
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008731 }
8732 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008733
8734 /**
8735 * Get the current signal strength information for the given subscription.
8736 * Because this information is not updated when the device is in a low power state
8737 * it should not be relied-upon to be current.
8738 * @param subId Subscription index
8739 * @return the most recent cached signal strength info from the modem
8740 */
8741 @Override
8742 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 Phone p = getPhone(subId);
8746 if (p == null) {
8747 return null;
8748 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 return p.getSignalStrength();
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008754 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008755
Pengquan Meng77b7f132018-08-22 14:49:57 -07008756 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008757 * Get the current modem radio state for the given slot.
8758 * @param slotIndex slot index.
8759 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008760 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008761 * @return the current radio power state from the modem
8762 */
8763 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008764 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008765 Phone phone = PhoneFactory.getPhone(slotIndex);
8766 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8768 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008769 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8770 }
8771
8772 final long identity = Binder.clearCallingIdentity();
8773 try {
8774 return phone.getRadioPowerState();
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
8777 }
8778 }
8779 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8780 }
8781
8782 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008783 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8784 *
8785 * <p>Requires one of the following permissions:
8786 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008787 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008788 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8789 * privileges.
8790 *
8791 * @param subId subscription id
8792 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8793 * {@code false}.
8794 */
8795 @Override
8796 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008797 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008798 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008799 try {
8800 mApp.enforceCallingOrSelfPermission(
8801 android.Manifest.permission.ACCESS_NETWORK_STATE,
8802 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008803 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008804 mApp.enforceCallingOrSelfPermission(
8805 permission.READ_BASIC_PHONE_STATE, functionName);
8806 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008807 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008808 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008809 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008810 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008811
Pengquan Menga1bb6272018-09-06 09:59:22 -07008812 boolean isEnabled = false;
8813 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008814 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008815 Phone phone = getPhone(subId);
8816 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008817 } finally {
8818 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008819 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008820 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008821 }
8822
8823
8824 /**
8825 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8826 *
8827 * <p> Requires permission:
8828 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8829 * privileges.
8830 *
8831 * @param subId subscription id
8832 * @param isEnabled {@code true} means enable, {@code false} means disable.
8833 */
8834 @Override
8835 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8837 mApp, subId, "setDataRoamingEnabled");
8838
Pengquan Menga1bb6272018-09-06 09:59:22 -07008839 final long identity = Binder.clearCallingIdentity();
8840 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008841 Phone phone = getPhone(subId);
8842 if (phone != null) {
8843 phone.setDataRoamingEnabled(isEnabled);
8844 }
8845 } finally {
8846 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008847 }
8848 }
8849
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008850 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008851 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008852 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008853 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008854 mApp, subId, "isManualNetworkSelectionAllowed");
8855
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008856 boolean isAllowed = true;
8857 final long identity = Binder.clearCallingIdentity();
8858 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008859 Phone phone = getPhone(subId);
8860 if (phone != null) {
8861 isAllowed = phone.isCspPlmnEnabled();
8862 }
8863 } finally {
8864 Binder.restoreCallingIdentity(identity);
8865 }
8866 return isAllowed;
8867 }
8868
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008869 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8870 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008871 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008872 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008873 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008874 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8875 if (phone == null) {
8876 return false;
8877 }
8878 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8879 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8880 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008881 }
8882
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008883 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008884 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008885 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008886 mApp.getSystemService(AppOpsManager.class)
8887 .checkPackage(Binder.getCallingUid(), callingPackage);
8888
Jordan Liu1e142fc2019-04-22 15:10:43 -07008889 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008890 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008891 try {
8892 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008893 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008894 } catch (SecurityException e) {
8895 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8896 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008897 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008898 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008899 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008900 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008901 }
sandeepjsb6c87872021-09-27 15:34:44 +00008902 // checking compatibility, if calling app's target SDK is T and beyond.
8903 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8904 Binder.getCallingUid())) {
8905 isIccIdAccessRestricted = true;
8906 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008907 final long identity = Binder.clearCallingIdentity();
8908 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008909 UiccController uiccController = UiccController.getInstance();
8910 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008911 if (hasReadPermission) {
8912 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008913 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008914
8915 // Remove private info if the caller doesn't have access
8916 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8917 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008918 //setting the value after compatibility check
8919 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008920 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8921 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008922 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008923 if (card == null) {
8924 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008925 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008926 continue;
8927 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008928 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8929 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008930 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008931 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008932 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008933 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8934 for (UiccPortInfo portInfo : portInfos) {
8935 UiccPort port = uiccController.getUiccPortForSlot(
8936 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8937 if (port == null) {
8938 // assume no access if port is null
8939 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8940 continue;
8941 }
8942 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8943 uiccPortInfos.add(portInfo);
8944 } else {
8945 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8946 }
8947 }
8948 filteredInfos.add(new UiccCardInfo(
8949 cardInfo.isEuicc(),
8950 cardInfo.getCardId(),
8951 null,
8952 cardInfo.getPhysicalSlotIndex(),
8953 cardInfo.isRemovable(),
8954 cardInfo.isMultipleEnabledProfilesSupported(),
8955 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008956 }
8957 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008958 } finally {
8959 Binder.restoreCallingIdentity(identity);
8960 }
8961 }
8962
sandeepjsb6c87872021-09-27 15:34:44 +00008963 /**
8964 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8965 * generally private and require carrier privileges to view.
8966 *
8967 * @hide
8968 */
8969 @NonNull
8970 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8971 List<UiccPortInfo> portinfo = new ArrayList<>();
8972 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8973 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8974 }
8975 return new UiccCardInfo(
8976 cardInfo.isEuicc(),
8977 cardInfo.getCardId(),
8978 null,
8979 cardInfo.getPhysicalSlotIndex(),
8980 cardInfo.isRemovable(),
8981 cardInfo.isMultipleEnabledProfilesSupported(),
8982 portinfo
8983 );
8984 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008985
sandeepjsb6c87872021-09-27 15:34:44 +00008986 /**
8987 * @hide
8988 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8989 * These values are generally private and require carrier privileges to view.
8990 */
8991 @NonNull
8992 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8993 return new UiccPortInfo(
8994 UiccPortInfo.ICCID_REDACTED,
8995 portInfo.getPortIndex(),
8996 portInfo.getLogicalSlotIndex(),
8997 portInfo.isActive()
8998 );
8999 }
9000 @Override
9001 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009002 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009003 mApp.getSystemService(AppOpsManager.class)
9004 .checkPackage(Binder.getCallingUid(), callingPackage);
9005
sandeepjsb6c87872021-09-27 15:34:44 +00009006 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009007
Aman Guptaf3c90b32022-03-17 04:54:16 +00009008 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9009 // we are reading iccId which is PII data.
9010 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009011
9012 // checking compatibility, if calling app's target SDK is T and beyond.
9013 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9014 Binder.getCallingUid())) {
9015 isLogicalSlotAccessRestricted = true;
9016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009017 final long identity = Binder.clearCallingIdentity();
9018 try {
9019 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009020 if (slots == null || slots.length == 0) {
9021 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009022 return null;
9023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9025 for (int i = 0; i < slots.length; i++) {
9026 UiccSlot slot = slots[i];
9027 if (slot == null) {
9028 continue;
9029 }
9030
Jordan Liu7be7e652019-05-06 18:55:02 +00009031 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 UiccCard card = slot.getUiccCard();
9033 if (card != null) {
9034 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009035 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009036 cardId = slot.getEid();
9037 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009038 // If cardId is null, use iccId of default port as cardId.
9039 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 }
9042
Jordan Liu857451f2019-05-09 16:35:35 -07009043 if (cardId != null) {
9044 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9045 // if cardId is an EID, it's all digits so this is fine
9046 cardId = IccUtils.stripTrailingFs(cardId);
9047 }
9048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 int cardState = 0;
9050 switch (slot.getCardState()) {
9051 case CARDSTATE_ABSENT:
9052 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9053 break;
9054 case CARDSTATE_PRESENT:
9055 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9056 break;
9057 case CARDSTATE_ERROR:
9058 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9059 break;
9060 case CARDSTATE_RESTRICTED:
9061 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9062 break;
9063 default:
9064 break;
9065
9066 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009067 List<UiccPortInfo> portInfos = new ArrayList<>();
9068 int[] portIndexes = slot.getPortList();
9069 for (int portIdx : portIndexes) {
9070 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009071 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009072 portInfos.add(new UiccPortInfo(iccId, portIdx,
9073 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009076 slot.isEuicc(),
9077 cardId,
9078 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009079 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009080 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009081 //setting the value after compatibility check
9082 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009083 }
9084 return infos;
9085 } finally {
9086 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009087 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009088 }
9089
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009090 /* Returns null if doesn't have read permission or carrier privilege access. */
9091 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9092 boolean hasReadPermission) {
9093 String iccId = slot.getIccId(portIndex);
9094 if (hasReadPermission) { // if has read permission
9095 return iccId;
9096 } else {
9097 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9098 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9099 // if no read permission, checking carrier privilege access
9100 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9101 return iccId;
9102 }
9103 }
9104 }
9105 // No read permission or carrier privilege access.
9106 return UiccPortInfo.ICCID_REDACTED;
9107 }
9108
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009109 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009110 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009111 public boolean switchSlots(int[] physicalSlots) {
9112 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009113
9114 final long identity = Binder.clearCallingIdentity();
9115 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009116 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9117 for (int i = 0; i < physicalSlots.length; i++) {
9118 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9119 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9120 physicalSlots[i], i));
9121 }
9122 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009123 } finally {
9124 Binder.restoreCallingIdentity(identity);
9125 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009126 }
Jack Yu4c988042018-02-27 15:30:01 -08009127
9128 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009129 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9130 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9131 enforceModifyPermission();
9132
9133 final long identity = Binder.clearCallingIdentity();
9134 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009135 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009136 } finally {
9137 Binder.restoreCallingIdentity(identity);
9138 }
9139 }
9140
9141 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009142 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 return UiccController.getInstance().getCardIdForDefaultEuicc();
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
Pengquan Meng85728fb2018-03-12 16:31:21 -07009151 /**
goneil47ffb6e2018-04-06 15:40:58 -07009152 * A test API to reload the UICC profile.
9153 *
9154 * <p>Requires that the calling app has permission
9155 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9156 * @hide
9157 */
9158 @Override
9159 public void refreshUiccProfile(int subId) {
9160 enforceModifyPermission();
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 Phone phone = getPhone(subId);
9165 if (phone == null) {
9166 return;
9167 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009168 UiccPort uiccPort = phone.getUiccPort();
9169 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009170 return;
9171 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009172 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009173 if (uiccProfile == null) {
9174 return;
9175 }
9176 uiccProfile.refresh();
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
9181
9182 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009183 * Returns false if the mobile data is disabled by default, otherwise return true.
9184 */
9185 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009186 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009187 }
9188
9189 /**
9190 * Returns true if the data roaming is enabled by default, i.e the system property
9191 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9192 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9193 */
9194 private boolean getDefaultDataRoamingEnabled(int subId) {
9195 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009196 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009197 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009198 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9199 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9200 return isDataRoamingEnabled;
9201 }
9202
9203 /**
9204 * Returns the default network type for the given {@code subId}, if the default network type is
9205 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9206 */
9207 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009208 List<Integer> list = TelephonyProperties.default_network();
9209 int phoneId = mSubscriptionController.getPhoneId(subId);
9210 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9211 return list.get(phoneId);
9212 }
9213 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009214 }
fionaxua13278b2018-03-21 00:08:13 -07009215
9216 @Override
9217 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009218 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 final Phone phone = getPhone(subId);
9224 if (phone == null) {
9225 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9226 return;
9227 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009228 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9229 if (cpt != null) {
9230 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9231 }
9232 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009233 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9234 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009235 if (carrierPrivilegeRules == null) {
9236 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9237 } else {
9238 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009240 } finally {
9241 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009242 }
fionaxua13278b2018-03-21 00:08:13 -07009243 }
9244
9245 @Override
9246 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009247 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 final Phone phone = getPhone(subId);
9252 if (phone == null) {
9253 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9254 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9255 }
9256 return phone.getCarrierIdListVersion();
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009259 }
fionaxua13278b2018-03-21 00:08:13 -07009260 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009261
9262 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009263 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9264 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009266 mApp, subId, callingPackage, callingFeatureId,
9267 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009268 return -1;
9269 }
9270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009278
9279 @Override
9280 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009281 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009282 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009283 mApp, subId, "getCdmaRoamingMode");
9284
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
9293 @Override
9294 public boolean setCdmaRoamingMode(int subId, int mode) {
9295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9296 mApp, subId, "setCdmaRoamingMode");
9297
9298 final long identity = Binder.clearCallingIdentity();
9299 try {
9300 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9301 } finally {
9302 Binder.restoreCallingIdentity(identity);
9303 }
9304 }
9305
9306 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009307 public int getCdmaSubscriptionMode(int subId) {
9308 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009309 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009310 mApp, subId, "getCdmaSubscriptionMode");
9311
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
9314 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
9319
9320 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009321 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9323 mApp, subId, "setCdmaSubscriptionMode");
9324
9325 final long identity = Binder.clearCallingIdentity();
9326 try {
9327 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009332
sqianc5eccab2018-10-19 18:46:41 -07009333 @Override
sqian8c685422019-02-22 15:55:18 -08009334 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009335 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009337 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9338 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009339 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9340 }
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
sqian854d44b2018-12-12 16:48:18 -08009343 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9344 for (Phone phone: PhoneFactory.getPhones()) {
9345 if (phone.getEmergencyNumberTracker() != null
9346 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9347 emergencyNumberListInternal.put(
9348 phone.getSubId(),
9349 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9350 }
sqian11b7a0e2018-12-05 18:48:28 -08009351 }
sqian854d44b2018-12-12 16:48:18 -08009352 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
sqianc5eccab2018-10-19 18:46:41 -07009356 }
9357
9358 @Override
sqian8c685422019-02-22 15:55:18 -08009359 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009360 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009361 if (!exactMatch) {
9362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009364 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009365 }
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
sqian854d44b2018-12-12 16:48:18 -08009368 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009369 //Note: we ignore passed in param exactMatch. We can remove it once
9370 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009371 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009372 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009373 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009374 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009375 }
sqian11b7a0e2018-12-05 18:48:28 -08009376 }
9377 return false;
9378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
9381 }
9382
sqianf4ca7ed2019-01-15 18:32:07 -08009383 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009384 * Start emergency callback mode for GsmCdmaPhone for testing.
9385 */
9386 @Override
9387 public void startEmergencyCallbackMode() {
9388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9389 "startEmergencyCallbackMode");
9390 enforceModifyPermission();
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 for (Phone phone : PhoneFactory.getPhones()) {
9394 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9395 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9396 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9397 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9398 gsmCdmaPhone.obtainMessage(
9399 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9400 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9401 }
9402 }
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
9408 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009409 * Update emergency number list for test mode.
9410 */
9411 @Override
9412 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9414 "updateEmergencyNumberListTestMode");
9415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 for (Phone phone: PhoneFactory.getPhones()) {
9419 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9420 if (tracker != null) {
9421 tracker.executeEmergencyNumberTestModeCommand(action, num);
9422 }
9423 }
9424 } finally {
9425 Binder.restoreCallingIdentity(identity);
9426 }
9427 }
9428
9429 /**
9430 * Get the full emergency number list for test mode.
9431 */
9432 @Override
9433 public List<String> getEmergencyNumberListTestMode() {
9434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9435 "getEmergencyNumberListTestMode");
9436
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
9439 Set<String> emergencyNumbers = new HashSet<>();
9440 for (Phone phone: PhoneFactory.getPhones()) {
9441 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9442 if (tracker != null) {
9443 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9444 emergencyNumbers.add(num.getNumber());
9445 }
9446 }
9447 }
9448 return new ArrayList<>(emergencyNumbers);
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
chen xud6b45bd2018-10-30 22:27:10 -07009454 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009455 public int getEmergencyNumberDbVersion(int subId) {
9456 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9457
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
9460 final Phone phone = getPhone(subId);
9461 if (phone == null) {
9462 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9463 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9464 }
9465 return phone.getEmergencyNumberDbVersion();
9466 } finally {
9467 Binder.restoreCallingIdentity(identity);
9468 }
9469 }
9470
9471 @Override
9472 public void notifyOtaEmergencyNumberDbInstalled() {
9473 enforceModifyPermission();
9474
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
9477 for (Phone phone: PhoneFactory.getPhones()) {
9478 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9479 if (tracker != null) {
9480 tracker.updateOtaEmergencyNumberDatabase();
9481 }
9482 }
9483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
9488 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009489 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009490 enforceActiveEmergencySessionPermission();
9491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 for (Phone phone: PhoneFactory.getPhones()) {
9495 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9496 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009497 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9498 }
9499 }
9500 } finally {
9501 Binder.restoreCallingIdentity(identity);
9502 }
9503 }
9504
9505 @Override
9506 public void resetOtaEmergencyNumberDbFilePath() {
9507 enforceActiveEmergencySessionPermission();
9508
9509 final long identity = Binder.clearCallingIdentity();
9510 try {
9511 for (Phone phone: PhoneFactory.getPhones()) {
9512 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9513 if (tracker != null) {
9514 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009515 }
9516 }
9517 } finally {
9518 Binder.restoreCallingIdentity(identity);
9519 }
9520 }
9521
9522 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009523 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9524 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9525 Phone phone = getPhone(subId);
9526 if (phone == null) {
9527 return null;
9528 }
9529 final long identity = Binder.clearCallingIdentity();
9530 try {
9531 UiccProfile profile = UiccController.getInstance()
9532 .getUiccProfileForPhone(phone.getPhoneId());
9533 if (profile != null) {
9534 return profile.getCertsFromCarrierPrivilegeAccessRules();
9535 }
9536 } finally {
9537 Binder.restoreCallingIdentity(identity);
9538 }
9539 return null;
9540 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009541
9542 /**
9543 * Enable or disable a modem stack.
9544 */
9545 @Override
9546 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9547 enforceModifyPermission();
9548
9549 final long identity = Binder.clearCallingIdentity();
9550 try {
9551 Phone phone = PhoneFactory.getPhone(slotIndex);
9552 if (phone == null) {
9553 return false;
9554 } else {
9555 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9556 }
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 }
Michelecea4cf22018-12-21 15:00:11 -08009561
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009562 /**
9563 * Whether a modem stack is enabled or not.
9564 */
9565 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009566 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9567 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009568 Phone phone = PhoneFactory.getPhone(slotIndex);
9569 if (phone == null) return false;
9570
9571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009572 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9573 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009574 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9575 }
9576
9577 final long identity = Binder.clearCallingIdentity();
9578 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009579 try {
9580 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9581 } catch (NoSuchElementException ex) {
9582 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9583 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588
Michelecea4cf22018-12-21 15:00:11 -08009589 @Override
Michele0ea7d782019-03-19 14:58:42 -07009590 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009591 enforceModifyPermission();
9592
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
9595 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009596 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009597 .commit();
9598 } finally {
9599 Binder.restoreCallingIdentity(identity);
9600 }
9601 }
9602
9603 @Override
Michele0ea7d782019-03-19 14:58:42 -07009604 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009605 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009607 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9608 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009609 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009610 }
Michelecea4cf22018-12-21 15:00:11 -08009611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
Michele0ea7d782019-03-19 14:58:42 -07009614 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009619
Michele0ea7d782019-03-19 14:58:42 -07009620 @TelephonyManager.IsMultiSimSupportedResult
9621 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009622 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9623 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9624 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009625 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9626 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009627 }
9628 // Check if the hardware supports multisim functionality. If usage of multisim is not
9629 // supported by the modem, indicate that it is restricted.
9630 PhoneCapability staticCapability =
9631 mPhoneConfigurationManager.getStaticPhoneCapability();
9632 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009633 loge("isMultiSimSupportedInternal: no static configuration available");
9634 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009635 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009636 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009637 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9638 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009639 }
9640 // Check if support of multiple SIMs is restricted by carrier
9641 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009642 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009643 }
9644
Michele0ea7d782019-03-19 14:58:42 -07009645 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009646 }
9647
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009648 /**
9649 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009650 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9651 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9652 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009653 * @param numOfSims number of active sims we want to switch to
9654 */
9655 @Override
9656 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009657 if (numOfSims == 1) {
9658 enforceModifyPermission();
9659 } else {
9660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9661 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9662 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009663 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009664
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009665 try {
Michele30b57b22019-03-01 12:01:14 -08009666 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009667 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009668 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9669 return;
9670 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009671 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009677 @Override
9678 public boolean isApplicationOnUicc(int subId, int appType) {
9679 enforceReadPrivilegedPermission("isApplicationOnUicc");
9680 Phone phone = getPhone(subId);
9681 if (phone == null) {
9682 return false;
9683 }
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009686 UiccPort uiccPort = phone.getUiccPort();
9687 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009688 return false;
9689 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009690 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009691 if (uiccProfile == null) {
9692 return false;
9693 }
9694 if (TelephonyManager.APPTYPE_SIM <= appType
9695 && appType <= TelephonyManager.APPTYPE_ISIM) {
9696 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9697 }
9698 return false;
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702 }
9703
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009704 /**
chen xub4baa772019-04-03 10:23:41 -07009705 * Get whether making changes to modem configurations will trigger reboot.
9706 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009707 */
9708 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009709 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9710 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009712 mApp, subId, callingPackage, callingFeatureId,
9713 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009714 return false;
9715 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009716 final long identity = Binder.clearCallingIdentity();
9717 try {
9718 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9719 } finally {
9720 Binder.restoreCallingIdentity(identity);
9721 }
9722 }
9723
Nathan Harold29f5f052019-02-15 13:41:57 -08009724 private void updateModemStateMetrics() {
9725 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9726 // TODO: check the state for each modem if the api is ready.
9727 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9728 }
9729
Pengquan Meng3889a572019-01-23 11:16:29 -08009730 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009731 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009732 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009733 // Verify that the callingPackage belongs to the calling UID
9734 mApp.getSystemService(AppOpsManager.class)
9735 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009736 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009737 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009738 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009739 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9740 if (slotInfos != null) {
9741 for (int i = 0; i < slotInfos.length; i++) {
9742 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9743 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9744 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9745 portInfo.getLogicalSlotIndex()));
9746 }
9747 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009748 }
9749 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009750 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009755
9756 /**
9757 * Get the IRadio HAL Version
9758 */
9759 @Override
9760 public int getRadioHalVersion() {
9761 Phone phone = getDefaultPhone();
9762 if (phone == null) return -1;
9763 HalVersion hv = phone.getHalVersion();
9764 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9765 return hv.major * 100 + hv.minor;
9766 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009767
9768 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009769 * Get the current calling package name.
9770 * @return the current calling package name
9771 */
9772 @Override
9773 public String getCurrentPackageName() {
9774 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9775 }
9776
9777 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009778 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9779 * corresponding network requests on a subId.
9780 *
9781 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009782 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009783 * 2) APN is un-metered for this subscription, or
9784 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009785 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009786 *
9787 * @return whether data is allowed for a apn type.
9788 *
9789 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009790 */
9791 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009792 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009793 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9794 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009795
9796 // Now that all security checks passes, perform the operation as ourselves.
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 Phone phone = getPhone(subId);
9800 if (phone == null) return false;
9801
Jack Yu27422a52022-03-21 10:38:05 -07009802 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009803 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009804 isMetered = phone.getDataNetworkController().getDataConfigManager()
9805 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9806 phone.getServiceState().getDataRoaming());
9807 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009808 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009815 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009816 enforceReadPrivilegedPermission("isApnMetered");
9817
9818 // Now that all security checks passes, perform the operation as ourselves.
9819 final long identity = Binder.clearCallingIdentity();
9820 try {
9821 Phone phone = getPhone(subId);
9822 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009823 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9824 DataUtils.apnTypeToNetworkCapability(apnType),
9825 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009830
9831 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009832 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9833 int subscriptionId, IBooleanConsumer resultCallback) {
9834 enforceModifyPermission();
9835 long token = Binder.clearCallingIdentity();
9836 try {
9837 Phone phone = getPhone(subscriptionId);
9838 if (phone == null) {
9839 try {
9840 if (resultCallback != null) {
9841 resultCallback.accept(false);
9842 }
9843 } catch (RemoteException e) {
9844 // ignore
9845 }
9846 return;
9847 }
9848 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9849 Pair.create(specifiers, (x) -> {
9850 try {
9851 if (resultCallback != null) {
9852 resultCallback.accept(x);
9853 }
9854 } catch (RemoteException e) {
9855 // ignore
9856 }
9857 });
9858 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9859 } finally {
9860 Binder.restoreCallingIdentity(token);
9861 }
9862 }
9863
9864 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009865 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9866 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009867 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009868 mApp, subId, "getSystemSelectionChannels");
9869 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9870 final long identity = Binder.clearCallingIdentity();
9871 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009872 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9873 if (result instanceof IllegalStateException) {
9874 throw (IllegalStateException) result;
9875 }
9876 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009877 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9878 return specifiers;
9879 } finally {
9880 Binder.restoreCallingIdentity(identity);
9881 }
9882 }
9883
9884 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009885 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009886 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009887 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009888 }
9889
9890 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009891 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9892 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009893 if (callingPackage == null) {
9894 callingPackage = getCurrentPackageName();
9895 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009896 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9897 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009898 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9899 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009900 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9901 }
9902 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9903 Intent intent = new Intent();
9904 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9905 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9906 // Bring up choose default SMS subscription dialog right now
9907 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9908 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9909 mApp.startActivity(intent);
9910 }
chen xud5ca2d52019-05-28 15:20:57 -07009911
9912 @Override
9913 public String getMmsUAProfUrl(int subId) {
9914 //TODO investigate if this API should require proper permission check in R b/133791609
9915 final long identity = Binder.clearCallingIdentity();
9916 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009917 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9918 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9919 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9920 return carrierUAProfUrl;
9921 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009922 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9923 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009924 } finally {
9925 Binder.restoreCallingIdentity(identity);
9926 }
9927 }
9928
9929 @Override
9930 public String getMmsUserAgent(int subId) {
9931 //TODO investigate if this API should require proper permission check in R b/133791609
9932 final long identity = Binder.clearCallingIdentity();
9933 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009934 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9935 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9936 if (!TextUtils.isEmpty(carrierUserAgent)) {
9937 return carrierUserAgent;
9938 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009939 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9940 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009941 } finally {
9942 Binder.restoreCallingIdentity(identity);
9943 }
9944 }
Jack Yub07d4972019-05-28 16:12:25 -07009945
9946 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009947 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9948 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009949
Jack Yub07d4972019-05-28 16:12:25 -07009950 final long identity = Binder.clearCallingIdentity();
9951 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009952 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009953 if (phone == null) return false;
9954
Hall Liua62f5da2020-09-25 10:42:19 -07009955 switch (policy) {
9956 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu7968c6d2022-07-31 00:43:21 -07009957 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
Hall Liua62f5da2020-09-25 10:42:19 -07009958 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu7968c6d2022-07-31 00:43:21 -07009959 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
Hall Liua62f5da2020-09-25 10:42:19 -07009960 default:
9961 throw new IllegalArgumentException(policy + " is not a valid policy");
9962 }
Jack Yub07d4972019-05-28 16:12:25 -07009963 } finally {
9964 Binder.restoreCallingIdentity(identity);
9965 }
9966 }
9967
9968 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009969 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009970 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009971 enforceModifyPermission();
9972
changbettyd5c246e2019-12-24 15:40:37 +08009973 final long identity = Binder.clearCallingIdentity();
9974 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009975 Phone phone = getPhone(subscriptionId);
9976 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009977
Hall Liua62f5da2020-09-25 10:42:19 -07009978 switch (policy) {
9979 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yu7968c6d2022-07-31 00:43:21 -07009980 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009981 break;
9982 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yu7968c6d2022-07-31 00:43:21 -07009983 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
Hall Liua62f5da2020-09-25 10:42:19 -07009984 break;
9985 default:
9986 throw new IllegalArgumentException(policy + " is not a valid policy");
9987 }
changbettyd5c246e2019-12-24 15:40:37 +08009988 } finally {
9989 Binder.restoreCallingIdentity(identity);
9990 }
9991 }
9992
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009993 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009994 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009995 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9996 * otherwise.
9997 */
9998 @Override
9999 public void setCepEnabled(boolean isCepEnabled) {
10000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10001
10002 final long identity = Binder.clearCallingIdentity();
10003 try {
10004 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10005 for (Phone phone : PhoneFactory.getPhones()) {
10006 Phone defaultPhone = phone.getImsPhone();
10007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10009 ImsPhoneCallTracker imsPhoneCallTracker =
10010 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10011 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10012 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10013 + imsPhone.getMsisdn());
10014 }
10015 }
10016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
allenwtsu46dcc572020-01-08 18:24:03 +080010020
10021 /**
10022 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10023 *
10024 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10025 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10026 * before being read.
10027 */
10028 @Override
10029 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10030 isCompressed) {
10031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10032 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10034 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10035 }
10036 if (!isImsAvailableOnDevice()) {
10037 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10038 "IMS not available on device.");
10039 }
10040
10041 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010042 try {
Hui Wang761a6682020-10-31 05:12:53 +000010043 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010046 }
10047 }
zoey chene02881a2019-12-30 16:11:23 +080010048
10049 @Override
10050 public boolean isIccLockEnabled(int subId) {
10051 enforceReadPrivilegedPermission("isIccLockEnabled");
10052
10053 // Now that all security checks passes, perform the operation as ourselves.
10054 final long identity = Binder.clearCallingIdentity();
10055 try {
10056 Phone phone = getPhone(subId);
10057 if (phone != null && phone.getIccCard() != null) {
10058 return phone.getIccCard().getIccLockEnabled();
10059 } else {
10060 return false;
10061 }
10062 } finally {
10063 Binder.restoreCallingIdentity(identity);
10064 }
10065 }
10066
10067 /**
10068 * Set the ICC pin lock enabled or disabled.
10069 *
10070 * @return an integer representing the status of IccLock enabled or disabled in the following
10071 * three cases:
10072 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10073 * successfully.
10074 * - Positive number and zero for remaining password attempts.
10075 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10076 *
10077 */
10078 @Override
10079 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10080 enforceModifyPermission();
10081
10082 Phone phone = getPhone(subId);
10083 if (phone == null) {
10084 return 0;
10085 }
10086 // Now that all security checks passes, perform the operation as ourselves.
10087 final long identity = Binder.clearCallingIdentity();
10088 try {
10089 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10090 new Pair<Boolean, String>(enabled, password), phone, null);
10091 return attemptsRemaining;
10092
10093 } catch (Exception e) {
10094 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 return 0;
10099 }
10100
10101 /**
10102 * Change the ICC password used in ICC pin lock.
10103 *
10104 * @return an integer representing the status of IccLock changed in the following three cases:
10105 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10106 * - Positive number and zero for remaining password attempts.
10107 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10108 *
10109 */
10110 @Override
10111 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10112 enforceModifyPermission();
10113
10114 Phone phone = getPhone(subId);
10115 if (phone == null) {
10116 return 0;
10117 }
10118 // Now that all security checks passes, perform the operation as ourselves.
10119 final long identity = Binder.clearCallingIdentity();
10120 try {
10121 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10122 new Pair<String, String>(oldPassword, newPassword), phone, null);
10123 return attemptsRemaining;
10124
10125 } catch (Exception e) {
10126 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 return 0;
10131 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010132
10133 /**
10134 * Request for receiving user activity notification
10135 */
10136 @Override
10137 public void requestUserActivityNotification() {
10138 if (!mNotifyUserActivity.get()
10139 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10140 mNotifyUserActivity.set(true);
10141 }
10142 }
10143
10144 /**
10145 * Called when userActivity is signalled in the power manager.
10146 * This is safe to call from any thread, with any window manager locks held or not.
10147 */
10148 @Override
10149 public void userActivity() {
10150 // ***************************************
10151 // * Inherited from PhoneWindowManager *
10152 // ***************************************
10153 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10154 // WITH ITS LOCKS HELD.
10155 //
10156 // This code must be VERY careful about the locks
10157 // it acquires.
10158 // In fact, the current code acquires way too many,
10159 // and probably has lurking deadlocks.
10160
10161 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10162 throw new SecurityException("Only the OS may call notifyUserActivity()");
10163 }
10164
10165 if (mNotifyUserActivity.getAndSet(false)) {
10166 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10167 USER_ACTIVITY_NOTIFICATION_DELAY);
10168 }
10169 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010170
10171 @Override
10172 public boolean canConnectTo5GInDsdsMode() {
10173 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10174 }
Jack Yud10cdd42020-09-28 20:28:01 -070010175
10176 @Override
10177 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10178 String callingFeatureId) {
10179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10180 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10181 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10182 }
10183
10184 Phone phone = getPhone(subId);
10185 if (phone == null) {
10186 throw new RuntimeException("phone is not available");
10187 }
10188 // Now that all security checks passes, perform the operation as ourselves.
10189 final long identity = Binder.clearCallingIdentity();
10190 try {
10191 return phone.getEquivalentHomePlmns();
10192 } finally {
10193 Binder.restoreCallingIdentity(identity);
10194 }
10195 }
Daniel Bright59e67312020-11-13 11:49:37 -080010196
10197 @Override
10198 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010199 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10200 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010201 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010202 if (radioInterfaceCapabilities == null) {
10203 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010204 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010205 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010206 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010207
Hui Wang641e81c2020-10-12 12:14:23 -070010208 @Override
10209 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10210 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010211 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10212 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10213 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10214 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10215 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010216 if (DBG) {
10217 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10218 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10219 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10220 }
10221
10222 if (!SubscriptionManager.isValidSubscriptionId(subId)
10223 || appType < TelephonyManager.APPTYPE_UNKNOWN
10224 || appType > TelephonyManager.APPTYPE_ISIM
10225 || nafUrl == null || securityProtocol == null || callback == null) {
10226 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10227 if (callback != null) {
10228 try {
10229 callback.onAuthenticationFailure(
10230 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10231 } catch (RemoteException exception) {
10232 log("Fail to notify onAuthenticationFailure due to " + exception);
10233 }
10234 return;
10235 }
10236 }
10237
10238 final long token = Binder.clearCallingIdentity();
10239 try {
10240 getGbaManager(subId).bootstrapAuthenticationRequest(
10241 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10242 forceBootStrapping, callback));
10243 } finally {
10244 Binder.restoreCallingIdentity(token);
10245 }
10246 }
10247
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010249 * Attempts to set the radio power state for all phones for thermal reason.
10250 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 * requested radio power state will actually be set. See {@link
10252 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10253 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 * @param enable {@code true} if trying to turn radio on.
10255 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10256 * false}.
10257 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010258 private boolean setRadioPowerForThermal(boolean enable) {
10259 boolean isPhoneAvailable = false;
10260 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10261 Phone phone = PhoneFactory.getPhone(i);
10262 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010263 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010264 isPhoneAvailable = true;
10265 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010267
10268 // return true if successfully informed the phone object about the thermal radio power
10269 // request.
10270 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 }
10272
10273 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010274 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010275 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10276 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10277 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10278 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10279 throw new IllegalArgumentException("modem does not support data throttling");
10280 }
10281
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010282 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10283 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010284 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010285 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10286 }
10287
Sarah Chinecc78c42022-03-31 21:16:48 -070010288 setDataEnabledForReason(
10289 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010291 if (isDataThrottlingSupported) {
10292 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010293 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010294 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10295 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10296 } else if (thermalMitigationResult
10297 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010298 log("Modem likely does not support data throttling on secondary carrier. Data " +
10299 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10300 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010301 }
10302 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010303 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010304
10305 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010306 }
10307
Jack Nudelman644b91a2021-03-12 14:09:48 -080010308 private static List<String> getThermalMitigationAllowlist(Context context) {
10309 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10310 for (String pckg : context.getResources()
10311 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10312 sThermalMitigationAllowlistedPackages.add(pckg);
10313 }
10314 }
10315
10316 return sThermalMitigationAllowlistedPackages;
10317 }
10318
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010319 private boolean isAnyPhoneInEmergencyState() {
10320 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10321 if (tm.isInEmergencyCall()) {
10322 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10323 return true;
10324 }
10325 for (Phone phone : PhoneFactory.getPhones()) {
10326 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10327 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10328 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10329 + phone.isInEcm());
10330 return true;
10331 }
10332 }
10333
10334 return false;
10335 }
10336
Jack Nudelman644b91a2021-03-12 14:09:48 -080010337 /**
10338 * Used by shell commands to add an authorized package name for thermal mitigation.
10339 * @param packageName name of package to be allowlisted
10340 * @param context
10341 */
10342 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10343 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10344 sThermalMitigationAllowlistedPackages.add(packageName);
10345 }
10346
10347 /**
10348 * Used by shell commands to remove an authorized package name for thermal mitigation.
10349 * @param packageName name of package to remove from allowlist
10350 * @param context
10351 */
10352 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10353 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10354 sThermalMitigationAllowlistedPackages.remove(packageName);
10355 }
10356
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357 /**
10358 * Thermal mitigation request to control functionalities at modem.
10359 *
10360 * @param subId the id of the subscription.
10361 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010362 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010363 *
10364 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10365 */
10366 @Override
10367 @ThermalMitigationResult
10368 public int sendThermalMitigationRequest(
10369 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010370 ThermalMitigationRequest thermalMitigationRequest,
10371 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 enforceModifyPermission();
10373
Jack Nudelman644b91a2021-03-12 14:09:48 -080010374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10375 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10376 .contains(callingPackage)) {
10377 throw new SecurityException("Calling package must be configured in the device config. "
10378 + "calling package: " + callingPackage);
10379 }
10380
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10382 final long identity = Binder.clearCallingIdentity();
10383
10384 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10385 try {
10386 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10387 switch (thermalMitigationAction) {
10388 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10389 thermalMitigationResult =
10390 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010391 thermalMitigationRequest.getDataThrottlingRequest(),
10392 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010393 break;
10394 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10395 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10396 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10397 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10398 }
10399
10400 // Ensure that radio is on. If not able to power on due to phone being
10401 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010402 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 thermalMitigationResult =
10404 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10405 break;
10406 }
10407
10408 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010409 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010410 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10411 break;
10412 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10413 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10414 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10415 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10416 }
10417
10418 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10419 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010420 Phone phone = getPhone(subId);
10421 if (phone == null) {
10422 thermalMitigationResult =
10423 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10424 break;
10425 }
10426
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010427 TelephonyConnectionService service =
10428 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010429 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010430 Log.e(LOG_TAG, "An emergency call is pending");
10431 thermalMitigationResult =
10432 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10433 break;
10434 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010435 thermalMitigationResult =
10436 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10437 break;
10438 }
10439 } else {
10440 thermalMitigationResult =
10441 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10442 break;
10443 }
10444
10445 // Turn radio off. If not able to power off due to phone being unavailable,
10446 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010447 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010448 thermalMitigationResult =
10449 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10450 break;
10451 }
10452 thermalMitigationResult =
10453 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10454 break;
10455 default:
10456 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10457 + "not exist. Requested action: " + thermalMitigationAction);
10458 }
10459 } catch (IllegalArgumentException e) {
10460 throw e;
10461 } catch (Exception e) {
10462 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10463 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467
10468 if (DBG) {
10469 log("thermalMitigationRequest returning with thermalMitigationResult: "
10470 + thermalMitigationResult);
10471 }
10472
10473 return thermalMitigationResult;
10474 }
Hui Wang641e81c2020-10-12 12:14:23 -070010475
10476 /**
10477 * Set the GbaService Package Name that Telephony will bind to.
10478 *
10479 * @param subId The sim that the GbaService is associated with.
10480 * @param packageName The name of the package to be replaced with.
10481 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10482 */
10483 @Override
10484 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10485 enforceModifyPermission();
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 return getGbaManager(subId).overrideServicePackage(packageName);
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 /**
10496 * Return the package name of the currently bound GbaService.
10497 *
10498 * @param subId The sim that the GbaService is associated with.
10499 * @return the package name of the GbaService configuration, null if GBA is not supported.
10500 */
10501 @Override
10502 public String getBoundGbaService(int subId) {
10503 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 return getGbaManager(subId).getServicePackage();
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
10513 /**
10514 * Set the release time for telephony to unbind GbaService.
10515 *
10516 * @param subId The sim that the GbaService is associated with.
10517 * @param interval The release time to unbind GbaService by millisecond.
10518 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10519 */
10520 @Override
10521 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10522 enforceModifyPermission();
10523
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 return getGbaManager(subId).overrideReleaseTime(interval);
10527 } finally {
10528 Binder.restoreCallingIdentity(identity);
10529 }
10530 }
10531
10532 /**
10533 * Return the release time for telephony to unbind GbaService.
10534 *
10535 * @param subId The sim that the GbaService is associated with.
10536 * @return The release time to unbind GbaService by millisecond.
10537 */
10538 @Override
10539 public int getGbaReleaseTime(int subId) {
10540 enforceReadPrivilegedPermission("getGbaReleaseTime");
10541
10542 final long identity = Binder.clearCallingIdentity();
10543 try {
10544 return getGbaManager(subId).getReleaseTime();
10545 } finally {
10546 Binder.restoreCallingIdentity(identity);
10547 }
10548 }
10549
10550 private GbaManager getGbaManager(int subId) {
10551 GbaManager instance = GbaManager.getInstance(subId);
10552 if (instance == null) {
10553 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10554 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10555 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10556 }
10557 return instance;
10558 }
Hui Wang761a6682020-10-31 05:12:53 +000010559
10560 /**
10561 * indicate whether the device and the carrier can support
10562 * RCS VoLTE single registration.
10563 */
10564 @Override
10565 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010566 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10567 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10568 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10569 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010570
10571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10572 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10573 }
10574
10575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10578 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010579 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10580 if (isCapable != null) {
10581 return isCapable;
10582 }
Hui Wang761a6682020-10-31 05:12:53 +000010583 }
Hui Wang67af90e2021-06-04 16:57:15 -070010584 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10585 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
10591 /**
10592 * Register RCS provisioning callback.
10593 */
10594 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010595 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010596 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010597 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010598 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010599 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10600 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010601
10602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10604 }
10605 if (!isImsAvailableOnDevice()) {
10606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10607 "IMS not available on device.");
10608 }
10609
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010612 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010613 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010614 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10615 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010616 }
Hui Wang761a6682020-10-31 05:12:53 +000010617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 /**
10623 * Unregister RCS provisioning callback.
10624 */
10625 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010626 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010627 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010628 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010629 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010630 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10631 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010632
10633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10634 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10635 }
10636 if (!isImsAvailableOnDevice()) {
10637 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10638 "IMS not available on device.");
10639 }
10640
10641 final long identity = Binder.clearCallingIdentity();
10642 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010643 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010644 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
10650 /**
10651 * trigger RCS reconfiguration.
10652 */
10653 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010654 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10655 "triggerRcsReconfiguration",
10656 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010657
10658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10659 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10660 }
10661 if (!isImsAvailableOnDevice()) {
10662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10663 "IMS not available on device.");
10664 }
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
10674 /**
10675 * Provide the client configuration parameters of the RCS application.
10676 */
10677 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010678 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10679 "setRcsClientConfiguration",
10680 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010681
10682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10684 }
10685 if (!isImsAvailableOnDevice()) {
10686 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10687 "IMS not available on device.");
10688 }
10689
10690 final long identity = Binder.clearCallingIdentity();
10691
10692 try {
10693 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10694 if (configBinder == null) {
10695 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010696 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10697 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010698 } else {
10699 configBinder.setRcsClientConfiguration(rcc);
10700 }
joonhunshin3e154242021-09-17 06:33:39 +000010701
10702 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10703 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010704 } catch (RemoteException e) {
10705 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010706 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10707 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010714 * Enables or disables the test mode for RCS VoLTE single registration.
10715 */
10716 @Override
10717 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10719 "setRcsSingleRegistrationTestModeEnabled");
10720
10721 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10722 }
10723
10724 /**
10725 * Gets the test mode for RCS VoLTE single registration.
10726 */
10727 @Override
10728 public boolean getRcsSingleRegistrationTestModeEnabled() {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10730 "getRcsSingleRegistrationTestModeEnabled");
10731
10732 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10733 }
10734
10735 /**
Hui Wang761a6682020-10-31 05:12:53 +000010736 * Overrides the config of RCS VoLTE single registration enabled for the device.
10737 */
10738 @Override
10739 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10741 "setDeviceSingleRegistrationEnabledOverride");
10742 enforceModifyPermission();
10743
10744 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10745 : Boolean.parseBoolean(enabledStr);
10746 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010747 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010748 }
10749
10750 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010751 * Sends a device to device communication message. Only usable via shell.
10752 * @param message message to send.
10753 * @param value message value.
10754 */
10755 @Override
10756 public void sendDeviceToDeviceMessage(int message, int value) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010758 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010759 enforceModifyPermission();
10760
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 TelephonyConnectionService service =
10764 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10765 if (service == null) {
10766 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10767 return;
10768 }
10769 service.sendTestDeviceToDeviceMessage(message, value);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
Tyler Gunnbabbda02021-02-10 11:05:02 -080010775 /**
10776 * Sets the specified device to device transport active.
10777 * @param transport The transport to set active.
10778 */
10779 @Override
10780 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10782 "setActiveDeviceToDeviceTransport");
10783 enforceModifyPermission();
10784
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 TelephonyConnectionService service =
10788 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10789 if (service == null) {
10790 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10791 return;
10792 }
10793 service.setActiveDeviceToDeviceTransport(transport);
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
Tyler Gunn92479152021-01-20 16:30:10 -080010798
Tyler Gunnd4339262021-05-03 14:46:49 -070010799 @Override
10800 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10802 "setDeviceToDeviceForceEnabled");
10803
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 Arrays.stream(PhoneFactory.getPhones()).forEach(
10807 p -> {
10808 Phone thePhone = p.getImsPhone();
10809 if (thePhone != null && thePhone instanceof ImsPhone) {
10810 ImsPhone imsPhone = (ImsPhone) thePhone;
10811 CallTracker tracker = imsPhone.getCallTracker();
10812 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10813 ImsPhoneCallTracker imsPhoneCallTracker =
10814 (ImsPhoneCallTracker) tracker;
10815 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10816 }
10817 }
10818 }
10819 );
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
Tyler Gunn92479152021-01-20 16:30:10 -080010825 /**
Hui Wang761a6682020-10-31 05:12:53 +000010826 * Gets the config of RCS VoLTE single registration enabled for the device.
10827 */
10828 @Override
10829 public boolean getDeviceSingleRegistrationEnabled() {
10830 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10831 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10832 }
10833
10834 /**
10835 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10836 */
10837 @Override
10838 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10840 "setCarrierSingleRegistrationEnabledOverride");
10841 enforceModifyPermission();
10842
10843 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10844 : Boolean.parseBoolean(enabledStr);
10845 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10846 subId, enabled);
10847 }
10848
10849 /**
10850 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10851 */
10852 @Override
10853 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10854 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10855 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10856 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010857
10858 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010859 * Overrides the ims feature validation result
10860 */
10861 @Override
10862 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10864 "setImsFeatureValidationOverride");
10865
10866 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10867 : Boolean.parseBoolean(enabledStr);
10868 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10869 subId, enabled);
10870 }
10871
10872 /**
10873 * Gets the ims feature validation override value
10874 */
10875 @Override
10876 public boolean getImsFeatureValidationOverride(int subId) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "getImsFeatureValidationOverride");
10879 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10880 }
10881
10882 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010883 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10884 * their mobile plan.
10885 */
10886 @Override
10887 public String getMobileProvisioningUrl() {
10888 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return getDefaultPhone().getMobileProvisioningUrl();
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010896
James.cf Linbcdf8b32021-01-14 16:44:13 +080010897 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010898 * Get the EAB contact from the EAB database.
10899 */
10900 @Override
10901 public String getContactFromEab(String contact) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10903 enforceModifyPermission();
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 /**
Calvin Pana1434322021-07-01 19:27:01 +080010913 * Get the EAB capability from the EAB database.
10914 */
10915 @Override
10916 public String getCapabilityFromEab(String contact) {
10917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10918 enforceModifyPermission();
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
10921 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010928 * Remove the EAB contacts from the EAB database.
10929 */
10930 @Override
10931 public int removeContactFromEab(int subId, String contacts) {
10932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10933 enforceModifyPermission();
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10937 } finally {
10938 Binder.restoreCallingIdentity(identity);
10939 }
10940 }
10941
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010942 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010943 public boolean getDeviceUceEnabled() {
10944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.getDeviceUceEnabled();
10948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 @Override
10954 public void setDeviceUceEnabled(boolean isEnabled) {
10955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 mApp.setDeviceUceEnabled(isEnabled);
10959 } finally {
10960 Binder.restoreCallingIdentity(identity);
10961 }
10962 }
10963
Brad Ebinger14d467f2021-02-12 06:18:28 +000010964 /**
10965 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10966 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10967 */
10968 // Used for SHELL command only right now.
10969 @Override
10970 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10971 List<String> featureTags) {
10972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10973 "addUceRegistrationOverrideShell");
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
10976 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10977 new ArraySet<>(featureTags));
10978 } catch (ImsException e) {
10979 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
10984
10985 /**
10986 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10987 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10988 */
10989 // Used for SHELL command only right now.
10990 @Override
10991 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10992 List<String> featureTags) {
10993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10994 "removeUceRegistrationOverrideShell");
10995 final long identity = Binder.clearCallingIdentity();
10996 try {
10997 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10998 new ArraySet<>(featureTags));
10999 } catch (ImsException e) {
11000 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 /**
11007 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11008 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11009 */
11010 // Used for SHELL command only right now.
11011 @Override
11012 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11014 "clearUceRegistrationOverrideShell");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 /**
11026 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11027 */
11028 // Used for SHELL command only right now.
11029 @Override
11030 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11032 "getLatestRcsContactUceCapabilityShell");
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
11035 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11036 } catch (ImsException e) {
11037 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 /**
11044 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11045 * device does not have an active PUBLISH.
11046 */
11047 // Used for SHELL command only right now.
11048 @Override
11049 public String getLastUcePidfXmlShell(int subId) {
11050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11054 } catch (ImsException e) {
11055 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
11060
James.cf Line8713a42021-04-29 16:04:26 +080011061 /**
11062 * Remove UCE requests cannot be sent to the network status.
11063 */
11064 // Used for SHELL command only right now.
11065 @Override
11066 public boolean removeUceRequestDisallowedStatus(int subId) {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11068 final long identity = Binder.clearCallingIdentity();
11069 try {
11070 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11071 } catch (ImsException e) {
11072 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
James.cf Lin18bb9002021-05-25 01:37:38 +080011078 /**
11079 * Remove UCE requests cannot be sent to the network status.
11080 */
11081 // Used for SHELL command only.
11082 @Override
11083 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11085 final long identity = Binder.clearCallingIdentity();
11086 try {
11087 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11088 } catch (ImsException e) {
11089 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011094
James.cf Lin4b784aa2021-01-31 03:25:15 +080011095 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011096 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11097 String callingPackage) {
11098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11099 mApp, subId, "setSignalStrengthUpdateRequest");
11100
11101 final int callingUid = Binder.getCallingUid();
11102 // Verify that tha callingPackage belongs to the calling UID
11103 mApp.getSystemService(AppOpsManager.class)
11104 .checkPackage(callingUid, callingPackage);
11105
Rambo Wang3607f502021-02-01 21:51:40 -080011106 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011107
11108 final long identity = Binder.clearCallingIdentity();
11109 try {
11110 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11111 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11112
11113 if (result instanceof IllegalStateException) {
11114 throw (IllegalStateException) result;
11115 }
11116 } finally {
11117 Binder.restoreCallingIdentity(identity);
11118 }
11119 }
11120
11121 @Override
11122 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11123 String callingPackage) {
11124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11125 mApp, subId, "clearSignalStrengthUpdateRequest");
11126
11127 final int callingUid = Binder.getCallingUid();
11128 // Verify that tha callingPackage belongs to the calling UID
11129 mApp.getSystemService(AppOpsManager.class)
11130 .checkPackage(callingUid, callingPackage);
11131
11132 final long identity = Binder.clearCallingIdentity();
11133 try {
11134 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11135 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11136
11137 if (result instanceof IllegalStateException) {
11138 throw (IllegalStateException) result;
11139 }
11140 } finally {
11141 Binder.restoreCallingIdentity(identity);
11142 }
11143 }
11144
Rambo Wang3607f502021-02-01 21:51:40 -080011145 private static void validateSignalStrengthUpdateRequest(Context context,
11146 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011147 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11148 // phone/system process do not have further restriction on request
11149 return;
11150 }
11151
11152 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011153 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011154 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011155 context.enforceCallingOrSelfPermission(
11156 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11157 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011158 }
11159
11160 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11161 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11162 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11163 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11164 || info.isEnabled()) {
11165 throw new IllegalArgumentException(
11166 "Only system can set hide fields in SignalThresholdInfo");
11167 }
11168
11169 // Thresholds length for each RAN need in range. This has been validated in
11170 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11171 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11172 final int[] thresholds = info.getThresholds();
11173 Objects.requireNonNull(thresholds);
11174 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11175 || thresholds.length
11176 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11177 throw new IllegalArgumentException(
11178 "thresholds length is out of range: " + thresholds.length);
11179 }
11180 }
11181 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011182
11183 /**
11184 * Gets the current phone capability.
11185 *
11186 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11187 * @return the PhoneCapability which describes the data connection capability of modem.
11188 * It's used to evaluate possible phone config change, for example from single
11189 * SIM device to multi-SIM device.
11190 */
11191 @Override
11192 public PhoneCapability getPhoneCapability() {
11193 enforceReadPrivilegedPermission("getPhoneCapability");
11194 final long identity = Binder.clearCallingIdentity();
11195 try {
11196 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
Michele Berionne5e411512020-11-13 02:36:59 +000011201
11202 /**
11203 * Prepare TelephonyManager for an unattended reboot. The reboot is
11204 * required to be done shortly after the API is invoked.
11205 */
11206 @Override
11207 @TelephonyManager.PrepareUnattendedRebootResult
11208 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011210 enforceRebootPermission();
11211
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011214 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011215 } finally {
11216 Binder.restoreCallingIdentity(identity);
11217 }
11218 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011219
11220 /**
11221 * Request to get the current slicing configuration including URSP rules and
11222 * NSSAIs (configured, allowed and rejected).
11223 *
11224 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11225 */
11226 @Override
11227 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011228 TelephonyPermissions
11229 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11230 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011231
11232 final long identity = Binder.clearCallingIdentity();
11233 try {
11234 Phone phone = getDefaultPhone();
11235 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11236 } finally {
11237 Binder.restoreCallingIdentity(identity);
11238 }
11239 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011240
11241 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011242 * Check whether the given premium capability is available for purchase from the carrier.
11243 *
11244 * @param capability The premium capability to check.
11245 * @param subId The subId to check the premium capability for.
11246 *
11247 * @return Whether the given premium capability is available to purchase.
11248 */
11249 @Override
11250 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11251 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11252 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11253 log("Premium capability "
11254 + TelephonyManager.convertPremiumCapabilityToString(capability)
11255 + " is not available for purchase due to missing permissions.");
11256 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11257 + "permission READ_BASIC_PHONE_STATE.");
11258 }
11259
11260 Phone phone = getPhone(subId);
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return SliceStore.getInstance(phone)
11264 .isPremiumCapabilityAvailableForPurchase(capability);
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
11269
11270 /**
11271 * Purchase the given premium capability from the carrier.
11272 *
11273 * @param capability The premium capability to purchase.
11274 * @param callback The result of the purchase request.
11275 * @param subId The subId to purchase the premium capability for.
11276 */
11277 @Override
11278 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11279 log("purchasePremiumCapability: capability="
11280 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11281 + getCurrentPackageName());
11282
11283 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11284 mApp, "purchasePremiumCapability")) {
11285 log("purchasePremiumCapability "
11286 + TelephonyManager.convertPremiumCapabilityToString(capability)
11287 + " failed due to missing permissions.");
11288 throw new SecurityException("purchasePremiumCapability requires permission "
11289 + "READ_BASIC_PHONE_STATE.");
11290 }
11291
11292 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011293 String appName;
11294 try {
11295 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11296 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11297 } catch (PackageManager.NameNotFoundException e) {
11298 appName = "An application";
11299 }
11300 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11301 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011302 }
11303
11304 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011305 * Register an IMS connection state callback
11306 */
11307 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011308 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11309 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011310 if (feature == ImsFeature.FEATURE_MMTEL) {
11311 // ImsMmTelManager
11312 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11313 TelephonyPermissions
11314 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11315 mApp, subId, "registerImsStateCallback");
11316 } else if (feature == ImsFeature.FEATURE_RCS) {
11317 // ImsRcsManager or SipDelegateManager
11318 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11319 Binder.getCallingUid(), "registerImsStateCallback",
11320 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11321 Manifest.permission.READ_PRECISE_PHONE_STATE,
11322 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11324 }
11325
11326 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11327 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11328 "IMS not available on device.");
11329 }
11330
11331 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11332 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11333 }
11334
11335 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11336 if (controller == null) {
11337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11338 "IMS not available on device.");
11339 }
11340
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011341 if (callingPackage == null) {
11342 callingPackage = getCurrentPackageName();
11343 }
11344
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011345 final long token = Binder.clearCallingIdentity();
11346 try {
11347 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011348 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011349 } catch (ImsException e) {
11350 throw new ServiceSpecificException(e.getCode());
11351 } finally {
11352 Binder.restoreCallingIdentity(token);
11353 }
11354 }
11355
11356 /**
11357 * Unregister an IMS connection state callback
11358 */
11359 @Override
11360 public void unregisterImsStateCallback(IImsStateCallback cb) {
11361 final long token = Binder.clearCallingIdentity();
11362 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11363 if (controller == null) {
11364 return;
11365 }
11366 try {
11367 controller.unregisterImsStateCallback(cb);
11368 } finally {
11369 Binder.restoreCallingIdentity(token);
11370 }
11371 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011372
11373 /**
11374 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11375 *
11376 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11377 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11378 * SecurityException.
11379 * If there is current registered network this value will be same as the registered cell
11380 * identity. If the device goes out of service the previous cell identity is cached and
11381 * will be returned. If the cache age of the Cell identity is more than 24 hours
11382 * it will be cleared and null will be returned.
11383 *
11384 */
11385 @Override
11386 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11387 String callingFeatureId) {
11388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11389 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11390 LocationAccessPolicy.checkLocationPermission(mApp,
11391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11392 .setCallingPackage(callingPackage)
11393 .setCallingFeatureId(callingFeatureId)
11394 .setCallingPid(Binder.getCallingPid())
11395 .setCallingUid(Binder.getCallingUid())
11396 .setMethod("getLastKnownCellIdentity")
11397 .setLogAsInfo(true)
11398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11400 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11401 .build());
11402
11403 boolean hasFinePermission =
11404 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11405 if (!hasFinePermission
11406 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11407 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011408 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011409 }
11410
11411 final long identity = Binder.clearCallingIdentity();
11412 try {
11413 Phone phone = getPhone(subId);
11414 if (phone == null) return null;
11415 ServiceStateTracker sst = phone.getServiceStateTracker();
11416 if (sst == null) return null;
11417 return sst.getLastKnownCellIdentity();
11418 } finally {
11419 Binder.restoreCallingIdentity(identity);
11420 }
11421 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011422
jimsun3b9ccac2021-10-26 15:01:23 +080011423 /**
11424 * Sets the modem service class Name that Telephony will bind to.
11425 *
11426 * @param serviceName The class name of the modem service.
11427 * @return true if the operation is succeed, otherwise false.
11428 */
11429 public boolean setModemService(String serviceName) {
11430 Log.d(LOG_TAG, "setModemService - " + serviceName);
11431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11433 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11434 "setModemService");
11435 return mPhoneConfigurationManager.setModemService(serviceName);
11436 }
11437
11438 /**
11439 * Return the class name of the currently bounded modem service.
11440 *
11441 * @return the class name of the modem service.
11442 */
11443 public String getModemService() {
11444 String result;
11445 Log.d(LOG_TAG, "getModemService");
11446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11447 TelephonyPermissions
11448 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11449 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11450 "getModemService");
11451 result = mPhoneConfigurationManager.getModemService();
11452 Log.d(LOG_TAG, "result = " + result);
11453 return result;
11454 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011455
11456 @Override
11457 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11458 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11459 mApp.enforceCallingOrSelfPermission(
11460 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11462
11463 final long identity = Binder.clearCallingIdentity();
11464 try {
11465 Phone phone = getPhone(subId);
11466 if (phone == null) return;
11467 phone.setVoiceServiceStateOverride(hasService);
11468 } finally {
11469 Binder.restoreCallingIdentity(identity);
11470 }
11471 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011472
11473 /**
11474 * set removable eSIM as default eUICC.
11475 *
11476 * @hide
11477 */
11478 @Override
11479 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11480 enforceModifyPermission();
11481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11482
11483 final long identity = Binder.clearCallingIdentity();
11484 try {
11485 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11486 } finally {
11487 Binder.restoreCallingIdentity(identity);
11488 }
11489 }
11490
11491 /**
11492 * Returns whether the removable eSIM is default eUICC or not.
11493 *
11494 * @hide
11495 */
11496 @Override
11497 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11498 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11500
11501 final long identity = Binder.clearCallingIdentity();
11502 try {
11503 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11504 } finally {
11505 Binder.restoreCallingIdentity(identity);
11506 }
11507 }
11508
11509
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011510}