blob: 3f05f0ada42cabad78e0e92c242d167374c160d0 [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;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070081import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080082import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070083import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080084import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070085import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080086import android.telephony.CellIdentityCdma;
87import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070089import android.telephony.CellInfoGsm;
90import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070091import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080092import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070093import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070094import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070095import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080096import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080098import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070099import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800100import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800101import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800105import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800106import android.telephony.SignalStrengthUpdateRequest;
107import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800108import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800110import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700111import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700112import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800113import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800114import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800115import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700119import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800121import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800122import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700123import android.telephony.gba.GbaAuthRequest;
124import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700125import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000127import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000128import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700129import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000130import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700133import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700137import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700188import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700214import com.android.phone.slicestore.SliceStore;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800231import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800232import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800234import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100235import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700237import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800239import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700240import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700364 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
365 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800367 // Parameters of select command.
368 private static final int SELECT_COMMAND = 0xA4;
369 private static final int SELECT_P1 = 0x04;
370 private static final int SELECT_P2 = 0;
371 private static final int SELECT_P3 = 0x10;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /** The singleton instance. */
374 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800375 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800379 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700380 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700382 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800384 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700386 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800387 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Sarah Chin2ec39f62022-08-31 17:03:26 -0700414 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
415 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
416
Derek Tan89e89d42014-07-08 17:00:10 -0700417 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700418 * Experiment flag to enable erase modem config on reset network, default value is false
419 */
420 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
421 "reset_network_erase_modem_config_enabled";
422
Rambo Wang0f050d82021-02-12 11:43:36 -0800423 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800424
sandeepjsb6c87872021-09-27 15:34:44 +0000425 /**
426 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
427 * one ICCID active at the same time.
428 * Apps should use below API signatures if targeting SDK is T and beyond.
429 *
430 * @hide
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800435
Naina Nallurid63128d2019-09-17 14:10:30 -0700436 /**
Chen Xu540470b2021-12-14 17:15:47 -0800437 * Apps targeting on Android T and beyond will get exception whenever icc close channel
438 * operation fails.
439 */
440 @ChangeId
441 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
442 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
443
444 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class IccAPDUArgument {
448 public int channel, cla, command, p1, p2, p3;
449 public String data;
450
451 public IccAPDUArgument(int channel, int cla, int command,
452 int p1, int p2, int p3, String data) {
453 this.channel = channel;
454 this.cla = cla;
455 this.command = command;
456 this.p1 = p1;
457 this.p2 = p2;
458 this.p3 = p3;
459 this.data = data;
460 }
461 }
462
463 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700464 * A request object to use for transmitting data to an ICC.
465 */
466 private static final class ManualNetworkSelectionArgument {
467 public OperatorInfo operatorInfo;
468 public boolean persistSelection;
469
470 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
471 this.operatorInfo = operatorInfo;
472 this.persistSelection = persistSelection;
473 }
474 }
475
Sarah Chin71b3a852022-09-28 15:54:19 -0700476 private static final class PurchasePremiumCapabilityArgument {
477 public @TelephonyManager.PremiumCapability int capability;
478 public @NonNull String appName;
479 public @NonNull IIntegerConsumer callback;
480
481 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
482 @NonNull String appName, @NonNull IIntegerConsumer callback) {
483 this.capability = capability;
484 this.appName = appName;
485 this.callback = callback;
486 }
487 }
488
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700489 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
491 * request after sending. The main thread will notify the request when it is complete.
492 */
493 private static final class MainThreadRequest {
494 /** The argument to use for the request */
495 public Object argument;
496 /** The result of the request that is run on the main thread */
497 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800498 // The subscriber id that this request applies to. Defaults to
499 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
500 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501
Nathan Harold92bed182018-10-12 18:16:49 -0700502 // In cases where subId is unavailable, the caller needs to specify the phone.
503 public Phone phone;
504
vagdeviaf9a5b92018-08-15 16:01:53 -0700505 public WorkSource workSource;
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 public MainThreadRequest(Object argument) {
508 this.argument = argument;
509 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800510
Nathan Harold92bed182018-10-12 18:16:49 -0700511 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
512 this.argument = argument;
513 if (phone != null) {
514 this.phone = phone;
515 }
516 this.workSource = workSource;
517 }
518
vagdeviaf9a5b92018-08-15 16:01:53 -0700519 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800520 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800521 if (subId != null) {
522 this.subId = subId;
523 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700524 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 }
527
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800528 private static final class IncomingThirdPartyCallArgs {
529 public final ComponentName component;
530 public final String callId;
531 public final String callerDisplayName;
532
533 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
534 String callerDisplayName) {
535 this.component = component;
536 this.callId = callId;
537 this.callerDisplayName = callerDisplayName;
538 }
539 }
540
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 /**
542 * A handler that processes messages on the main thread in the phone process. Since many
543 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
544 * inbound binder threads to the main thread in the phone process. The Binder thread
545 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
546 * on, which will be notified when the operation completes and will contain the result of the
547 * request.
548 *
549 * <p>If a MainThreadRequest object is provided in the msg.obj field,
550 * note that request.result must be set to something non-null for the calling thread to
551 * unblock.
552 */
553 private final class MainThreadHandler extends Handler {
554 @Override
555 public void handleMessage(Message msg) {
556 MainThreadRequest request;
557 Message onCompleted;
558 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000559 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800561 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562
563 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 case CMD_HANDLE_USSD_REQUEST: {
565 request = (MainThreadRequest) msg.obj;
566 final Phone phone = getPhoneFromRequest(request);
567 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800568 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700570
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 if (!isUssdApiAllowed(request.subId)) {
572 // Carrier does not support use of this API, return failure.
573 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
574 UssdResponse response = new UssdResponse(ussdRequest, null);
575 Bundle returnData = new Bundle();
576 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
577 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700578
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 request.result = true;
580 notifyRequester(request);
581 return;
582 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700583
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 try {
585 request.result = phone != null
586 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
587 } catch (CallStateException cse) {
588 request.result = false;
589 }
590 // Wake up the requesting thread
591 notifyRequester(request);
592 break;
pkanwar32d516d2016-10-14 19:37:38 -0700593 }
594
Yorke Lee716f67e2015-06-17 15:39:16 -0700595 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700597 final Phone phone = getPhoneFromRequest(request);
598 request.result = phone != null ?
599 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
600 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 uiccPort = getUiccPortFromRequest(request);
610 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800616 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000617 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800618 iccArgument.channel, iccArgument.cla, iccArgument.command,
619 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
620 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result;
629 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.result == null) {
632 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800633 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800635 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
637 loge("iccTransmitApduLogicalChannel: Unknown exception");
638 }
639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
645 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort = getUiccPortFromRequest(request);
647 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 } else {
652 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800655 iccArgument.cla, iccArgument.command, iccArgument.p1,
656 iccArgument.p2,
657 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 }
659 break;
660
661 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
666 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 if (ar.result == null) {
669 loge("iccTransmitApduBasicChannel: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("iccTransmitApduBasicChannel: CommandException: " +
672 ar.exception);
673 } else {
674 loge("iccTransmitApduBasicChannel: Unknown exception");
675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 break;
679
680 case CMD_EXCHANGE_SIM_IO:
681 request = (MainThreadRequest) msg.obj;
682 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort = getUiccPortFromRequest(request);
684 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
690 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
693 iccArgument.data, onCompleted);
694 }
695 break;
696
697 case EVENT_EXCHANGE_SIM_IO_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
700 if (ar.exception == null && ar.result != null) {
701 request.result = ar.result;
702 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 break;
707
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 case CMD_SEND_ENVELOPE:
709 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort = getUiccPortFromRequest(request);
711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800717 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800719 break;
720
721 case EVENT_SEND_ENVELOPE_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800726 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700728 if (ar.result == null) {
729 loge("sendEnvelopeWithStatus: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("sendEnvelopeWithStatus: CommandException: " +
732 ar.exception);
733 } else {
734 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
735 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 break;
739
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 case CMD_OPEN_CHANNEL:
741 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000742 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800743 IccLogicalChannelRequest openChannelRequest =
744 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800747 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800748 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800752 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
753 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_OPEN_CHANNEL_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 int[] result = (int[]) ar.result;
763 int channelId = result[0];
764 byte[] selectResponse = null;
765 if (result.length > 1) {
766 selectResponse = new byte[result.length - 1];
767 for (int i = 1; i < result.length; ++i) {
768 selectResponse[i - 1] = (byte) result[i];
769 }
770 }
771 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800772 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800773
774 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700775 if (uiccPort == null) {
776 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
777 } else {
778 IccLogicalChannelRequest channelRequest =
779 (IccLogicalChannelRequest) request.argument;
780 channelRequest.channel = channelId;
781 uiccPort.onLogicalChannelOpened(channelRequest);
782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 if (ar.result == null) {
785 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700787 if (ar.exception != null) {
788 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
789 }
790
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700791 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800794 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700795 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700796 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700797 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700798 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700799 }
800 }
801 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800802 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700804 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
808 case CMD_CLOSE_CHANNEL:
809 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000810 uiccPort = getUiccPortFromRequest(request);
811 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800813 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800814 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800815 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 } else {
817 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000818 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 break;
821
822 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null) {
826 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800827 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700828 if (uiccPort == null) {
829 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
830 } else {
831 final int channelId = (Integer) request.argument;
832 uiccPort.onLogicalChannelClosed(channelId);
833 }
Chen Xu540470b2021-12-14 17:15:47 -0800834 } else {
835 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800836 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800837 if (ar.exception instanceof CommandException) {
838 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
839 CommandException.Error error =
840 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800841 if (error == CommandException.Error.INVALID_ARGUMENTS) {
842 // should only throw exceptions from the binder threads.
843 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800844 "iccCloseLogicalChannel: invalid argument ");
845 }
846 } else {
847 loge("iccCloseLogicalChannel: Unknown exception");
848 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800849 request.result = (exception != null) ? exception :
850 new IllegalStateException(
851 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800852 }
853 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800854 break;
855
856 case CMD_NV_READ_ITEM:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800869 request.result = "";
870 if (ar.result == null) {
871 loge("nvReadItem: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("nvReadItem: CommandException: " +
874 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800876 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 }
878 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700879 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 break;
881
Jake Hambye994d462014-02-03 13:10:13 -0800882 case CMD_NV_WRITE_ITEM:
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
885 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700887 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
890 case EVENT_NV_WRITE_ITEM_DONE:
891 handleNullReturnEvent(msg, "nvWriteItem");
892 break;
893
894 case CMD_NV_WRITE_CDMA_PRL:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800897 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800898 break;
899
900 case EVENT_NV_WRITE_CDMA_PRL_DONE:
901 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
902 break;
903
chen xu6dac5ab2018-10-26 17:39:23 -0700904 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800905 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700906 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800908 break;
909
chen xu6dac5ab2018-10-26 17:39:23 -0700910 case EVENT_RESET_MODEM_CONFIG_DONE:
911 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
Sooraj Sasindran37444802020-08-11 10:40:43 -0700914 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
917 request);
918 Phone phone = getPhoneFromRequest(request);
919 if (phone != null) {
920 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
921 } else {
922 loge("isNRDualConnectivityEnabled: No phone object");
923 request.result = false;
924 notifyRequester(request);
925 }
926 break;
927 }
928
929 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 // request.result must be set to something non-null
936 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700937 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700938 request.result = ar.result;
939 } else {
940 request.result = false;
941 }
942 if (ar.result == null) {
943 loge("isNRDualConnectivityEnabled: Empty response");
944 } else if (ar.exception instanceof CommandException) {
945 loge("isNRDualConnectivityEnabled: CommandException: "
946 + ar.exception);
947 } else {
948 loge("isNRDualConnectivityEnabled: Unknown exception");
949 }
950 }
951 notifyRequester(request);
952 break;
953
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700954 case CMD_IS_VONR_ENABLED: {
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
957 request);
958 Phone phone = getPhoneFromRequest(request);
959 if (phone != null) {
960 phone.isVoNrEnabled(onCompleted, request.workSource);
961 } else {
962 loge("isVoNrEnabled: No phone object");
963 request.result = false;
964 notifyRequester(request);
965 }
966 break;
967 }
968
969 case EVENT_IS_VONR_ENABLED_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception == null && ar.result != null) {
973 request.result = ar.result;
974 } else {
975 // request.result must be set to something non-null
976 // for the calling thread to unblock
977 if (ar.result != null) {
978 request.result = ar.result;
979 } else {
980 request.result = false;
981 }
982 if (ar.result == null) {
983 loge("isVoNrEnabled: Empty response");
984 } else if (ar.exception instanceof CommandException) {
985 loge("isVoNrEnabled: CommandException: "
986 + ar.exception);
987 } else {
988 loge("isVoNrEnabled: Unknown exception");
989 }
990 }
991 notifyRequester(request);
992 break;
993
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
997 Phone phone = getPhoneFromRequest(request);
998 if (phone != null) {
999 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1000 request.workSource);
1001 } else {
1002 loge("enableNrDualConnectivity: No phone object");
1003 request.result =
1004 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1005 notifyRequester(request);
1006 }
1007 break;
1008 }
1009
1010 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result =
1015 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1016 } else {
1017 request.result =
1018 TelephonyManager
1019 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1020 if (ar.exception instanceof CommandException) {
1021 CommandException.Error error =
1022 ((CommandException) (ar.exception)).getCommandError();
1023 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1024 request.result =
1025 TelephonyManager
1026 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1028 request.result =
1029 TelephonyManager
1030 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001031 }
1032 loge("enableNrDualConnectivity" + ": CommandException: "
1033 + ar.exception);
1034 } else {
1035 loge("enableNrDualConnectivity" + ": Unknown exception");
1036 }
1037 }
1038 notifyRequester(request);
1039 break;
1040 }
1041
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001042 case CMD_ENABLE_VONR: {
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1045 Phone phone = getPhoneFromRequest(request);
1046 if (phone != null) {
1047 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1048 request.workSource);
1049 } else {
1050 loge("setVoNrEnabled: No phone object");
1051 request.result =
1052 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1053 notifyRequester(request);
1054 }
1055 break;
1056 }
1057
1058 case EVENT_ENABLE_VONR_DONE: {
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 if (ar.exception == null) {
1062 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1063 } else {
1064 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1065 if (ar.exception instanceof CommandException) {
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1069 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1070 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1071 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1072 } else {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1074 }
1075 loge("setVoNrEnabled" + ": CommandException: "
1076 + ar.exception);
1077 } else {
1078 loge("setVoNrEnabled" + ": Unknown exception");
1079 }
1080 }
1081 notifyRequester(request);
1082 break;
1083 }
1084
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1088 request);
1089 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null && ar.result != null) {
1096 request.result = ar.result; // Integer
1097 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301098 // request.result must be set to something non-null
1099 // for the calling thread to unblock
1100 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 loge("getAllowedNetworkTypesBitmask: CommandException: "
1105 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 }
1109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 break;
1112
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1116 request);
1117 Pair<Integer, Long> reasonWithNetworkTypes =
1118 (Pair<Integer, Long>) request.argument;
1119 getPhoneFromRequest(request).setAllowedNetworkTypes(
1120 reasonWithNetworkTypes.first,
1121 reasonWithNetworkTypes.second,
1122 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1126 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001129 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1130 request = (MainThreadRequest)msg.obj;
1131 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001132 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001133 break;
1134
1135 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1136 ar = (AsyncResult)msg.obj;
1137 request = (MainThreadRequest)ar.userObj;
1138 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001140 break;
1141
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001142 case CMD_SET_VOICEMAIL_NUMBER:
1143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1145 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001146 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1147 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001148 break;
1149
1150 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1151 handleNullReturnEvent(msg, "setVoicemailNumber");
1152 break;
1153
Stuart Scott54788802015-03-30 13:18:01 -07001154 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1157 request);
1158 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1159 break;
1160
1161 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1162 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1163 break;
1164
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 case CMD_PERFORM_NETWORK_SCAN:
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1168 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1169 break;
1170
Hall Liu27d24262020-09-18 19:04:59 -07001171 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001174 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1175 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1176 request.argument;
1177 int callForwardingReason = args.first;
1178 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
1181 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001184 TelephonyManager.CallForwardingInfoCallback callback =
1185 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1186 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001187 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001188 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001189 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1190 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1191 // Service Class is a bit mask per 3gpp 27.007. Search for
1192 // any service for voice call.
1193 if ((callForwardInfo.serviceClass
1194 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001195 callForwardingInfo = new CallForwardingInfo(
1196 callForwardInfo.status
1197 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001198 callForwardInfo.reason,
1199 callForwardInfo.number,
1200 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
1202 }
1203 }
1204 // Didn't find a call forward info for voice call.
1205 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1207 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 } else {
1211 if (ar.result == null) {
1212 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1213 }
1214 if (ar.exception != null) {
1215 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1216 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001217 int errorCode = TelephonyManager
1218 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 if (ar.exception instanceof CommandException) {
1220 CommandException.Error error =
1221 ((CommandException) (ar.exception)).getCommandError();
1222 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001223 errorCode = TelephonyManager
1224 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001226 errorCode = TelephonyManager
1227 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 }
Hall Liu27d24262020-09-18 19:04:59 -07001230 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001231 }
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 request = (MainThreadRequest) msg.obj;
1237 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001238 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001240 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1241 request.argument).first;
1242 request.phone.setCallForwardingOption(
1243 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001244 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001245 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001246 callForwardingInfoToSet.getReason(),
1247 callForwardingInfoToSet.getNumber(),
1248 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1249 break;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251
Hall Liu27d24262020-09-18 19:04:59 -07001252 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001253 ar = (AsyncResult) msg.obj;
1254 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001255 Consumer<Integer> callback =
1256 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1257 request.argument).second;
1258 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager.CallForwardingInfoCallback
1261 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager.CallForwardingInfoCallback
1267 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager.CallForwardingInfoCallback
1270 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001271 }
1272 }
1273 callback.accept(errorCode);
1274 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277 break;
Hall Liu27d24262020-09-18 19:04:59 -07001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279
Hall Liu27d24262020-09-18 19:04:59 -07001280 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1283 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001290 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001291 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001293 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 // Service Class is a bit mask per 3gpp 27.007.
1295 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001296 if (callForwardResults.length > 1
1297 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001298 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001300 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1301 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001302 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
1305 } else {
1306 if (ar.result == null) {
1307 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1308 }
1309 if (ar.exception != null) {
1310 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1311 }
1312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001317 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1319 callWaitingStatus =
1320 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
1322 }
1323 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001325 break;
Hall Liu27d24262020-09-18 19:04:59 -07001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327
Hall Liu27d24262020-09-18 19:04:59 -07001328 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001331 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1332 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335
Hall Liu27d24262020-09-18 19:04:59 -07001336 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001339 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1340 Consumer<Integer> callback =
1341 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1342 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001344 if (ar.exception instanceof CommandException) {
1345 CommandException.Error error =
1346 ((CommandException) (ar.exception)).getCommandError();
1347 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1348 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1350 callback.accept(
1351 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001352 } else {
1353 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1354 }
1355 } else {
1356 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1357 }
1358 } else {
1359 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1360 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001361 }
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 CellNetworkScanResult cellScanResult;
1368 if (ar.exception == null && ar.result != null) {
1369 cellScanResult = new CellNetworkScanResult(
1370 CellNetworkScanResult.STATUS_SUCCESS,
1371 (List<OperatorInfo>) ar.result);
1372 } else {
1373 if (ar.result == null) {
1374 loge("getCellNetworkScanResults: Empty response");
1375 }
1376 if (ar.exception != null) {
1377 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1378 }
1379 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1384 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1385 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1386 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1387 }
1388 }
1389 cellScanResult = new CellNetworkScanResult(errorCode, null);
1390 }
1391 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 break;
1394
1395 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1396 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001397 ManualNetworkSelectionArgument selArg =
1398 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1400 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001401 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1402 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 break;
1404
1405 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception == null) {
1409 request.result = true;
1410 } else {
1411 request.result = false;
1412 loge("setNetworkSelectionModeManual " + ar.exception);
1413 }
1414 notifyRequester(request);
1415 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 break;
1417
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 case CMD_GET_MODEM_ACTIVITY_INFO:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001421 if (defaultPhone != null) {
1422 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001423 } else {
1424 ResultReceiver result = (ResultReceiver) request.argument;
1425 Bundle bundle = new Bundle();
1426 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001427 new ModemActivityInfo(0, 0, 0,
1428 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001430 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 break;
1432
Hall Liud0f208c2020-10-14 16:54:44 -07001433 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001437 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001438 if (mLastModemActivityInfo == null) {
1439 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1440 mLastModemActivitySpecificInfo[0] =
1441 new ActivityStatsTechSpecificInfo(
1442 0,
1443 0,
1444 new int[ModemActivityInfo.getNumTxPowerLevels()],
1445 0);
1446 mLastModemActivityInfo =
1447 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1448 }
1449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 // Update the last modem activity info and the result of the request.
1452 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1453 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001454 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 mLastModemActivityInfo =
1457 new ModemActivityInfo(
1458 mLastModemActivityInfo.getTimestampMillis(),
1459 mLastModemActivityInfo.getSleepTimeMillis(),
1460 mLastModemActivityInfo.getIdleTimeMillis(),
1461 mLastModemActivitySpecificInfo);
1462
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 } else {
1464 if (ar.result == null) {
1465 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001466 error = TelephonyManager.ModemActivityInfoException
1467 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001470 error = TelephonyManager.ModemActivityInfoException
1471 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 } else {
1473 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001474 error = TelephonyManager.ModemActivityInfoException
1475 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 }
1477 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001479 if (mLastModemActivityInfo != null) {
1480 bundle.putParcelable(
1481 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1482 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001483 } else {
1484 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1485 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001486 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001489 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490
Meng Wang1a7c35a2016-05-05 20:56:15 -07001491 case CMD_SET_ALLOWED_CARRIERS:
1492 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001493 CarrierRestrictionRules argument =
1494 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001495 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001496 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 break;
1498
1499 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 if (ar.exception == null && ar.result != null) {
1503 request.result = ar.result;
1504 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001505 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1506 if (ar.exception instanceof CommandException) {
1507 loge("setAllowedCarriers: CommandException: " + ar.exception);
1508 CommandException.Error error =
1509 ((CommandException) (ar.exception)).getCommandError();
1510 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1511 request.result =
1512 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1513 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 } else {
1515 loge("setAllowedCarriers: Unknown exception");
1516 }
1517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001518 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
1521 case CMD_GET_ALLOWED_CARRIERS:
1522 request = (MainThreadRequest) msg.obj;
1523 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001524 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
1527 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001533 request.result = new IllegalStateException(
1534 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 if (ar.result == null) {
1536 loge("getAllowedCarriers: Empty response");
1537 } else if (ar.exception instanceof CommandException) {
1538 loge("getAllowedCarriers: CommandException: " +
1539 ar.exception);
1540 } else {
1541 loge("getAllowedCarriers: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
1553 request.result = new IllegalArgumentException(
1554 "Failed to retrieve Forbidden Plmns");
1555 if (ar.result == null) {
1556 loge("getForbiddenPlmns: Empty response");
1557 } else {
1558 loge("getForbiddenPlmns: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001562 break;
1563
1564 case CMD_GET_FORBIDDEN_PLMNS:
1565 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001566 uiccPort = getUiccPortFromRequest(request);
1567 if (uiccPort == null) {
1568 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001569 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001570 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001572 break;
1573 }
1574 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001575 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001576 if (uiccApp == null) {
1577 loge("getForbiddenPlmns() no app with specified type -- "
1578 + appType);
1579 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001581 break;
1582 } else {
1583 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1584 + " specified type -- " + appType);
1585 }
1586 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1587 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1588 onCompleted);
1589 break;
1590
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001591 case CMD_SWITCH_SLOTS:
1592 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001593 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001594 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001595 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 break;
1597
1598 case EVENT_SWITCH_SLOTS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_NETWORK_SELECTION_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1607 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1608 break;
1609
1610 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1615 } else {
1616 int mode = ((int[]) ar.result)[0];
1617 if (mode == 0) {
1618 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1619 } else {
1620 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1621 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
1624 break;
1625 case CMD_GET_CDMA_ROAMING_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1628 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1629 break;
1630 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception != null) {
1634 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1635 } else {
1636 request.result = ((int[]) ar.result)[0];
1637 }
1638 notifyRequester(request);
1639 break;
1640 case CMD_SET_CDMA_ROAMING_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1643 int mode = (int) request.argument;
1644 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1645 break;
1646 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 request.result = ar.exception == null;
1650 notifyRequester(request);
1651 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001652 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1655 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1656 break;
1657 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 if (ar.exception != null) {
1661 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1662 } else {
1663 request.result = ((int[]) ar.result)[0];
1664 }
1665 notifyRequester(request);
1666 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1670 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001671 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1672 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001673 break;
1674 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 request.result = ar.exception == null;
1678 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001680 case CMD_GET_ALL_CELL_INFO:
1681 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001682 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001683 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 case EVENT_GET_ALL_CELL_INFO_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001688 // If a timeout occurs, the response will be null
1689 request.result = (ar.exception == null && ar.result != null)
1690 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 synchronized (request) {
1692 request.notifyAll();
1693 }
1694 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001695 case CMD_REQUEST_CELL_INFO_UPDATE:
1696 request = (MainThreadRequest) msg.obj;
1697 request.phone.requestCellInfoUpdate(request.workSource,
1698 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1699 break;
1700 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1704 try {
1705 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001706 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001707 cb.onError(
1708 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1709 ar.exception.getClass().getName(),
1710 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001711 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001713 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001714 } else {
1715 // use the result as returned
1716 cb.onCellInfo((List<CellInfo>) ar.result);
1717 }
1718 } catch (RemoteException re) {
1719 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1720 }
1721 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 request = (MainThreadRequest) msg.obj;
1724 WorkSource ws = (WorkSource) request.argument;
1725 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001726 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001727 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001728 }
1729 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception == null) {
1733 request.result = ar.result;
1734 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001735 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001737 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 }
1739
1740 synchronized (request) {
1741 request.notifyAll();
1742 }
1743 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 }
chen xu6dac5ab2018-10-26 17:39:23 -07001745 case CMD_MODEM_REBOOT:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001748 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001749 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001750 case EVENT_CMD_MODEM_REBOOT_DONE:
1751 handleNullReturnEvent(msg, "rebootModem");
1752 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001753 case CMD_REQUEST_ENABLE_MODEM:
1754 request = (MainThreadRequest) msg.obj;
1755 boolean enable = (boolean) request.argument;
1756 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001757 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001758 PhoneConfigurationManager.getInstance()
1759 .enablePhone(request.phone, enable, onCompleted);
1760 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001761 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001765 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001766 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001767 if ((boolean) request.result) {
1768 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1769 updateModemStateMetrics();
1770 } else {
1771 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1772 + ar.exception);
1773 }
1774 notifyRequester(request);
1775 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001776 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001777 case CMD_GET_MODEM_STATUS:
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1780 PhoneConfigurationManager.getInstance()
1781 .getPhoneStatusFromModem(request.phone, onCompleted);
1782 break;
1783 case EVENT_GET_MODEM_STATUS_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 int id = request.phone.getPhoneId();
1787 if (ar.exception == null && ar.result != null) {
1788 request.result = ar.result;
1789 //update the cache as modem status has changed
1790 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1791 (boolean) request.result);
1792 } else {
1793 // Return true if modem status cannot be retrieved. For most cases,
1794 // modem status is on. And for older version modems, GET_MODEM_STATUS
1795 // and disable modem are not supported. Modem is always on.
1796 // TODO: this should be fixed in R to support a third
1797 // status UNKNOWN b/131631629
1798 request.result = true;
1799 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1800 + ar.exception);
1801 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001802 notifyRequester(request);
1803 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001804 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1805 request = (MainThreadRequest) msg.obj;
1806 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1807 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1808 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1809 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1810 break;
1811 }
1812 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1816 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1817 args.second.accept(ar.exception == null);
1818 notifyRequester(request);
1819 break;
1820 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1822 request = (MainThreadRequest) msg.obj;
1823 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1824 Phone phone = getPhoneFromRequest(request);
1825 if (phone != null) {
1826 phone.getSystemSelectionChannels(onCompleted);
1827 } else {
1828 loge("getSystemSelectionChannels: No phone object");
1829 request.result = new ArrayList<RadioAccessSpecifier>();
1830 notifyRequester(request);
1831 }
1832 break;
1833 }
1834 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null && ar.result != null) {
1838 request.result = ar.result;
1839 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001840 request.result = new IllegalStateException(
1841 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001842 if (ar.result == null) {
1843 loge("getSystemSelectionChannels: Empty response");
1844 } else {
1845 loge("getSystemSelectionChannels: Unknown exception");
1846 }
1847 }
1848 notifyRequester(request);
1849 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001850 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 if (ar.exception == null && ar.result != null) {
1854 request.result = ar.result;
1855 } else {
1856 request.result = -1;
1857 loge("Failed to set Forbidden Plmns");
1858 if (ar.result == null) {
1859 loge("setForbidenPlmns: Empty response");
1860 } else if (ar.exception != null) {
1861 loge("setForbiddenPlmns: Exception: " + ar.exception);
1862 request.result = -1;
1863 } else {
1864 loge("setForbiddenPlmns: Unknown exception");
1865 }
1866 }
1867 notifyRequester(request);
1868 break;
1869 case CMD_SET_FORBIDDEN_PLMNS:
1870 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001871 uiccPort = getUiccPortFromRequest(request);
1872 if (uiccPort == null) {
1873 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001874 request.result = -1;
1875 notifyRequester(request);
1876 break;
1877 }
1878 Pair<Integer, List<String>> setFplmnsArgs =
1879 (Pair<Integer, List<String>>) request.argument;
1880 appType = setFplmnsArgs.first;
1881 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001882 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001883 if (uiccApp == null) {
1884 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1885 request.result = -1;
1886 loge("Failed to get UICC App");
1887 notifyRequester(request);
1888 } else {
1889 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1890 ((SIMRecords) uiccApp.getIccRecords())
1891 .setForbiddenPlmns(onCompleted, fplmns);
1892 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001893 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001894 case CMD_ERASE_MODEM_CONFIG:
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1897 defaultPhone.eraseModemConfig(onCompleted);
1898 break;
1899 case EVENT_ERASE_MODEM_CONFIG_DONE:
1900 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001901 break;
zoey chene02881a2019-12-30 16:11:23 +08001902
Kai Shif70f46f2021-03-03 13:59:46 -08001903 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1904 request = (MainThreadRequest) msg.obj;
1905 request.result = defaultPhone.eraseDataInSharedPreferences();
1906 notifyRequester(request);
1907 break;
1908
zoey chene02881a2019-12-30 16:11:23 +08001909 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1912 Pair<String, String> changed = (Pair<String, String>) request.argument;
1913 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1914 changed.first, changed.second, onCompleted);
1915 break;
1916 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1917 ar = (AsyncResult) msg.obj;
1918 request = (MainThreadRequest) ar.userObj;
1919 if (ar.exception == null) {
1920 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001921 // If the operation is successful, update the PIN storage
1922 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1923 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001924 UiccController.getInstance().getPinStorage()
1925 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001926 } else {
1927 request.result = msg.arg1;
1928 }
1929 notifyRequester(request);
1930 break;
1931
Michele Berionne5e411512020-11-13 02:36:59 +00001932 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1935 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1936 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1937 enabled.first, enabled.second, onCompleted);
1938 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001939 }
zoey chene02881a2019-12-30 16:11:23 +08001940 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null) {
1944 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001945 // If the operation is successful, update the PIN storage
1946 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1947 int phoneId = getPhoneFromRequest(request).getPhoneId();
1948 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001949 UiccController.getInstance().getPinStorage()
1950 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001951 } else {
1952 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1953 }
zoey chene02881a2019-12-30 16:11:23 +08001954 } else {
1955 request.result = msg.arg1;
1956 }
Michele Berionne5e411512020-11-13 02:36:59 +00001957
1958
zoey chene02881a2019-12-30 16:11:23 +08001959 notifyRequester(request);
1960 break;
1961
Peter Wangdafb9ac2020-01-15 14:13:38 -08001962 case MSG_NOTIFY_USER_ACTIVITY:
1963 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001964 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001965 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1966 getDefaultPhone().getContext().sendBroadcastAsUser(
1967 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1968 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001969
1970 case CMD_SET_DATA_THROTTLING: {
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1973 DataThrottlingRequest dataThrottlingRequest =
1974 (DataThrottlingRequest) request.argument;
1975 Phone phone = getPhoneFromRequest(request);
1976 if (phone != null) {
1977 phone.setDataThrottling(onCompleted,
1978 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1979 dataThrottlingRequest.getCompletionDurationMillis());
1980 } else {
1981 loge("setDataThrottling: No phone object");
1982 request.result =
1983 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1984 notifyRequester(request);
1985 }
1986
1987 break;
1988 }
1989 case EVENT_SET_DATA_THROTTLING_DONE:
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992
1993 if (ar.exception == null) {
1994 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1995 } else if (ar.exception instanceof CommandException) {
1996 loge("setDataThrottling: CommandException: " + ar.exception);
1997 CommandException.Error error =
1998 ((CommandException) (ar.exception)).getCommandError();
1999
2000 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2001 request.result = TelephonyManager
2002 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2003 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2004 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002005 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2006 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002007 } else {
2008 request.result =
2009 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2010 }
2011 } else {
2012 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2013 }
2014 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2015 notifyRequester(request);
2016 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002017
2018 case CMD_SET_SIM_POWER: {
2019 request = (MainThreadRequest) msg.obj;
2020 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2021 request = (MainThreadRequest) msg.obj;
2022 int stateToSet =
2023 ((Pair<Integer, IIntegerConsumer>)
2024 request.argument).first;
2025 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2026 break;
2027 }
2028 case EVENT_SET_SIM_POWER_DONE: {
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 IIntegerConsumer callback =
2032 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2033 if (ar.exception != null) {
2034 loge("setSimPower exception: " + ar.exception);
2035 int errorCode = TelephonyManager.CallForwardingInfoCallback
2036 .RESULT_ERROR_UNKNOWN;
2037 if (ar.exception instanceof CommandException) {
2038 CommandException.Error error =
2039 ((CommandException) (ar.exception)).getCommandError();
2040 if (error == CommandException.Error.SIM_ERR) {
2041 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2042 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2043 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2045 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2046 } else {
2047 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2048 }
2049 }
2050 try {
2051 callback.accept(errorCode);
2052 } catch (RemoteException e) {
2053 // Ignore if the remote process is no longer available to call back.
2054 Log.w(LOG_TAG, "setSimPower: callback not available.");
2055 }
2056 } else {
2057 try {
2058 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2059 } catch (RemoteException e) {
2060 // Ignore if the remote process is no longer available to call back.
2061 Log.w(LOG_TAG, "setSimPower: callback not available.");
2062 }
2063 }
2064 break;
2065 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002066 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2067 request = (MainThreadRequest) msg.obj;
2068
2069 final Phone phone = getPhoneFromRequest(request);
2070 if (phone == null || phone.getServiceStateTracker() == null) {
2071 request.result = new IllegalStateException("Phone or SST is null");
2072 notifyRequester(request);
2073 break;
2074 }
2075
2076 Pair<Integer, SignalStrengthUpdateRequest> pair =
2077 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2078 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2079 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002080 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002081 request.subId, pair.first /*callingUid*/,
2082 pair.second /*request*/, onCompleted);
2083 break;
2084 }
2085 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 // request.result will be the exception of ar if present, true otherwise.
2089 // Be cautious not to leave result null which will wait() forever
2090 request.result = ar.exception != null ? ar.exception : true;
2091 notifyRequester(request);
2092 break;
2093 }
2094 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2095 request = (MainThreadRequest) msg.obj;
2096
2097 Phone phone = getPhoneFromRequest(request);
2098 if (phone == null || phone.getServiceStateTracker() == null) {
2099 request.result = new IllegalStateException("Phone or SST is null");
2100 notifyRequester(request);
2101 break;
2102 }
2103
2104 Pair<Integer, SignalStrengthUpdateRequest> pair =
2105 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2106 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2107 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002108 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002109 request.subId, pair.first /*callingUid*/,
2110 pair.second /*request*/, onCompleted);
2111 break;
2112 }
2113 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2114 ar = (AsyncResult) msg.obj;
2115 request = (MainThreadRequest) ar.userObj;
2116 request.result = ar.exception != null ? ar.exception : true;
2117 notifyRequester(request);
2118 break;
2119 }
Jordan Liu109698e2020-11-24 14:50:34 -08002120
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 case CMD_GET_SLICING_CONFIG: {
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2124 request.phone.getSlicingConfig(onCompleted);
2125 break;
2126 }
2127 case EVENT_GET_SLICING_CONFIG_DONE: {
2128 ar = (AsyncResult) msg.obj;
2129 request = (MainThreadRequest) ar.userObj;
2130 ResultReceiver result = (ResultReceiver) request.argument;
2131
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002132 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 Bundle bundle = new Bundle();
2134 int resultCode = 0;
2135 if (ar.exception != null) {
2136 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2137 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002138 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002139 } else if (ar.result == null) {
2140 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002141 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002142 } else {
2143 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002144 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2145 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002146 }
2147
2148 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002149 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 }
2151 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2152 result.send(resultCode, bundle);
2153 notifyRequester(request);
2154 break;
2155 }
2156
Sarah Chin71b3a852022-09-28 15:54:19 -07002157 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002158 request = (MainThreadRequest) msg.obj;
2159 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002160 PurchasePremiumCapabilityArgument arg =
2161 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002162 SliceStore.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002163 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002164 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002165 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002166
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002168 ar = (AsyncResult) msg.obj;
2169 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002170 PurchasePremiumCapabilityArgument arg =
2171 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002172 try {
2173 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177 + ", result= "
2178 + TelephonyManager.convertPurchaseResultToString(result));
2179 } catch (RemoteException e) {
2180 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182 + " failed: " + e;
2183 if (DBG) log(logStr);
2184 AnomalyReporter.reportAnomaly(
2185 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2186 }
2187 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189
Michele Berionne5e411512020-11-13 02:36:59 +00002190 case CMD_PREPARE_UNATTENDED_REBOOT:
2191 request = (MainThreadRequest) msg.obj;
2192 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002193 UiccController.getInstance().getPinStorage()
2194 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002195 notifyRequester(request);
2196 break;
2197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 default:
2199 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2200 break;
2201 }
2202 }
Jake Hambye994d462014-02-03 13:10:13 -08002203
Pengquan Menga1bb6272018-09-06 09:59:22 -07002204 private void notifyRequester(MainThreadRequest request) {
2205 synchronized (request) {
2206 request.notifyAll();
2207 }
2208 }
2209
Jake Hambye994d462014-02-03 13:10:13 -08002210 private void handleNullReturnEvent(Message msg, String command) {
2211 AsyncResult ar = (AsyncResult) msg.obj;
2212 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2213 if (ar.exception == null) {
2214 request.result = true;
2215 } else {
2216 request.result = false;
2217 if (ar.exception instanceof CommandException) {
2218 loge(command + ": CommandException: " + ar.exception);
2219 } else {
2220 loge(command + ": Unknown exception");
2221 }
2222 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002223 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
2227 /**
2228 * Posts the specified command to be executed on the main thread,
2229 * waits for the request to complete, and returns the result.
2230 * @see #sendRequestAsync
2231 */
2232 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2234 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002235 }
2236
2237 /**
2238 * Posts the specified command to be executed on the main thread,
2239 * waits for the request to complete, and returns the result.
2240 * @see #sendRequestAsync
2241 */
2242 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2243 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002245 }
2246
2247 /**
2248 * Posts the specified command to be executed on the main thread,
2249 * waits for the request to complete, and returns the result.
2250 * @see #sendRequestAsync
2251 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002252 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2254 }
2255
2256 /**
2257 * Posts the specified command to be executed on the main thread,
2258 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2259 * if not timeout or null otherwise.
2260 * @see #sendRequestAsync
2261 */
2262 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2263 long timeoutInMs) {
2264 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002265 }
2266
2267 /**
2268 * Posts the specified command to be executed on the main thread,
2269 * waits for the request to complete, and returns the result.
2270 * @see #sendRequestAsync
2271 */
Nathan Harold92bed182018-10-12 18:16:49 -07002272 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002273 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002274 }
2275
2276 /**
2277 * Posts the specified command to be executed on the main thread,
2278 * waits for the request to complete, and returns the result.
2279 * @see #sendRequestAsync
2280 */
2281 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2283 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002284 }
2285
2286 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002287 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2288 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2289 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002290 * @see #sendRequestAsync
2291 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002292 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2293 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2295 throw new RuntimeException("This method will deadlock if called from the main thread.");
2296 }
2297
Nathan Harold92bed182018-10-12 18:16:49 -07002298 MainThreadRequest request = null;
2299 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2300 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2301 } else if (phone != null) {
2302 request = new MainThreadRequest(argument, phone, workSource);
2303 } else {
2304 request = new MainThreadRequest(argument, subId, workSource);
2305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 Message msg = mMainThreadHandler.obtainMessage(command, request);
2308 msg.sendToTarget();
2309
Rambo Wang0f050d82021-02-12 11:43:36 -08002310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 if (timeoutInMs >= 0) {
2313 // Wait for at least timeoutInMs before returning null request result
2314 long now = SystemClock.elapsedRealtime();
2315 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002316 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 try {
2318 request.wait(deadline - now);
2319 } catch (InterruptedException e) {
2320 // Do nothing, go back and check if request is completed or timeout
2321 } finally {
2322 now = SystemClock.elapsedRealtime();
2323 }
2324 }
2325 } else {
2326 // Wait for the request to complete
2327 while (request.result == null) {
2328 try {
2329 request.wait();
2330 } catch (InterruptedException e) {
2331 // Do nothing, go back and wait until the request is complete
2332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334 }
2335 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 if (request.result == null) {
2337 Log.wtf(LOG_TAG,
2338 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 return request.result;
2341 }
2342
2343 /**
2344 * Asynchronous ("fire and forget") version of sendRequest():
2345 * Posts the specified command to be executed on the main thread, and
2346 * returns immediately.
2347 * @see #sendRequest
2348 */
2349 private void sendRequestAsync(int command) {
2350 mMainThreadHandler.sendEmptyMessage(command);
2351 }
2352
2353 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002354 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002355 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002356 */
2357 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 sendRequestAsync(command, argument, null, null);
2359 }
2360
2361 /**
2362 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2363 * @see {@link #sendRequest(int,Object)}
2364 */
2365 private void sendRequestAsync(
2366 int command, Object argument, Phone phone, WorkSource workSource) {
2367 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002368 Message msg = mMainThreadHandler.obtainMessage(command, request);
2369 msg.sendToTarget();
2370 }
2371
2372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 * Initialize the singleton PhoneInterfaceManager instance.
2374 * This is only done once, at startup, from PhoneApp.onCreate().
2375 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002376 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 synchronized (PhoneInterfaceManager.class) {
2378 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002379 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 } else {
2381 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2382 }
2383 return sInstance;
2384 }
2385 }
2386
2387 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002388 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002391 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002394 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002397 mTelephonySharedPreferences =
2398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002401 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002402 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002403 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 publish();
2405 }
2406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002407 private Phone getDefaultPhone() {
2408 Phone thePhone = getPhone(getDefaultSubscription());
2409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2410 }
2411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 private void publish() {
2413 if (DBG) log("publish: " + this);
2414
Peter Wangc035ce42020-01-08 21:00:22 -08002415 TelephonyFrameworkInitializer
2416 .getTelephonyServiceManager()
2417 .getTelephonyServiceRegisterer()
2418 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
Stuart Scott584921c2015-01-15 17:10:34 -08002421 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002422 if (request.phone != null) {
2423 return request.phone;
2424 } else {
2425 return getPhoneFromSubId(request.subId);
2426 }
2427 }
2428
2429 private Phone getPhoneFromSubId(int subId) {
2430 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2431 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002432 }
2433
Rambo Wange53e07d2022-05-10 13:01:13 -07002434 @Nullable
2435 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 Phone phone = getPhoneFromRequest(request);
2437 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002438 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 }
2440
Wink Saville36469e72014-06-11 15:17:00 -07002441 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002442 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002443 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445
Kai Shif70f46f2021-03-03 13:59:46 -08002446 private void sendEraseModemConfig(@NonNull Phone phone) {
2447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2449 }
2450
2451 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2452 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2453 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002454 }
2455
Peter Wang44b186e2020-01-13 23:33:09 -08002456 private boolean isImsAvailableOnDevice() {
2457 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2458 if (pm == null) {
2459 // For some reason package manger is not available.. This will fail internally anyway,
2460 // so do not throw error and allow.
2461 return true;
2462 }
2463 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002467 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Wink Savilleb564aae2014-10-23 10:18:09 -07002470 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 if (DBG) log("dial: " + number);
2472 // No permission check needed here: This is just a wrapper around the
2473 // ACTION_DIAL intent, which is available to any app since it puts up
2474 // the UI before it does anything.
2475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 String url = createTelUrl(number);
2479 if (url == null) {
2480 return;
2481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 // PENDING: should we just silently fail if phone is offhook or ringing?
2484 PhoneConstants.State state = mCM.getState(subId);
2485 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2486 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2487 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2488 mApp.startActivity(intent);
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493 }
2494
2495 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 if (DBG) log("call: " + number);
2501
2502 // This is just a wrapper around the ACTION_CALL intent, but we still
2503 // need to do a permission check since we're calling startActivity()
2504 // from the context of the phone app.
2505 enforceCallPermission();
2506
Jordan Liu1617b712019-07-10 15:06:26 -07002507 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 != AppOpsManager.MODE_ALLOWED) {
2509 return;
2510 }
2511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 String url = createTelUrl(number);
2515 if (url == null) {
2516 return;
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 boolean isValid = false;
2520 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2521 if (slist != null) {
2522 for (SubscriptionInfo subInfoRecord : slist) {
2523 if (subInfoRecord.getSubscriptionId() == subId) {
2524 isValid = true;
2525 break;
2526 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002527 }
Wink Saville08874612014-08-31 19:19:58 -07002528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 if (!isValid) {
2530 return;
2531 }
Wink Saville08874612014-08-31 19:19:58 -07002532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2534 intent.putExtra(SUBSCRIPTION_KEY, subId);
2535 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2536 mApp.startActivity(intent);
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
2541
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002543 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2545 }
2546
Wink Savilleb564aae2014-10-23 10:18:09 -07002547 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002548 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2550 }
2551
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002557 Phone phone = getPhone(subId);
2558 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 checkSimPin.start();
2560 return checkSimPin.unlockSim(null, pin);
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002571 Phone phone = getPhone(subId);
2572 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 checkSimPuk.start();
2574 return checkSimPuk.unlockSim(puk, pin);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002581 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 * a synchronous one.
2583 */
2584 private static class UnlockSim extends Thread {
2585
2586 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002587 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588
2589 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002590 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2591 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 // For replies from SimCard interface
2594 private Handler mHandler;
2595
2596 // For async handler to identify request type
2597 private static final int SUPPLY_PIN_COMPLETE = 100;
2598
Michele Berionne5e411512020-11-13 02:36:59 +00002599 UnlockSim(int phoneId, IccCard simCard) {
2600 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 mSimCard = simCard;
2602 }
2603
2604 @Override
2605 public void run() {
2606 Looper.prepare();
2607 synchronized (UnlockSim.this) {
2608 mHandler = new Handler() {
2609 @Override
2610 public void handleMessage(Message msg) {
2611 AsyncResult ar = (AsyncResult) msg.obj;
2612 switch (msg.what) {
2613 case SUPPLY_PIN_COMPLETE:
2614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002616 mRetryCount = msg.arg1;
2617 if (ar.exception != null) {
2618 if (ar.exception instanceof CommandException &&
2619 ((CommandException)(ar.exception)).getCommandError()
2620 == CommandException.Error.PASSWORD_INCORRECT) {
2621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002622 } //When UiccCardApp dispose,handle message and return exception
2623 else if (ar.exception instanceof CommandException &&
2624 ((CommandException) (ar.exception)).getCommandError()
2625 == CommandException.Error.ABORTED) {
2626 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002627 } else {
2628 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2629 }
2630 } else {
2631 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 mDone = true;
2634 UnlockSim.this.notifyAll();
2635 }
2636 break;
2637 }
2638 }
2639 };
2640 UnlockSim.this.notifyAll();
2641 }
2642 Looper.loop();
2643 }
2644
2645 /*
2646 * Use PIN or PUK to unlock SIM card
2647 *
2648 * If PUK is null, unlock SIM card with PIN
2649 *
2650 * If PUK is not null, unlock SIM card with PUK and set PIN code
2651 */
Wink Saville9de0f752013-10-22 19:04:03 -07002652 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653
2654 while (mHandler == null) {
2655 try {
2656 wait();
2657 } catch (InterruptedException e) {
2658 Thread.currentThread().interrupt();
2659 }
2660 }
2661 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2662
2663 if (puk == null) {
2664 mSimCard.supplyPin(pin, callback);
2665 } else {
2666 mSimCard.supplyPuk(puk, pin, callback);
2667 }
2668
2669 while (!mDone) {
2670 try {
2671 Log.d(LOG_TAG, "wait for done");
2672 wait();
2673 } catch (InterruptedException e) {
2674 // Restore the interrupted status
2675 Thread.currentThread().interrupt();
2676 }
2677 }
2678 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002679 int[] resultArray = new int[2];
2680 resultArray[0] = mResult;
2681 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002682
2683 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002684 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002685 }
2686
Wink Saville9de0f752013-10-22 19:04:03 -07002687 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689 }
2690
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002691 /**
2692 * This method has been removed due to privacy and stability concerns.
2693 */
2694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002696 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2697 return;
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Nathan Harold1f889d82020-06-04 17:05:26 -07002700 @Override
2701 public void updateServiceLocationWithPackageName(String callingPackage) {
2702 mApp.getSystemService(AppOpsManager.class)
2703 .checkPackage(Binder.getCallingUid(), callingPackage);
2704
Nathan Haroldf096d982020-11-18 17:18:06 -08002705 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002706 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2707 // Callers targeting S have no business invoking this method.
2708 return;
2709 }
2710
2711 LocationAccessPolicy.LocationPermissionResult locationResult =
2712 LocationAccessPolicy.checkLocationPermission(mApp,
2713 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2714 .setCallingPackage(callingPackage)
2715 .setCallingFeatureId(null)
2716 .setCallingPid(Binder.getCallingPid())
2717 .setCallingUid(Binder.getCallingUid())
2718 .setMethod("updateServiceLocation")
2719 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2720 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2721 .build());
2722 // Apps that lack location permission have no business calling this method;
2723 // however, because no permission was declared in the public API, denials must
2724 // all be "soft".
2725 switch (locationResult) {
2726 case DENIED_HARD: /* fall through */
2727 case DENIED_SOFT:
2728 return;
2729 }
2730
2731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002734 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002736 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002743 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002744 @Override
2745 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002746 return isRadioOnWithFeature(callingPackage, null);
2747 }
2748
2749
2750 @Override
2751 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2752 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2753 callingFeatureId);
2754 }
2755
2756 @Deprecated
2757 @Override
2758 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2759 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002763 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002766 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 return false;
2768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 return isRadioOnForSubscriber(subId);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 }
2777
2778 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
2783 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
2792 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002793 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
Wink Saville36469e72014-06-11 15:17:00 -07002795
Wink Savilleb564aae2014-10-23 10:18:09 -07002796 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002807 }
Wink Saville36469e72014-06-11 15:17:00 -07002808 }
2809
2810 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002811 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
Wink Savilleb564aae2014-10-23 10:18:09 -07002814 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone == null) {
2821 return false;
2822 }
2823 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2824 toggleRadioOnOffForSubscriber(subId);
2825 }
2826 return true;
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
Wink Saville36469e72014-06-11 15:17:00 -07002831
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002833 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002834 /*
2835 * If any of the Radios are available, it will need to be
2836 * shutdown. So return true if any Radio is available.
2837 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2841 Phone phone = PhoneFactory.getPhone(i);
2842 if (phone != null && phone.isRadioAvailable()) return true;
2843 }
2844 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2845 return false;
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002848 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002849 }
2850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002852 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 enforceModifyPermission();
2854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2858 logv("Shutting down Phone " + i);
2859 shutdownRadioUsingPhoneId(i);
2860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 }
2864 }
2865
2866 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 Phone phone = PhoneFactory.getPhone(phoneId);
2868 if (phone != null && phone.isRadioAvailable()) {
2869 phone.shutdownRadio();
2870 }
2871 }
2872
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2879 if (defaultPhone != null) {
2880 defaultPhone.setRadioPower(turnOn);
2881 return true;
2882 } else {
2883 loge("There's no default phone.");
2884 return false;
2885 }
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002888 }
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Wink Savilleb564aae2014-10-23 10:18:09 -07002891 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 phone.setRadioPower(turnOn);
2899 return true;
2900 } else {
2901 return false;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002908 /**
2909 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2910 * no reason to power it off. When any of the voters want to power it off, it will be turned
2911 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2912 * powering it off, and these radio off votes will be cleared.
2913 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2914 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2915 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2916 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2917 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2918 * check its vote.
2919 *
2920 * @param subId The subscription ID.
2921 * @param reason The reason for powering off radio.
2922 * @return true on success and false on failure.
2923 */
2924 public boolean requestRadioPowerOffForReason(int subId,
2925 @TelephonyManager.RadioPowerReason int reason) {
2926 enforceModifyPermission();
2927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 final Phone phone = getPhone(subId);
2931 if (phone != null) {
2932 phone.setRadioPowerForReason(false, reason);
2933 return true;
2934 } else {
2935 return false;
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 /**
2943 * Remove the vote on powering off the radio for a reason, as requested by
2944 * {@link requestRadioPowerOffForReason}.
2945 *
2946 * @param subId The subscription ID.
2947 * @param reason The reason for powering off radio.
2948 * @return true on success and false on failure.
2949 */
2950 public boolean clearRadioPowerOffForReason(int subId,
2951 @TelephonyManager.RadioPowerReason int reason) {
2952 enforceModifyPermission();
2953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 if (phone != null) {
2958 phone.setRadioPowerForReason(true, reason);
2959 return true;
2960 } else {
2961 return false;
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 /**
2969 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2970 *
2971 * @param subId The subscription ID.
2972 * @param callingPackage The package making the call.
2973 * @param callingFeatureId The feature in the package.
2974 * @return List of reasons for powering off radio.
2975 */
2976 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2977 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2978
2979 final long identity = Binder.clearCallingIdentity();
2980 List result = new ArrayList();
2981 try {
2982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2983 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2984 return result;
2985 }
2986
2987 final Phone phone = getPhone(subId);
2988 if (phone != null) {
2989 result.addAll(phone.getRadioPowerOffReasons());
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 return result;
2995 }
2996
Wink Saville36469e72014-06-11 15:17:00 -07002997 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002999 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 int subId = mSubscriptionController.getDefaultDataSubId();
3005 final Phone phone = getPhone(subId);
3006 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003007 phone.getDataSettingsManager().setDataEnabled(
3008 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 return true;
3010 } else {
3011 return false;
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Wink Saville36469e72014-06-11 15:17:00 -07003018 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003020 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 int subId = mSubscriptionController.getDefaultDataSubId();
3026 final Phone phone = getPhone(subId);
3027 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003028 phone.getDataSettingsManager().setDataEnabled(
3029 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 return true;
3031 } else {
3032 return false;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003040 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003045 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 } else {
3047 return false;
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
3054 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003055 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003056 }
3057
pkanwarae03a6b2016-11-06 20:37:09 -08003058 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 enforceCallPermission();
3060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3064 return;
3065 }
3066 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3067 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
pkanwar32d516d2016-10-14 19:37:38 -07003071 };
3072
Wink Savilleb564aae2014-10-23 10:18:09 -07003073 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3079 return false;
3080 }
3081 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 }
3086
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003087 /**
3088 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3089 * tag on getCallState Binder call.
3090 */
3091 @Deprecated
3092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003094 if (CompatChanges.isChangeEnabled(
3095 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3096 Binder.getCallingUid())) {
3097 // Do not allow this API to be called on API version 31+, it should only be
3098 // called on old apps using this Binder call directly.
3099 throw new SecurityException("This method can only be used for applications "
3100 + "targeting API version 30 or less.");
3101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003104 Phone phone = getPhone(getDefaultSubscription());
3105 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3106 PhoneConstantConversions.convertCallState(phone.getState());
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3114 if (CompatChanges.isChangeEnabled(
3115 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3116 Binder.getCallingUid())) {
3117 // Check READ_PHONE_STATE for API version 31+
3118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3119 featureId, "getCallStateForSubscription")) {
3120 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3121 + "targeting API level 31+.");
3122 }
3123 }
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3128 PhoneConstantConversions.convertCallState(phone.getState());
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003135 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003136 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3137 }
3138
3139 @Override
3140 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 final long identity = Binder.clearCallingIdentity();
3142 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003143 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003145 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 } else {
3147 return PhoneConstantConversions.convertDataState(
3148 PhoneConstants.DataState.DISCONNECTED);
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003156 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003157 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3158 }
3159
3160 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003161 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003164 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003166 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 } else {
3168 return TelephonyManager.DATA_ACTIVITY_NONE;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003176 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003178 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003179
3180 LocationAccessPolicy.LocationPermissionResult locationResult =
3181 LocationAccessPolicy.checkLocationPermission(mApp,
3182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3183 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setCallingPid(Binder.getCallingPid())
3186 .setCallingUid(Binder.getCallingUid())
3187 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3190 .build());
3191 switch (locationResult) {
3192 case DENIED_HARD:
3193 throw new SecurityException("Not allowed to access cell location");
3194 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003195 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3196 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003203 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003204 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
Svetoslav64fad262015-04-14 14:35:21 -07003208 }
3209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003211 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003212 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3213 // registered cell info, so return a NULL country instead.
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003216 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3217 // Get default phone in this case.
3218 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3219 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003220 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003222 if (phone == null) return "";
3223 ServiceStateTracker sst = phone.getServiceStateTracker();
3224 if (sst == null) return "";
3225 LocaleTracker lt = sst.getLocaleTracker();
3226 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003227 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003231 }
3232
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003233 /**
3234 * This method was removed due to potential issues caused by performing partial
3235 * updates of service state, and lack of a credible use case.
3236 *
3237 * This has the ability to break the telephony implementation by disabling notification of
3238 * changes in device connectivity. DO NOT USE THIS!
3239 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003240 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 public void enableLocationUpdates() {
3242 mApp.enforceCallingOrSelfPermission(
3243 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003246 /**
3247 * This method was removed due to potential issues caused by performing partial
3248 * updates of service state, and lack of a credible use case.
3249 *
3250 * This has the ability to break the telephony implementation by disabling notification of
3251 * changes in device connectivity. DO NOT USE THIS!
3252 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 @Override
3254 public void disableLocationUpdates() {
3255 mApp.enforceCallingOrSelfPermission(
3256 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
3259 @Override
3260 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003261 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3262 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003263 try {
3264 mApp.getSystemService(AppOpsManager.class)
3265 .checkPackage(Binder.getCallingUid(), callingPackage);
3266 } catch (SecurityException e) {
3267 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3268 throw e;
3269 }
3270
Nathan Haroldf096d982020-11-18 17:18:06 -08003271 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003272 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3273 throw new SecurityException(
3274 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3275 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003276
Jordan Liu1617b712019-07-10 15:06:26 -07003277 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3279 return null;
3280 }
Svetoslav64fad262015-04-14 14:35:21 -07003281
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003282 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003284 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003285 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286
Nathan Haroldf180aac2018-06-01 18:43:55 -07003287 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3288 for (CellInfo ci : info) {
3289 if (ci instanceof CellInfoGsm) {
3290 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3291 } else if (ci instanceof CellInfoWcdma) {
3292 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003295 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003298 private List<CellInfo> getCachedCellInfo() {
3299 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3300 for (Phone phone : PhoneFactory.getPhones()) {
3301 List<CellInfo> info = phone.getAllCellInfo();
3302 if (info != null) cellInfos.addAll(info);
3303 }
3304 return cellInfos;
3305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306
3307 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003308 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003310 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003311
3312 LocationAccessPolicy.LocationPermissionResult locationResult =
3313 LocationAccessPolicy.checkLocationPermission(mApp,
3314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3315 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003316 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003317 .setCallingPid(Binder.getCallingPid())
3318 .setCallingUid(Binder.getCallingUid())
3319 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003320 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003321 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3322 .build());
3323 switch (locationResult) {
3324 case DENIED_HARD:
3325 throw new SecurityException("Not allowed to access cell info");
3326 case DENIED_SOFT:
3327 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
Nathan Haroldf096d982020-11-18 17:18:06 -08003330 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003331 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3332 return getCachedCellInfo();
3333 }
3334
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003335 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3340 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003341 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003342 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 if (info != null) cellInfos.addAll(info);
3344 }
3345 return cellInfos;
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 }
3349 }
3350
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003351 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003352 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3353 String callingFeatureId) {
3354 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3355 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003356 }
3357
3358 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003359 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3360 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003361 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003362 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003363 }
3364
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3366 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003369
3370 LocationAccessPolicy.LocationPermissionResult locationResult =
3371 LocationAccessPolicy.checkLocationPermission(mApp,
3372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3373 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003375 .setCallingPid(Binder.getCallingPid())
3376 .setCallingUid(Binder.getCallingUid())
3377 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003378 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3379 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .build());
3381 switch (locationResult) {
3382 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003383 if (TelephonyPermissions
3384 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003385 // Safetynet logging for b/154934934
3386 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3387 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003388 throw new SecurityException("Not allowed to access cell info");
3389 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003390 if (TelephonyPermissions
3391 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003392 // Safetynet logging for b/154934934
3393 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3394 }
Nathan Harold5320c422019-05-09 10:26:08 -07003395 try {
3396 cb.onCellInfo(new ArrayList<CellInfo>());
3397 } catch (RemoteException re) {
3398 // Drop without consequences
3399 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003401 }
3402
Nathan Harolda939a962019-05-09 10:13:47 -07003403
3404 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3406
3407 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3408 }
3409
3410 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003411 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003412 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003417 Phone phone = getPhone(subId);
3418 if (phone == null) {
3419 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3420 } else {
3421 phone.setCellInfoListRate(rateInMillis, workSource);
3422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 }
3427
Shishir Agrawala9f32182016-04-12 12:00:16 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 Phone phone = PhoneFactory.getPhone(slotIndex);
3431 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 return null;
3433 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003434 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003435 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003436 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003437 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 return null;
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return phone.getImei();
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003447 }
3448
3449 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003450 public String getTypeAllocationCodeForSlot(int slotIndex) {
3451 Phone phone = PhoneFactory.getPhone(slotIndex);
3452 String tac = null;
3453 if (phone != null) {
3454 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003455 try {
3456 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3457 } catch (IndexOutOfBoundsException e) {
3458 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3459 return null;
3460 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003461 }
3462 return tac;
3463 }
3464
3465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003466 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003467 try {
3468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3469 } catch (SecurityException se) {
3470 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3471 throw new SecurityException("Package " + callingPackage + " does not belong to "
3472 + Binder.getCallingUid());
3473 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003474 Phone phone = PhoneFactory.getPhone(slotIndex);
3475 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003476 return null;
3477 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003480 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003482 return null;
3483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 return phone.getMeid();
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
Jack Yu2af8d712017-03-15 17:14:14 -07003491 }
3492
3493 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003494 public String getManufacturerCodeForSlot(int slotIndex) {
3495 Phone phone = PhoneFactory.getPhone(slotIndex);
3496 String manufacturerCode = null;
3497 if (phone != null) {
3498 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003499 try {
3500 manufacturerCode =
3501 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3502 } catch (IndexOutOfBoundsException e) {
3503 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3504 return null;
3505 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003506 }
3507 return manufacturerCode;
3508 }
3509
3510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3512 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003513 Phone phone = PhoneFactory.getPhone(slotIndex);
3514 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 return null;
3516 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 int subId = phone.getSubId();
3518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 mApp, subId, callingPackage, callingFeatureId,
3520 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 return null;
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return phone.getDeviceSvn();
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 }
3531
fionaxu43304da2017-11-27 22:51:16 -08003532 @Override
3533 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = getPhone(subId);
3537 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
fionaxu43304da2017-11-27 22:51:16 -08003541 }
3542
3543 @Override
3544 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 return phone == null ? null : phone.getCarrierName();
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
fionaxu43304da2017-11-27 22:51:16 -08003552 }
3553
calvinpanffe225e2018-11-01 19:43:06 +08003554 @Override
chen xu0026ca62019-03-06 15:28:50 -08003555 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003560 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
3566 @Override
chen xu0026ca62019-03-06 15:28:50 -08003567 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003571 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
chen xu651eec72018-11-11 19:03:44 -08003577 @Override
chen xu864e11c2018-12-06 22:10:03 -08003578 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3579 if (!isSubscriptionMccMnc) {
3580 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3581 }
chen xu651eec72018-11-11 19:03:44 -08003582 final Phone phone = PhoneFactory.getPhone(slotIndex);
3583 if (phone == null) {
3584 return TelephonyManager.UNKNOWN_CARRIER_ID;
3585 }
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 //
3595 // Internal helper methods.
3596 //
3597
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003598 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003599 * Make sure the caller is the calling package itself
3600 *
3601 * @throws SecurityException if the caller is not the calling package
3602 */
3603 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3604 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003605 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3606 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003607 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003608 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003609 } catch (PackageManager.NameNotFoundException e) {
3610 // packageUid is -1
3611 }
3612 if (packageUid != callingUid) {
3613 throw new SecurityException(message + ": Package " + callingPackage
3614 + " does not belong to " + callingUid);
3615 }
3616 }
3617
3618 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3620 *
3621 * @throws SecurityException if the caller does not have the required permission
3622 */
3623 private void enforceModifyPermission() {
3624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3625 }
3626
Shuo Qian3b6ee772019-11-13 17:43:31 -08003627 private void enforceActiveEmergencySessionPermission() {
3628 mApp.enforceCallingOrSelfPermission(
3629 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3630 }
3631
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 /**
3633 * Make sure the caller has the CALL_PHONE permission.
3634 *
3635 * @throws SecurityException if the caller does not have the required permission
3636 */
3637 private void enforceCallPermission() {
3638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3639 }
3640
paulhu5a773602019-08-23 19:17:33 +08003641 private void enforceSettingsPermission() {
3642 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003643 }
3644
Michele Berionne5e411512020-11-13 02:36:59 +00003645 private void enforceRebootPermission() {
3646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3647 }
3648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 private String createTelUrl(String number) {
3650 if (TextUtils.isEmpty(number)) {
3651 return null;
3652 }
3653
Jake Hambye994d462014-02-03 13:10:13 -08003654 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 }
3656
Ihab Awadf9e92732013-12-05 18:02:52 -08003657 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3659 }
3660
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003661 private static void logv(String msg) {
3662 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3663 }
3664
Ihab Awadf9e92732013-12-05 18:02:52 -08003665 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3667 }
3668
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003669 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003671 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Sanket Padawe356d7632015-06-22 14:03:32 -07003674 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003675 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = PhoneFactory.getPhone(slotIndex);
3679 if (phone == null) {
3680 return PhoneConstants.PHONE_TYPE_NONE;
3681 } else {
3682 return phone.getPhoneType();
3683 }
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 }
3688
3689 /**
3690 * Returns the CDMA ERI icon index to display
3691 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003693 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3694 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3695 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003696 }
3697
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3700 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 mApp, subId, callingPackage, callingFeatureId,
3703 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 return -1;
3705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 final Phone phone = getPhone(subId);
3710 if (phone != null) {
3711 return phone.getCdmaEriIconIndex();
3712 } else {
3713 return -1;
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
3721 * Returns the CDMA ERI icon mode,
3722 * 0 - ON
3723 * 1 - FLASHING
3724 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003726 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3727 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3728 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003729 }
3730
Sanket Padawe356d7632015-06-22 14:03:32 -07003731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003732 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003735 mApp, subId, callingPackage, callingFeatureId,
3736 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 return -1;
3738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 final Phone phone = getPhone(subId);
3743 if (phone != null) {
3744 return phone.getCdmaEriIconMode();
3745 } else {
3746 return -1;
3747 }
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003751 }
3752
3753 /**
3754 * Returns the CDMA ERI text,
3755 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3758 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3759 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003760 }
3761
Sanket Padawe356d7632015-06-22 14:03:32 -07003762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003766 mApp, subId, callingPackage, callingFeatureId,
3767 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003768 return null;
3769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 return phone.getCdmaEriText();
3776 } else {
3777 return null;
3778 }
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 }
3783
3784 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003785 * Returns the CDMA MDN.
3786 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003788 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 return phone.getLine1Number();
3797 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 return null;
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003803 }
3804 }
3805
3806 /**
3807 * Returns the CDMA MIN.
3808 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003809 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003810 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
3814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3818 return phone.getCdmaMin();
3819 } else {
3820 return null;
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003824 }
3825 }
3826
Hall Liud892bec2018-11-30 14:51:45 -08003827 @Override
3828 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3829 INumberVerificationCallback callback, String callingPackage) {
3830 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3831 != PERMISSION_GRANTED) {
3832 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3833 }
3834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3835
3836 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3837 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003838 throw new SecurityException("Calling package must be configured in the device config: "
3839 + "calling package: " + callingPackage
3840 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003841 }
3842
3843 if (range == null) {
3844 throw new NullPointerException("Range must be non-null");
3845 }
3846
3847 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003848 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003849
3850 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3851 }
3852
Junda Liuca05d5d2014-08-14 22:36:34 -07003853 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 * Returns true if CDMA provisioning needs to run.
3855 */
3856 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003863 }
3864
3865 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003866 * Sets the voice mail number of a given subId.
3867 */
3868 @Override
3869 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3871 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3876 new Pair<String, String>(alphaTag, number), new Integer(subId));
3877 return success;
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003881 }
3882
Ta-wei Yen87c49842016-05-13 21:19:52 -07003883 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003884 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003886 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3887 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003888 if (!TextUtils.equals(callingPackage, systemDialer)) {
3889 throw new SecurityException("caller must be system dialer");
3890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
3892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3895 if (phoneAccountHandle == null) {
3896 return null;
3897 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 } finally {
3900 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003901 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003902 }
3903
3904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003905 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3906 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003909 mApp, subId, callingPackage, callingFeatureId,
3910 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003911 return null;
3912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003920 }
3921
3922 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003923 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3924 VisualVoicemailSmsFilterSettings settings) {
3925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003934 }
3935
3936 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003937 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3938 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003947 }
3948
3949 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003950 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3951 String callingPackage, int subId) {
3952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003961 }
3962
3963 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003964 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003974 }
3975
3976 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003977 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3978 String callingAttributionTag, int subId, String number, int port, String text,
3979 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003981 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003982 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003983 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003984 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3985 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003986 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003987
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003988 /**
fionaxu0152e512016-11-14 13:36:14 -08003989 * Sets the voice activation state of a given subId.
3990 */
3991 @Override
3992 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3994 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 final Phone phone = getPhone(subId);
3999 if (phone != null) {
4000 phone.setVoiceActivationState(activationState);
4001 } else {
4002 loge("setVoiceActivationState fails with invalid subId: " + subId);
4003 }
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004006 }
4007 }
4008
4009 /**
4010 * Sets the data activation state of a given subId.
4011 */
4012 @Override
4013 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 final Phone phone = getPhone(subId);
4020 if (phone != null) {
4021 phone.setDataActivationState(activationState);
4022 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004023 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024 }
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004027 }
4028 }
4029
4030 /**
4031 * Returns the voice activation state of a given subId.
4032 */
4033 @Override
4034 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036
fionaxu0152e512016-11-14 13:36:14 -08004037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 if (phone != null) {
4041 return phone.getVoiceActivationState();
4042 } else {
4043 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004047 }
4048 }
4049
4050 /**
4051 * Returns the data activation state of a given subId.
4052 */
4053 @Override
4054 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056
fionaxu0152e512016-11-14 13:36:14 -08004057 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 if (phone != null) {
4061 return phone.getDataActivationState();
4062 } else {
4063 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4064 }
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004067 }
4068 }
4069
4070 /**
Wink Saville36469e72014-06-11 15:17:00 -07004071 * Returns the unread count of voicemails for a subId
4072 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004079 return 0;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 if (phone != null) {
4085 return phone.getVoiceMessageCount();
4086 } else {
4087 return 0;
4088 }
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 }
4093
4094 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004095 * returns true, if the device is in a state where both voice and data
4096 * are supported simultaneously. This can change based on location or network condition.
4097 */
4098 @Override
4099 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 final Phone phone = getPhone(subId);
4103 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004107 }
4108
4109 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004110 * Send the dialer code if called from the current default dialer or the caller has
4111 * carrier privilege.
4112 * @param inputCode The dialer code to send
4113 */
4114 @Override
4115 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004116 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004118 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4119 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004120 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
fionaxu235cc5e2017-03-06 22:25:57 -08004131 }
4132
Pengquan Menga1bb6272018-09-06 09:59:22 -07004133 @Override
4134 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004135 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004136 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004137 mApp, subId, "getNetworkSelectionMode");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 if (!isActiveSubscription(subId)) {
4141 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4142 }
4143 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004146 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004147 }
4148
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004150 public boolean isInEmergencySmsMode() {
4151 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 for (Phone phone : PhoneFactory.getPhones()) {
4155 if (phone.isInEmergencySmsMode()) {
4156 return true;
4157 }
4158 }
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 return false;
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4172 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004173 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004174 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004175
4176 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4177 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4178 "IMS not available on device.");
4179 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 final long token = Binder.clearCallingIdentity();
4181 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004182 int slotId = getSlotIndexOrException(subId);
4183 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004184
4185 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4186 if (controller != null) {
4187 ImsManager imsManager = controller.getImsManager(subId);
4188 if (imsManager != null) {
4189 imsManager.addRegistrationCallbackForSubscription(c, subId);
4190 } else {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4192 }
4193 } else {
4194 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4195 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 } catch (ImsException e) {
4197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
4201 }
4202
shilu366312e2019-12-17 09:28:10 -08004203 /**
4204 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4205 * @param subId The subscription to use to check the configuration.
4206 * @param c The callback that will be used to send the result.
4207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004209 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004210 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004211 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4214 }
Meng Wangafbc5852019-09-19 17:37:13 -07004215 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004216
Meng Wangafbc5852019-09-19 17:37:13 -07004217 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004218 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4219 if (controller != null) {
4220 ImsManager imsManager = controller.getImsManager(subId);
4221 if (imsManager != null) {
4222 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4223 } else {
4224 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4225 + "is inactive, ignoring unregister.");
4226 // If the ImsManager is not valid, just return, since the callback
4227 // will already have been removed internally.
4228 }
4229 }
Meng Wangafbc5852019-09-19 17:37:13 -07004230 } finally {
4231 Binder.restoreCallingIdentity(token);
4232 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 }
4234
Brad Ebingera34a6c22019-10-22 17:36:18 -07004235 /**
4236 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4237 */
4238 @Override
4239 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4240 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4243 "IMS not available on device.");
4244 }
4245 final long token = Binder.clearCallingIdentity();
4246 try {
4247 Phone phone = getPhone(subId);
4248 if (phone == null) {
4249 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4250 + subId + "'");
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4252 }
4253 phone.getImsRegistrationState(regState -> {
4254 try {
4255 consumer.accept((regState == null)
4256 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4257 } catch (RemoteException e) {
4258 // Ignore if the remote process is no longer available to call back.
4259 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4260 }
4261 });
4262 } finally {
4263 Binder.restoreCallingIdentity(token);
4264 }
4265 }
4266
4267 /**
4268 * Get the transport type for the IMS service registration state.
4269 */
4270 @Override
4271 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004273 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004274 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4276 "IMS not available on device.");
4277 }
4278 final long token = Binder.clearCallingIdentity();
4279 try {
4280 Phone phone = getPhone(subId);
4281 if (phone == null) {
4282 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4283 + subId + "'");
4284 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4285 }
4286 phone.getImsRegistrationTech(regTech -> {
4287 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4288 int regTechConverted = (regTech == null)
4289 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4290 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4291 regTechConverted);
4292 try {
4293 consumer.accept(regTechConverted);
4294 } catch (RemoteException e) {
4295 // Ignore if the remote process is no longer available to call back.
4296 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4297 }
4298 });
4299 } finally {
4300 Binder.restoreCallingIdentity(token);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
4305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4306 * @param subId The subscription to use to check the configuration.
4307 * @param c The callback that will be used to send the result.
4308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004310 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4311 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004312 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4316 "IMS not available on device.");
4317 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long token = Binder.clearCallingIdentity();
4319 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004320 int slotId = getSlotIndexOrException(subId);
4321 verifyImsMmTelConfiguredOrThrow(slotId);
4322 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 } finally {
4326 Binder.restoreCallingIdentity(token);
4327 }
4328 }
4329
shilu366312e2019-12-17 09:28:10 -08004330 /**
4331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 * @param c The callback that will be used to send the result.
4334 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004336 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004337 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004338 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4341 }
Meng Wangafbc5852019-09-19 17:37:13 -07004342
4343 final long token = Binder.clearCallingIdentity();
4344 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004345 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004346 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004347 } catch (ImsException e) {
4348 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4349 + "is inactive, ignoring unregister.");
4350 // If the subscription is no longer active, just return, since the callback
4351 // will already have been removed internally.
4352 } finally {
4353 Binder.restoreCallingIdentity(token);
4354 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 }
4356
4357 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004358 public boolean isCapable(int subId, int capability, int regTech) {
4359 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 final long token = Binder.clearCallingIdentity();
4361 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004362 int slotId = getSlotIndexOrException(subId);
4363 verifyImsMmTelConfiguredOrThrow(slotId);
4364 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4365 } catch (com.android.ims.ImsException e) {
4366 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4367 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004369 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4370 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(token);
4373 }
4374 }
4375
4376 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004377 public boolean isAvailable(int subId, int capability, int regTech) {
4378 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long token = Binder.clearCallingIdentity();
4380 try {
4381 Phone phone = getPhone(subId);
4382 if (phone == null) return false;
4383 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004384 } catch (com.android.ims.ImsException e) {
4385 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4386 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
4390 }
4391
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004392 /**
4393 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4394 * subscription.
4395 * @param subId The subscription to use to check the configuration.
4396 * @param callback The callback that will be used to send the result.
4397 * @param capability The MmTelFeature capability that will be used to send the result.
4398 * @param transportType The transport type of the MmTelFeature capability.
4399 */
4400 @Override
4401 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4402 int transportType) {
4403 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4406 "IMS not available on device.");
4407 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004408 final long token = Binder.clearCallingIdentity();
4409 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004410 int slotId = getSlotIndex(subId);
4411 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4412 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4413 + subId + "'");
4414 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4415 }
4416 verifyImsMmTelConfiguredOrThrow(slotId);
4417 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4418 transportType, aBoolean -> {
4419 try {
4420 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4421 } catch (RemoteException e) {
4422 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4423 + "running. Ignore");
4424 }
4425 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004428 } finally {
4429 Binder.restoreCallingIdentity(token);
4430 }
4431 }
4432
shilu366312e2019-12-17 09:28:10 -08004433 /**
4434 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4435 * @param subId The subscription to use to check the configuration.
4436 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 @Override
4438 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004441
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 final long token = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004445 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(token);
4451 }
4452 }
4453
4454 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004455 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004457 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004476 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004492 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004494 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
4528 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004529 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004531 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004535 // This setting doesn't require an active ImsService connection, so do not verify. The
4536 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
shilu366312e2019-12-17 09:28:10 -08004545 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004546 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4548 * @param subId The subscription to use to check the configuration.
4549 */
4550 @Override
4551 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004553 mApp, subId, "isCrossSimCallingEnabledByUser");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
4566 /**
4567 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4568 * Requires MODIFY_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4571 * false otherwise
4572 */
4573 @Override
4574 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4576 "setCrossSimCallingEnabled");
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify. The
4581 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
4588 }
4589
4590 /**
shilu366312e2019-12-17 09:28:10 -08004591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004595
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004598 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 final long identity = Binder.clearCallingIdentity();
4600 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004601 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004602 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004612 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004614 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify. The
4619 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
4628 @Override
4629 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4631 "setVoWiFiNonPersistent");
4632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004636 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (ImsException e) {
4638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
shilu366312e2019-12-17 09:28:10 -08004644 /**
4645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4646 * @param subId The subscription to use to check the configuration.
4647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 @Override
4649 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004650 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004651 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004655 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (ImsException e) {
4658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public void setVoWiFiModeSetting(int subId, int mode) {
4666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4667 "setVoWiFiModeSetting");
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004671 // This setting doesn't require an active ImsService connection, so do not verify. The
4672 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004673 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 } catch (ImsException e) {
4675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 } finally {
4677 Binder.restoreCallingIdentity(identity);
4678 }
4679 }
4680
4681 @Override
4682 public int getVoWiFiRoamingModeSetting(int subId) {
4683 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004686 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004687 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (ImsException e) {
4690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
4696 @Override
4697 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4699 "setVoWiFiRoamingModeSetting");
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004703 // This setting doesn't require an active ImsService connection, so do not verify. The
4704 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004706 } catch (ImsException e) {
4707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
4711 }
4712
4713 @Override
4714 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4716 "setRttCapabilityEnabled");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004720 // This setting doesn't require an active ImsService connection, so do not verify. The
4721 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
shilu366312e2019-12-17 09:28:10 -08004730 /**
4731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4732 * @param subId The subscription to use to check the configuration.
4733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 @Override
4735 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004736 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004737 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004740 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004741 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004742 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004743 } catch (ImsException e) {
4744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004750 @Override
4751 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4752 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004753
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 final long identity = Binder.clearCallingIdentity();
4755 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004756 if (!isImsAvailableOnDevice()) {
4757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4758 "IMS not available on device.");
4759 }
4760 int slotId = getSlotIndexOrException(subId);
4761 verifyImsMmTelConfiguredOrThrow(slotId);
4762 ImsManager.getInstance(mApp, slotId)
4763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004764 } catch (ImsException e) {
4765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
4771 @Override
4772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004774
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4778 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4784 + "is inactive, ignoring unregister.");
4785 // If the subscription is no longer active, just return, since the callback will already
4786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
4790 }
4791
joonhunshincffb7fc2021-11-28 07:32:01 +00004792 @Override
4793 public void registerFeatureProvisioningChangedCallback(int subId,
4794 IFeatureProvisioningCallback callback) {
4795 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4796 mApp, subId, "registerFeatureProvisioningChangedCallback");
4797
4798 final long identity = Binder.clearCallingIdentity();
4799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4801 }
4802
joonhunshin91bc1952022-04-29 08:47:15 +00004803 try {
4804 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4805 if (controller == null) {
4806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4807 "Device does not support IMS");
4808 }
4809 controller.addFeatureProvisioningChangedCallback(subId, callback);
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004813 }
4814
4815 @Override
4816 public void unregisterFeatureProvisioningChangedCallback(int subId,
4817 IFeatureProvisioningCallback callback) {
4818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4819 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4820
4821 final long identity = Binder.clearCallingIdentity();
4822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4824 }
4825
joonhunshin91bc1952022-04-29 08:47:15 +00004826 try {
4827 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4828 if (controller == null) {
4829 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4830 return;
4831 }
4832 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004836 }
allenwtsu99c623b2020-01-03 18:24:23 +08004837
4838 private void checkModifyPhoneStatePermission(int subId, String message) {
4839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4840 message);
4841 }
4842
allenwtsu99c623b2020-01-03 18:24:23 +08004843 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004845 boolean isProvisioned) {
4846 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4847
4848 final long identity = Binder.clearCallingIdentity();
4849 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004850 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4851 if (controller == null) {
4852 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4853 return;
4854 }
4855 controller.setRcsProvisioningStatusForCapability(
4856 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
allenwtsu99c623b2020-01-03 18:24:23 +08004860 }
4861
4862
4863 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004864 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4866 mApp, subId, "getRcsProvisioningStatusForCapability");
4867
allenwtsu99c623b2020-01-03 18:24:23 +08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004870 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4871 if (controller == null) {
4872 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4873
4874 // device does not support IMS, this method will return true always.
4875 return true;
4876 }
4877 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004884 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4885 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004886 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004887
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004890 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4891 if (controller == null) {
4892 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4893 return;
4894 }
4895 controller.setImsProvisioningStatusForCapability(
4896 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
4902 @Override
4903 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4905 mApp, subId, "getProvisioningStatusForCapability");
4906
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004909 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4910 if (controller == null) {
4911 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912
joonhunshin91bc1952022-04-29 08:47:15 +00004913 // device does not support IMS, this method will return true always.
4914 return true;
4915 }
4916 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
4922 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004923 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4924 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4925 mApp, subId, "isProvisioningRequiredForCapability");
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004929 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4930 if (controller == null) {
4931 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4932
4933 // device does not support IMS, this method will return false
4934 return false;
4935 }
4936 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 }
4941
4942 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004943 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4944 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4945 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 final long identity = Binder.clearCallingIdentity();
4948 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004949 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4950 if (controller == null) {
4951 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4952
4953 // device does not support IMS, this method will return false
4954 return false;
4955 }
4956 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 }
4961
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4965 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4966 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004967 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4968 mApp, subId, "getImsProvisioningInt");
4969
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 int slotId = getSlotIndex(subId);
4974 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4975 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4976 + subId + "' for key:" + key);
4977 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4978 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004979
joonhunshin91bc1952022-04-29 08:47:15 +00004980 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4981 if (controller == null) {
4982 loge("getImsProvisioningInt: Device does not support IMS");
4983
4984 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4985 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4986 }
4987 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004988 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4989 return retVal;
4990 }
4991
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4995 + subId + "' for key:" + key);
4996 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
5002 @Override
5003 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5005 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5006 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5008 mApp, subId, "getImsProvisioningString");
5009
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005013 int slotId = getSlotIndex(subId);
5014 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5015 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5016 + subId + "' for key:" + key);
5017 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5018 }
calvinpanb5a34062021-02-08 19:59:36 +08005019 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005021 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5022 + subId + "' for key:" + key);
5023 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
5030 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005031 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5032 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5033 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5035 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005036
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005040 int slotId = getSlotIndex(subId);
5041 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5042 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5043 + subId + "' for key:" + key);
5044 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5045 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005046
joonhunshin91bc1952022-04-29 08:47:15 +00005047 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5048 if (controller == null) {
5049 loge("setImsProvisioningInt: Device does not support IMS");
5050
5051 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5053 }
5054 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005055 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5056 return retVal;
5057 }
5058
calvinpanb5a34062021-02-08 19:59:36 +08005059 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5060 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005061 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005062 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
5069 @Override
5070 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5072 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5073 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005079 int slotId = getSlotIndex(subId);
5080 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5081 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5082 + subId + "' for key:" + key);
5083 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5084 }
calvinpanb5a34062021-02-08 19:59:36 +08005085 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5086 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005088 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 /**
5096 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5097 * for the given slot ID or no ImsResolver instance has been created.
5098 * @param slotId The slot ID that the IMS service is created for.
5099 * @throws ImsException If there is no ImsService configured for this slot.
5100 */
5101 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5102 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5103 ImsFeature.FEATURE_MMTEL)) {
5104 throw new ImsException("This subscription does not support MMTEL over IMS",
5105 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5106 }
5107 }
5108
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005109 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 int slotId = SubscriptionManager.getSlotIndex(subId);
5111 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005112 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5113 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 }
5115 return slotId;
5116 }
5117
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005118 private int getSlotIndex(int subId) {
5119 int slotId = SubscriptionManager.getSlotIndex(subId);
5120 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5121 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5122 }
5123 return slotId;
5124 }
5125
Wink Saville36469e72014-06-11 15:17:00 -07005126 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005127 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005128 */
5129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5131 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005132 try {
5133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5134 } catch (SecurityException se) {
5135 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5136 throw new SecurityException("Package " + callingPackage + " does not belong to "
5137 + Binder.getCallingUid());
5138 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005139 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005140 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005141 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005142 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005143 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 mApp, subId, callingPackage, callingFeatureId,
5145 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 final Phone phone = getPhone(subId);
5152 if (phone != null) {
5153 return phone.getServiceState().getDataNetworkType();
5154 } else {
5155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5156 }
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 }
5161
5162 /**
5163 * Returns the data network type
5164 */
5165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005167 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5168 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
5171 /**
5172 * Returns the data network type for a subId
5173 */
5174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005175 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5176 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005177 String functionName = "getDataNetworkTypeForSubscriber";
5178 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5179 mApp, functionName)) {
5180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5181 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5182 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5183 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 }
5185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 final Phone phone = getPhone(subId);
5189 if (phone != null) {
5190 return phone.getServiceState().getDataNetworkType();
5191 } else {
5192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
5198
5199 /**
Wink Saville36469e72014-06-11 15:17:00 -07005200 * Returns the Voice network type for a subId
5201 */
5202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005203 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5204 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005205 String functionName = "getVoiceNetworkTypeForSubscriber";
5206 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5207 mApp, functionName)) {
5208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5209 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5210 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5211 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005212 }
5213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 final Phone phone = getPhone(subId);
5217 if (phone != null) {
5218 return phone.getServiceState().getVoiceNetworkType();
5219 } else {
5220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5221 }
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005225 }
5226
5227 /**
5228 * @return true if a ICC card is present
5229 */
5230 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005231 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005232 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5233 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005234 }
5235
5236 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005238 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 final Phone phone = PhoneFactory.getPhone(slotIndex);
5244 if (phone != null) {
5245 return phone.getIccCard().hasIccCard();
5246 } else {
5247 return false;
5248 }
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005252 }
5253
5254 /**
5255 * Return if the current radio is LTE on CDMA. This
5256 * is a tri-state return value as for a period of time
5257 * the mode may be unknown.
5258 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005259 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005260 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005261 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005264 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5265 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5266 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005267 }
5268
Sanket Padawe356d7632015-06-22 14:03:32 -07005269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005270 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5271 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005272 try {
5273 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5274 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005275 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5276 }
5277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 final Phone phone = getPhone(subId);
5281 if (phone == null) {
5282 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5283 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005284 return TelephonyProperties.lte_on_cdma_device()
5285 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005289 }
Wink Saville36469e72014-06-11 15:17:00 -07005290 }
5291
Wink Saville36469e72014-06-11 15:17:00 -07005292 /**
5293 * {@hide}
5294 * Returns Default subId, 0 in the case of single standby.
5295 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005296 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005297 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005298 }
5299
Shishir Agrawala9f32182016-04-12 12:00:16 -07005300 private int getSlotForDefaultSubscription() {
5301 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5302 }
5303
Wink Savilleb564aae2014-10-23 10:18:09 -07005304 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005305 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005306 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005307
Pengquan Menge92a50d2018-09-21 15:54:48 -07005308 private boolean isActiveSubscription(int subId) {
5309 return mSubscriptionController.isActiveSubId(subId);
5310 }
5311
Ihab Awadf2177b72013-11-25 13:33:23 -08005312 /**
5313 * @see android.telephony.TelephonyManager.WifiCallingChoices
5314 */
5315 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 final long identity = Binder.clearCallingIdentity();
5317 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5320 getWhenToMakeWifiCallsDefaultPreference());
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005324 }
5325
5326 /**
5327 * @see android.telephony.TelephonyManager.WifiCallingChoices
5328 */
5329 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005333 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005338 }
5339
Sailesh Nepald1e68152013-12-12 19:08:02 -08005340 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005341 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005342 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005343 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005344
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005345 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5346 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5347 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005348 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005349 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5350 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005351 }
5352 return PhoneFactory.getPhone(phoneId);
5353 }
5354
Shishir Agrawal566b7612013-10-28 14:41:00 -07005355 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005356 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005357 @NonNull IccLogicalChannelRequest request) {
5358 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5359 /*message=*/ "iccOpenLogicalChannel");
5360
5361 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5362 // Verify that the callingPackage in the request belongs to the calling UID
5363 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5364
5365 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005367
Rambo Wanga1782702021-11-10 20:15:19 -08005368 private Phone getPhoneFromValidIccLogicalChannelRequest(
5369 @NonNull IccLogicalChannelRequest request, String message) {
5370 Phone phone;
5371 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5373 mApp, request.subId, message);
5374 phone = getPhoneFromSubId(request.subId);
5375 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5376 enforceModifyPermission();
5377 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5378 } else {
5379 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005380 }
Rambo Wanga1782702021-11-10 20:15:19 -08005381 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005382 }
5383
5384 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005385 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005388 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5391 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5393 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 loge("The calling package is not allowed to access ISD-R.");
5395 throw new SecurityException(
5396 "The calling package is not allowed to access ISD-R.");
5397 }
Derek Tan740e1672017-06-27 14:56:27 -07005398 }
Derek Tan740e1672017-06-27 14:56:27 -07005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005401 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5402 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 return response;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005407 }
5408
5409 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005410 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5411 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5412 /*message=*/"iccCloseLogicalChannel");
5413
5414 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5415
5416 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005418
Rambo Wanga1782702021-11-10 20:15:19 -08005419 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5420 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005421 // before this feature is enabled, this API should only return false if
5422 // the operation fails instead of throwing runtime exception for
5423 // backward-compatibility.
5424 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5425 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005428 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005429 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 }
Chen Xue9d737e2022-01-01 23:41:31 -08005431 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005432 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005433 Boolean success = false;
5434 if (result instanceof RuntimeException) {
5435 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005436 if (shouldThrowExceptionOnFailure) {
5437 throw (RuntimeException) result;
5438 } else {
5439 return false;
5440 }
Chen Xue9d737e2022-01-01 23:41:31 -08005441 } else if (result instanceof Boolean) {
5442 success = (Boolean) result;
5443 } else {
5444 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5445 }
Rambo Wanga1782702021-11-10 20:15:19 -08005446 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 return success;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005451 }
5452
5453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005454 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005458 if (DBG) {
5459 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5460 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5461 + p3 + " data=" + data);
5462 }
5463 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5464 command, p1, p2, p3, data);
5465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005466
Jordan Liu4c733742019-02-28 12:03:40 -08005467 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005468 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5469 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005470 enforceModifyPermission();
5471 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5473 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5474 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005475 }
5476 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005477 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5478 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005479 }
5480
5481 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5482 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005485 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 return "";
5487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005490 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5491 null /* workSource */);
5492 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // Append the returned status code to the end of the response payload.
5495 String s = Integer.toHexString(
5496 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5497 if (response.payload != null) {
5498 s = IccUtils.bytesToHexString(response.payload) + s;
5499 }
5500 return s;
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005504 }
Jake Hambye994d462014-02-03 13:10:13 -08005505
Evan Charltonc66da362014-05-16 14:06:40 -07005506 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005507 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5508 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5510 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005512 if (DBG) {
5513 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5514 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5515 }
5516 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5517 cla, command, p1, p2, p3, data);
5518 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519
Jordan Liu4c733742019-02-28 12:03:40 -08005520 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005521 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5522 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005523 enforceModifyPermission();
5524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5525 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005526 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5527 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5528 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005529 }
5530
5531 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5533 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005534 }
5535
5536 // open APDU basic channel assuming the caller has sufficient permissions
5537 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5538 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5542 && TextUtils.equals(ISDR_AID, data)) {
5543 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005544 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5545 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 if (bestComponent == null
5547 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5548 loge("The calling package is not allowed to select ISD-R.");
5549 throw new SecurityException(
5550 "The calling package is not allowed to select ISD-R.");
5551 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005552 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005555 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5556 null /* workSource */);
5557 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 // Append the returned status code to the end of the response payload.
5560 String s = Integer.toHexString(
5561 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5562 if (response.payload != null) {
5563 s = IccUtils.bytesToHexString(response.payload) + s;
5564 }
5565 return s;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005568 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005569 }
5570
5571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5575 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (DBG) {
5580 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5581 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5582 }
5583
5584 IccIoResult response =
5585 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5586 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5587 subId);
5588
5589 if (DBG) {
5590 log("Exchange SIM_IO [R]" + response);
5591 }
5592
5593 byte[] result = null;
5594 int length = 2;
5595 if (response.payload != null) {
5596 length = 2 + response.payload.length;
5597 result = new byte[length];
5598 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5599 } else {
5600 result = new byte[length];
5601 }
5602
5603 result[length - 1] = (byte) response.sw2;
5604 result[length - 2] = (byte) response.sw1;
5605 return result;
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 }
5610
Nathan Haroldb3014052017-01-25 15:57:32 -08005611 /**
5612 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5613 * on a particular subscription
5614 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005615 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5616 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005618 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005619 return null;
5620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 if (appType != TelephonyManager.APPTYPE_USIM
5625 && appType != TelephonyManager.APPTYPE_SIM) {
5626 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5627 return null;
5628 }
5629 Object response = sendRequest(
5630 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5631 if (response instanceof String[]) {
5632 return (String[]) response;
5633 }
yincheng zhao2737e882019-09-06 17:06:54 -07005634 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005636 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005639 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005640 }
5641
yincheng zhao2737e882019-09-06 17:06:54 -07005642 /**
5643 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5644 * subscription.
5645 *
5646 * @param subId the id of the subscription.
5647 * @param appType the uicc app type, must be USIM or SIM.
5648 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5649 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005650 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005651 * @return number of fplmns that is successfully written to the SIM.
5652 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5654 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setForbiddenPlmns");
5657
yincheng zhao2737e882019-09-06 17:06:54 -07005658 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5659 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5660 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5661 }
5662 if (fplmns == null) {
5663 throw new IllegalArgumentException("Fplmn List provided is null");
5664 }
5665 for (String fplmn : fplmns) {
5666 if (!CellIdentity.isValidPlmn(fplmn)) {
5667 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5668 }
5669 }
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 Object response = sendRequest(
5673 CMD_SET_FORBIDDEN_PLMNS,
5674 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5675 subId);
5676 return (int) response;
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
5680 }
5681
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005682 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005683 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5690 if (response.payload == null) {
5691 return "";
5692 }
Evan Charltonc66da362014-05-16 14:06:40 -07005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 // Append the returned status code to the end of the response payload.
5695 String s = Integer.toHexString(
5696 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5697 s = IccUtils.bytesToHexString(response.payload) + s;
5698 return s;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Evan Charltonc66da362014-05-16 14:06:40 -07005702 }
5703
Jake Hambye994d462014-02-03 13:10:13 -08005704 /**
5705 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5706 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5707 *
5708 * @param itemID the ID of the item to read
5709 * @return the NV item as a String, or null on error.
5710 */
5711 @Override
5712 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005720 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5722 return value;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Jake Hambye994d462014-02-03 13:10:13 -08005726 }
5727
5728 /**
5729 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5730 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5731 *
5732 * @param itemID the ID of the item to read
5733 * @param itemValue the value to write, as a String
5734 * @return true on success; false on any failure
5735 */
5736 @Override
5737 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5745 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005746 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5748 return success;
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Jake Hambye994d462014-02-03 13:10:13 -08005752 }
5753
5754 /**
5755 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5756 * Used for device configuration by some CDMA operators.
5757 *
5758 * @param preferredRoamingList byte array containing the new PRL
5759 * @return true on success; false on any failure
5760 */
5761 @Override
5762 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5764 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5769 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5770 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5771 return success;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Jake Hambye994d462014-02-03 13:10:13 -08005775 }
5776
5777 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005778 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005779 * Used for device configuration by some CDMA operators.
5780 *
chen xu6dac5ab2018-10-26 17:39:23 -07005781 * @param slotIndex - device slot.
5782 *
Jake Hambye994d462014-02-03 13:10:13 -08005783 * @return true on success; false on any failure
5784 */
5785 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005786 public boolean resetModemConfig(int slotIndex) {
5787 Phone phone = PhoneFactory.getPhone(slotIndex);
5788 if (phone != null) {
5789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5790 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
chen xu6dac5ab2018-10-26 17:39:23 -07005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5795 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5796 return success;
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 }
chen xu6dac5ab2018-10-26 17:39:23 -07005801 return false;
5802 }
5803
5804 /**
5805 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5806 *
5807 * @param slotIndex - device slot.
5808 *
5809 * @return true on success; false on any failure
5810 */
5811 @Override
5812 public boolean rebootModem(int slotIndex) {
5813 Phone phone = PhoneFactory.getPhone(slotIndex);
5814 if (phone != null) {
5815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5816 mApp, phone.getSubId(), "rebootModem");
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5821 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5822 return success;
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005828 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005829
Brad Ebinger51f743a2017-01-23 13:50:20 -08005830 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005831 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5832 * {@link #disableIms(int)}.
5833 * @param slotIndex device slot.
5834 */
5835 public void resetIms(int slotIndex) {
5836 enforceModifyPermission();
5837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 if (mImsResolver == null) {
5841 // may happen if the does not support IMS.
5842 return;
5843 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005844 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
5848 }
5849
5850 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005851 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5852 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005853 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 // may happen if the device does not support IMS.
5861 return;
5862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005867 }
5868
5869 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5871 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005872 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005873 public void disableIms(int slotId) {
5874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005879 // may happen if the device does not support IMS.
5880 return;
5881 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 }
5887
5888 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005889 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5890 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005892 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005893 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005899 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5900 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005901 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005902 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005906 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005907 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005908 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5909 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005910 @Override
5911 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005912 enforceModifyPermission();
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005917 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005924 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005925 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005926 */
5927 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005933 // may happen if the device does not support IMS.
5934 return null;
5935 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005940 }
5941
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005942 /**
5943 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005944 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005945 */
5946 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return null;
5954 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005959 }
5960
Brad Ebinger884c07b2018-02-15 16:17:40 -08005961 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005962 * Sets the ImsService Package Name that Telephony will bind to.
5963 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005964 * @param slotIndex the slot ID that the ImsService should bind for.
5965 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005967 * @param featureTypes An integer array of feature types associated with a packageName.
5968 * @param packageName The name of the package that the current configuration will be replaced
5969 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005971 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5973 int[] featureTypes, String packageName) {
5974 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5977 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005978 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 final long identity = Binder.clearCallingIdentity();
5981 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005983 // may happen if the device does not support IMS.
5984 return false;
5985 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 Map<Integer, String> featureConfig = new HashMap<>();
5987 for (int featureType : featureTypes) {
5988 featureConfig.put(featureType, packageName);
5989 }
5990 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5991 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005995 }
5996
5997 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005998 * Clears any carrier ImsService overrides for the slot index specified that were previously
5999 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6000 *
6001 * This should only be used for testing.
6002 *
6003 * @param slotIndex the slot ID that the ImsService should bind for.
6004 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6005 */
6006 @Override
6007 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6008 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6010 "clearCarrierImsServiceOverride");
6011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6012 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6013 "clearCarrierImsServiceOverride");
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 if (mImsResolver == null) {
6018 // may happen if the device does not support IMS.
6019 return false;
6020 }
6021 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006028 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006029 *
6030 * @param slotId The slot that the ImsService is associated with.
6031 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6032 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006033 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006034 * @return the package name of the ImsService configuration.
6035 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6037 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006038 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006040 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6042 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006046 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006047 // may happen if the device does not support IMS.
6048 return "";
6049 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006050 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6052 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006056 }
6057
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006058 /**
6059 * Get the MmTelFeature state associated with the requested subscription id.
6060 * @param subId The subscription that the MmTelFeature is associated with.
6061 * @param callback A callback with an integer containing the
6062 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6063 */
6064 @Override
6065 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6066 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6069 "IMS not available on device.");
6070 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006071 final long token = Binder.clearCallingIdentity();
6072 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006073 int slotId = getSlotIndex(subId);
6074 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6075 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6076 + subId + "'");
6077 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6078 }
6079 verifyImsMmTelConfiguredOrThrow(slotId);
6080 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6081 try {
6082 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6083 } catch (RemoteException e) {
6084 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6085 + "Ignore");
6086 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006087 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006088 } catch (ImsException e) {
6089 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006090 } finally {
6091 Binder.restoreCallingIdentity(token);
6092 }
6093 }
6094
Daniel Brightbb5840b2021-01-12 15:48:18 -08006095 /**
6096 * Sets the ims registration state on all valid {@link Phone}s.
6097 */
6098 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006103 // NOTE: Before S, this method only set the default phone.
6104 for (final Phone phone : PhoneFactory.getPhones()) {
6105 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6106 phone.setImsRegistrationState(registered);
6107 }
6108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
Wink Saville36469e72014-06-11 15:17:00 -07006112 }
6113
6114 /**
Stuart Scott54788802015-03-30 13:18:01 -07006115 * Set the network selection mode to automatic.
6116 *
6117 */
6118 @Override
6119 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6121 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
shilufc958392020-01-20 11:36:01 -08006125 if (!isActiveSubscription(subId)) {
6126 return;
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006129 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6130 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Stuart Scott54788802015-03-30 13:18:01 -07006134 }
6135
Jack Yud10cdd42020-09-28 20:28:01 -07006136 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006137 * Ask the radio to connect to the input network and change selection mode to manual.
6138 *
6139 * @param subId the id of the subscription.
6140 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6141 * the operator to attach to.
6142 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6143 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6144 * normal network selection next time.
6145 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006146 */
6147 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006148 public boolean setNetworkSelectionModeManual(
6149 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6151 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006152
6153 if (!isActiveSubscription(subId)) {
6154 return false;
6155 }
6156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006159 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006161 if (DBG) {
6162 log("setNetworkSelectionModeManual: subId: " + subId
6163 + " operator: " + operatorInfo);
6164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
6168 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006169 }
shilu84f6e8b2019-12-19 13:58:01 -08006170 /**
6171 * Get the manual network selection
6172 *
6173 * @param subId the id of the subscription.
6174 *
6175 * @return the previously saved user selected PLMN
6176 */
6177 @Override
6178 public String getManualNetworkSelectionPlmn(int subId) {
6179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006180 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006181 mApp, subId, "getManualNetworkSelectionPlmn");
6182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006186 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006187 }
6188
6189 final Phone phone = getPhone(subId);
6190 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006191 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006192 }
6193 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6194 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6195 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006200
6201 /**
6202 * Scans for available networks.
6203 */
6204 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006205 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6208 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006209 LocationAccessPolicy.LocationPermissionResult locationResult =
6210 LocationAccessPolicy.checkLocationPermission(mApp,
6211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6212 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006214 .setCallingPid(Binder.getCallingPid())
6215 .setCallingUid(Binder.getCallingUid())
6216 .setMethod("getCellNetworkScanResults")
6217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6219 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006220 .build());
6221 switch (locationResult) {
6222 case DENIED_HARD:
6223 throw new SecurityException("Not allowed to access scan results -- location");
6224 case DENIED_SOFT:
6225 return null;
6226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227
Pengquan Menga1bb6272018-09-06 09:59:22 -07006228 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 try {
6230 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006231 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006236 }
6237
6238 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006239 * Get the call forwarding info, given the call forwarding reason.
6240 */
6241 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006242 public void getCallForwarding(int subId, int callForwardingReason,
6243 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006244 enforceReadPrivilegedPermission("getCallForwarding");
6245 long identity = Binder.clearCallingIdentity();
6246 try {
6247 if (DBG) {
6248 log("getCallForwarding: subId " + subId
6249 + " callForwardingReason" + callForwardingReason);
6250 }
Hall Liu27d24262020-09-18 19:04:59 -07006251
6252 Phone phone = getPhone(subId);
6253 if (phone == null) {
6254 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006255 callback.onError(
6256 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006257 } catch (RemoteException e) {
6258 // ignore
6259 }
6260 return;
6261 }
6262
6263 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6264 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6265 @Override
6266 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6267 try {
6268 callback.onCallForwardingInfoAvailable(info);
6269 } catch (RemoteException e) {
6270 // ignore
6271 }
6272 }
6273
6274 @Override
6275 public void onError(int error) {
6276 try {
6277 callback.onError(error);
6278 } catch (RemoteException e) {
6279 // ignore
6280 }
6281 }
6282 });
6283 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
6287 }
6288
6289 /**
6290 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6291 * reason, the number to forward, and the timeout before the forwarding is attempted.
6292 */
6293 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006294 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6295 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006296 enforceModifyPermission();
6297 long identity = Binder.clearCallingIdentity();
6298 try {
6299 if (DBG) {
6300 log("setCallForwarding: subId " + subId
6301 + " callForwardingInfo" + callForwardingInfo);
6302 }
Hall Liu27d24262020-09-18 19:04:59 -07006303
6304 Phone phone = getPhone(subId);
6305 if (phone == null) {
6306 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006307 callback.accept(
6308 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006309 } catch (RemoteException e) {
6310 // ignore
6311 }
6312 return;
6313 }
6314
6315 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6316 FunctionalUtils.ignoreRemoteException(callback::accept));
6317
6318 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
6322 }
6323
6324 /**
Hall Liu27d24262020-09-18 19:04:59 -07006325 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006326 */
6327 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006328 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006329 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006330 long identity = Binder.clearCallingIdentity();
6331 try {
Hall Liu27d24262020-09-18 19:04:59 -07006332 Phone phone = getPhone(subId);
6333 if (phone == null) {
6334 try {
6335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6336 } catch (RemoteException e) {
6337 // ignore
6338 }
6339 return;
6340 }
SongFerngWang0e767992021-03-31 22:08:45 +08006341 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6342 PersistableBundle c = configManager.getConfigForSubId(subId);
6343 boolean requireUssd = c.getBoolean(
6344 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006345
Shuo Qian4a594052020-01-23 11:59:30 -08006346 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006347 if (requireUssd) {
6348 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6349 getSubscriptionCarrierId(subId));
6350 String newUssdCommand = "";
6351 try {
6352 newUssdCommand = carrierXmlParser.getFeature(
6353 CarrierXmlParser.FEATURE_CALL_WAITING)
6354 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6355 } catch (NullPointerException e) {
6356 loge("Failed to generate USSD number" + e);
6357 }
6358 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6359 mMainThreadHandler, callback, carrierXmlParser,
6360 CarrierXmlParser.SsEntry.SSAction.QUERY);
6361 final String ussdCommand = newUssdCommand;
6362 Executors.newSingleThreadExecutor().execute(() -> {
6363 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6364 });
6365 } else {
6366 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6367 callback::accept);
6368 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6369 }
Shuo Qian4a594052020-01-23 11:59:30 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
6375 /**
Hall Liu27d24262020-09-18 19:04:59 -07006376 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006377 */
6378 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006379 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006380 enforceModifyPermission();
6381 long identity = Binder.clearCallingIdentity();
6382 try {
Hall Liu27d24262020-09-18 19:04:59 -07006383 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6384
6385 Phone phone = getPhone(subId);
6386 if (phone == null) {
6387 try {
6388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6389 } catch (RemoteException e) {
6390 // ignore
6391 }
6392 return;
6393 }
6394
SongFerngWang0e767992021-03-31 22:08:45 +08006395 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6396 PersistableBundle c = configManager.getConfigForSubId(subId);
6397 boolean requireUssd = c.getBoolean(
6398 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006399
SongFerngWang0e767992021-03-31 22:08:45 +08006400 if (DBG) log("getCallWaitingStatus: subId " + subId);
6401 if (requireUssd) {
6402 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6403 getSubscriptionCarrierId(subId));
6404 CarrierXmlParser.SsEntry.SSAction ssAction =
6405 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6406 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6407 String newUssdCommand = "";
6408 try {
6409 newUssdCommand = carrierXmlParser.getFeature(
6410 CarrierXmlParser.FEATURE_CALL_WAITING)
6411 .makeCommand(ssAction, null);
6412 } catch (NullPointerException e) {
6413 loge("Failed to generate USSD number" + e);
6414 }
6415 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6416 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6417 final String ussdCommand = newUssdCommand;
6418 Executors.newSingleThreadExecutor().execute(() -> {
6419 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6420 });
6421 } else {
6422 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6423 FunctionalUtils.ignoreRemoteException(callback::accept));
6424
6425 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6426 }
Shuo Qian4a594052020-01-23 11:59:30 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 /**
yinxub1bed742017-04-17 11:45:04 -07006433 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006434 *
yinxub1bed742017-04-17 11:45:04 -07006435 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006436 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6437 * location related information which will be sent if the caller already possess
6438 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006439 * @param request contains the radio access networks with bands/channels to scan
6440 * @param messenger callback messenger for scan results or errors
6441 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006442 * @return the id of the requested scan which can be used to stop the scan.
6443 */
6444 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006445 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6446 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006447 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006450 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006451 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6452 if (!renounceFineLocationAccess) {
6453 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6454 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6455 .setCallingPackage(callingPackage)
6456 .setCallingFeatureId(callingFeatureId)
6457 .setCallingPid(Binder.getCallingPid())
6458 .setCallingUid(Binder.getCallingUid())
6459 .setMethod("requestNetworkScan")
6460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6462 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6463 .build());
6464 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006465 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006466 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6467 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006468 if (e != null) {
6469 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6470 throw e;
6471 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006472 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006473 return TelephonyScanManager.INVALID_SCAN_ID;
6474 }
6475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 }
Hall Liu912dfd32019-04-25 14:02:26 -07006477 int callingUid = Binder.getCallingUid();
6478 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006482 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006483 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
yinxu504e1392017-04-12 16:03:22 -07006487 }
6488
Hall Liub2ac8ef2019-02-28 15:56:23 -08006489 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006490 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006491 boolean hasCarrierPriv;
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6495 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Hall Liu558027f2019-05-15 19:14:05 -07006499 boolean hasNetworkScanPermission =
6500 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6501 == PERMISSION_GRANTED;
6502
6503 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6504 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6505 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006506 }
6507
6508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6511 return new SecurityException("Specific channels must not be"
6512 + " scanned without location access.");
6513 }
6514 }
6515 }
6516
Hall Liub2ac8ef2019-02-28 15:56:23 -08006517 return null;
6518 }
6519
yinxu504e1392017-04-12 16:03:22 -07006520 /**
6521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006522 *
6523 * @param subId id of the subscription
6524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006525 */
6526 @Override
6527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6529 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
Hall Liu912dfd32019-04-25 14:02:26 -07006531 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 final long identity = Binder.clearCallingIdentity();
6533 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
yinxu504e1392017-04-12 16:03:22 -07006538 }
6539
6540 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006542 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006544 */
6545 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 if (DBG) log("getAllowedNetworkTypesBitmask");
6554 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6555 int networkTypesBitmask = (result != null ? result[0] : -1);
6556 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6557 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006561 }
6562
6563 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006564 * Get the allowed network types for certain reason.
6565 *
6566 * @param subId the id of the subscription.
6567 * @param reason the reason the allowed network type change is taking place
6568 * @return the allowed network types.
6569 */
6570 @Override
6571 public long getAllowedNetworkTypesForReason(int subId,
6572 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006574 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 }
6582
6583 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006584 * Enable/Disable E-UTRA-NR Dual Connectivity
6585 * @param subId subscription id of the sim card
6586 * @param nrDualConnectivityState expected NR dual connectivity state
6587 * This can be passed following states
6588 * <ol>
6589 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6590 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6591 * <li>Disable NR dual connectivity and force secondary cell to be released
6592 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6593 * </ol>
6594 * @return operation result.
6595 */
6596 @Override
6597 public int setNrDualConnectivityState(int subId,
6598 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6600 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006601 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006602 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6603 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6604 }
6605
Sooraj Sasindran37444802020-08-11 10:40:43 -07006606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6610 nrDualConnectivityState, subId,
6611 workSource);
6612 if (DBG) log("enableNRDualConnectivity result: " + result);
6613 return result;
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 /**
6620 * Is E-UTRA-NR Dual Connectivity enabled
6621 * @return true if dual connectivity is enabled else false
6622 */
6623 @Override
6624 public boolean isNrDualConnectivityEnabled(int subId) {
6625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006627 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006628 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006629 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6630 return false;
6631 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6636 null, subId, workSource);
6637 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6638 return isEnabled;
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
6643
6644 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006645 * Set the allowed network types of the device and
6646 * provide the reason triggering the allowed network change.
6647 *
6648 * @param subId the id of the subscription.
6649 * @param reason the reason the allowed network type change is taking place
6650 * @param allowedNetworkTypes the allowed network types.
6651 * @return true on success; false on any failure.
6652 */
6653 @Override
6654 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006655 @TelephonyManager.AllowedNetworkTypesReason int reason,
6656 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006660 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6661 return false;
6662 }
6663 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6664 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006665 return false;
6666 }
6667
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006668 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6669 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6670
6671
6672 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6673 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6674 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006675 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006676
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006677 final long identity = Binder.clearCallingIdentity();
6678 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006679 Boolean success = (Boolean) sendRequest(
6680 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6681 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6682
6683 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6684 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
6690 /**
Miaoa84611c2019-03-15 09:21:10 +08006691 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006692 *
Miaoa84611c2019-03-15 09:21:10 +08006693 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006694 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006695 * @hide
6696 */
6697 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006698 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 try {
Miaoa84611c2019-03-15 09:21:10 +08006703 if (phone != null) {
6704 return phone.hasMatchedTetherApnSetting();
6705 } else {
6706 return false;
6707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006710 }
Junda Liu475951f2014-11-07 16:45:03 -08006711 }
6712
6713 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006714 * Get the user enabled state of Mobile Data.
6715 *
6716 * TODO: remove and use isUserDataEnabled.
6717 * This can't be removed now because some vendor codes
6718 * calls through ITelephony directly while they should
6719 * use TelephonyManager.
6720 *
6721 * @return true on enabled
6722 */
6723 @Override
6724 public boolean getDataEnabled(int subId) {
6725 return isUserDataEnabled(subId);
6726 }
6727
6728 /**
6729 * Get whether mobile data is enabled per user setting.
6730 *
6731 * There are other factors deciding whether mobile data is actually enabled, but they are
6732 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006733 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6735 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006736 *
6737 * @return {@code true} if data is enabled else {@code false}
6738 */
6739 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006740 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006741 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006742 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006743 try {
6744 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6745 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006746 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6748 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006749 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006751 mApp, subId, functionName);
6752
Robert Greenwalt646120a2014-05-23 11:54:03 -07006753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 int phoneId = mSubscriptionController.getPhoneId(subId);
6758 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6759 Phone phone = PhoneFactory.getPhone(phoneId);
6760 if (phone != null) {
6761 boolean retVal = phone.isUserDataEnabled();
6762 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6763 return retVal;
6764 } else {
6765 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6766 return false;
6767 }
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006770 }
6771 }
6772
6773 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006774 * Checks if the device is capable of mobile data by considering whether whether the
6775 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6776 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006777 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006778 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006779 */
6780 @Override
6781 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006782 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006783 try {
6784 try {
6785 mApp.enforceCallingOrSelfPermission(
6786 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006788 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006789 try {
6790 mApp.enforceCallingOrSelfPermission(
6791 android.Manifest.permission.READ_PHONE_STATE,
6792 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006793 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 mApp.enforceCallingOrSelfPermission(
6795 permission.READ_BASIC_PHONE_STATE, functionName);
6796 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006797 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006798 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 Phone phone = PhoneFactory.getPhone(phoneId);
6806 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006807 boolean retVal;
Sarah Chin360de232022-10-28 17:08:07 -07006808 if (phone.getDataSettingsManager() == null) {
6809 retVal = false;
6810 } else {
6811 retVal = phone.getDataSettingsManager().isDataEnabled();
6812 }
Jack Yu4ad64e52021-12-03 14:23:53 -08006813 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 return retVal;
6815 } else {
6816 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6817 return false;
6818 }
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006821 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006822 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006823
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 /**
6825 * Check if data is enabled for a specific reason
6826 * @param subId Subscription index
6827 * @param reason the reason the data enable change is taking place
6828 * @return {@code true} if the overall data is enabled; {@code false} if not.
6829 */
6830 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006831 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006832 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006833 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006834 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006835 try {
6836 mApp.enforceCallingOrSelfPermission(
6837 android.Manifest.permission.ACCESS_NETWORK_STATE,
6838 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006839 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006840 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6841 functionName);
6842 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006843 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006844 try {
6845 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006846 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006847 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006849 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006850 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006851 }
6852
6853
6854 final long identity = Binder.clearCallingIdentity();
6855 try {
6856 int phoneId = mSubscriptionController.getPhoneId(subId);
6857 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006858 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006859 + " reason=" + reason);
6860 }
6861 Phone phone = PhoneFactory.getPhone(phoneId);
6862 if (phone != null) {
6863 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006864 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006866 return retVal;
6867 } else {
6868 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006869 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006870 + subId + " retVal=false");
6871 }
6872 return false;
6873 }
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006879 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006880 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006881 // No permission needed; this only lets the caller inspect their own status.
6882 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006883 }
Junda Liu29340342014-07-10 15:23:27 -07006884
6885 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006886 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006887 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006888 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6889 }
6890
6891 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6892 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006894 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6896 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6898 if (cpt == null) {
6899 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6901 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006902 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006903 }
6904
6905 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006906 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006908 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006910 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006911 Phone phone = getPhone(subId);
6912 if (phone == null) {
6913 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6915 }
6916 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6917 if (cpt == null) {
6918 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6920 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006922 }
6923
6924 @Override
6925 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006926 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006927 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6928 }
6929
6930 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006931 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006934 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006935 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6936 Phone phone = PhoneFactory.getPhone(phoneId);
6937 if (phone == null) {
6938 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6941 if (cpt == null) {
6942 continue;
6943 }
6944 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006945 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6946 break;
6947 }
6948 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006949 return result;
Junda Liu29340342014-07-10 15:23:27 -07006950 }
Derek Tan89e89d42014-07-08 17:00:10 -07006951
6952 @Override
Junda Liue64de782015-04-16 17:19:16 -07006953 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006954 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone == null) {
6957 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006958 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006959 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6960 if (cpt == null) {
6961 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006962 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006963 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006964 }
6965
Amith Yamasani6e118872016-02-19 12:53:51 -08006966 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006967 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006968 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006969 Phone phone = PhoneFactory.getPhone(phoneId);
6970 if (phone == null) {
6971 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006972 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6974 if (cpt == null) {
6975 return Collections.emptyList();
6976 }
6977 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006978 }
6979
chen xuf7e9fe82019-05-09 19:31:02 -07006980 @Override
6981 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006982 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006983 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006984 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006985 try {
6986 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6987 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006991 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006992 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006993 }
6994
Rambo Wang6812ffb2022-03-15 16:54:17 -07006995 @Override
6996 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6997 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6998
6999 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7000 if (phone == null) {
7001 return null;
7002 }
7003 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7004 if (cpt == null) {
7005 return null;
7006 }
7007 return cpt.getCarrierServicePackageName();
7008 }
7009
Wink Savilleb564aae2014-10-23 10:18:09 -07007010 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007011 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007012 UiccPort port = phone == null ? null : phone.getUiccPort();
7013 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007014 return null;
7015 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007016 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007017 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007018 return null;
7019 }
7020 return iccId;
7021 }
7022
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007023 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007024 public void setCallComposerStatus(int subId, int status) {
7025 enforceModifyPermission();
7026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 Phone phone = getPhone(subId);
7030 if (phone != null) {
7031 Phone defaultPhone = phone.getImsPhone();
7032 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7033 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7034 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7036 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007037 }
7038 }
Shuo Qian284ae752020-12-22 19:10:14 -08007039 } catch (ImsException e) {
7040 throw new ServiceSpecificException(e.getCode());
7041 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
7047 public int getCallComposerStatus(int subId) {
7048 enforceReadPrivilegedPermission("getCallComposerStatus");
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 Phone phone = getPhone(subId);
7053 if (phone != null) {
7054 Phone defaultPhone = phone.getImsPhone();
7055 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7056 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7057 return imsPhone.getCallComposerStatus();
7058 }
7059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
7063 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7064 }
7065
7066 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007067 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7068 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007069 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007070 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 final String iccId = getIccId(subId);
7075 final Phone phone = getPhone(subId);
7076 if (phone == null) {
7077 return false;
7078 }
7079 final String subscriberId = phone.getSubscriberId();
7080
7081 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007082 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 + subscriberId + " to " + number);
7084 }
7085
7086 if (TextUtils.isEmpty(iccId)) {
7087 return false;
7088 }
7089
7090 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7091
7092 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7093 if (alphaTag == null) {
7094 editor.remove(alphaTagPrefKey);
7095 } else {
7096 editor.putString(alphaTagPrefKey, alphaTag);
7097 }
7098
7099 // Record both the line number and IMSI for this ICCID, since we need to
7100 // track all merged IMSIs based on line number
7101 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7102 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7103 if (number == null) {
7104 editor.remove(numberPrefKey);
7105 editor.remove(subscriberPrefKey);
7106 } else {
7107 editor.putString(numberPrefKey, number);
7108 editor.putString(subscriberPrefKey, subscriberId);
7109 }
7110
7111 editor.commit();
7112 return true;
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007115 }
Derek Tan7226c842014-07-02 17:42:23 -07007116 }
7117
7118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 public String getLine1NumberForDisplay(int subId, String callingPackage,
7120 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007121 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007123 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007124 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007125 return null;
7126 }
Derek Tan97ebb422014-09-05 16:55:38 -07007127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 String iccId = getIccId(subId);
7131 if (iccId != null) {
7132 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7133 if (DBG_MERGE) {
7134 log("getLine1NumberForDisplay returning "
7135 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7136 }
7137 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7140 return null;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
7145
7146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7148 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007150 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007151 return null;
7152 }
Derek Tan97ebb422014-09-05 16:55:38 -07007153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 String iccId = getIccId(subId);
7157 if (iccId != null) {
7158 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7159 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7160 }
7161 return null;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
Derek Tan7226c842014-07-02 17:42:23 -07007165 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007166
7167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007168 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7169 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007170 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7171 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007173 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007175 return null;
7176 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007177
Jordan Liub49b04b2019-05-06 14:45:15 -07007178 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7179 // the process, where TelephonyManager was instantiated.
7180 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 final TelephonyManager tele = TelephonyManager.from(context);
7185 final SubscriptionManager sub = SubscriptionManager.from(context);
7186
7187 // Figure out what subscribers are currently active
7188 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189
Jordan Liub49b04b2019-05-06 14:45:15 -07007190 // Only consider subs which match the current subId
7191 // This logic can be simplified. See b/131189269 for progress.
7192 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 activeSubscriberIds.add(tele.getSubscriberId(subId));
7194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
7196 // First pass, find a number override for an active subscriber
7197 String mergeNumber = null;
7198 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7199 for (String key : prefs.keySet()) {
7200 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7201 final String subscriberId = (String) prefs.get(key);
7202 if (activeSubscriberIds.contains(subscriberId)) {
7203 final String iccId = key.substring(
7204 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7205 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7206 mergeNumber = (String) prefs.get(numberKey);
7207 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007208 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 + " for active subscriber " + subscriberId);
7210 }
7211 if (!TextUtils.isEmpty(mergeNumber)) {
7212 break;
7213 }
7214 }
7215 }
7216 }
7217
7218 // Shortcut when no active merged subscribers
7219 if (TextUtils.isEmpty(mergeNumber)) {
7220 return null;
7221 }
7222
7223 // Second pass, find all subscribers under that line override
7224 final ArraySet<String> result = new ArraySet<>();
7225 for (String key : prefs.keySet()) {
7226 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7227 final String number = (String) prefs.get(key);
7228 if (mergeNumber.equals(number)) {
7229 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7230 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7231 final String subscriberId = (String) prefs.get(subscriberKey);
7232 if (!TextUtils.isEmpty(subscriberId)) {
7233 result.add(subscriberId);
7234 }
7235 }
7236 }
7237 }
7238
7239 final String[] resultArray = result.toArray(new String[result.size()]);
7240 Arrays.sort(resultArray);
7241 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007242 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7244 }
7245 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007249 }
7250
7251 @Override
zoey chen38003472019-12-13 17:16:31 +08007252 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7253 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 final TelephonyManager telephonyManager = mApp.getSystemService(
7258 TelephonyManager.class);
7259 String subscriberId = telephonyManager.getSubscriberId(subId);
7260 if (subscriberId == null) {
7261 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007262 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007263 + subId);
7264 }
7265 return null;
7266 }
7267
7268 final SubscriptionInfo info = SubscriptionController.getInstance()
7269 .getSubscriptionInfo(subId);
7270 final ParcelUuid groupUuid = info.getGroupUuid();
7271 // If it doesn't belong to any group, return just subscriberId of itself.
7272 if (groupUuid == null) {
7273 return new String[]{subscriberId};
7274 }
7275
7276 // Get all subscriberIds from the group.
7277 final List<String> mergedSubscriberIds = new ArrayList<>();
7278 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007279 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007280 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007281 for (SubscriptionInfo subInfo : groupInfos) {
7282 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7283 if (subscriberId != null) {
7284 mergedSubscriberIds.add(subscriberId);
7285 }
7286 }
7287
7288 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291
7292 }
7293 }
7294
7295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007296 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007297 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007298 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299
7300 final long identity = Binder.clearCallingIdentity();
7301 try {
7302 final Phone phone = getPhone(subId);
7303 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007307 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007308
7309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007310 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007311 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7312 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007313 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7314 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 final Phone phone = getPhone(subId);
7319 if (phone == null) {
7320 return false;
7321 }
7322 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7323 cdmaNonRoamingList);
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007326 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007327 }
7328
7329 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007330 @Deprecated
7331 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7332 enforceModifyPermission();
7333
7334 int returnValue = 0;
7335 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007336 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007337 if(result.exception == null) {
7338 if (result.result != null) {
7339 byte[] responseData = (byte[])(result.result);
7340 if(responseData.length > oemResp.length) {
7341 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7342 responseData.length + "bytes. Buffer Size is " +
7343 oemResp.length + "bytes.");
7344 }
7345 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7346 returnValue = responseData.length;
7347 }
7348 } else {
7349 CommandException ex = (CommandException) result.exception;
7350 returnValue = ex.getCommandError().ordinal();
7351 if(returnValue > 0) returnValue *= -1;
7352 }
7353 } catch (RuntimeException e) {
7354 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7355 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7356 if(returnValue > 0) returnValue *= -1;
7357 }
7358
7359 return returnValue;
7360 }
7361
7362 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007363 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007365 try {
7366 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007367 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007368 mApp, phone.getSubId(), "getRadioAccessFamily");
7369 } catch (SecurityException e) {
7370 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7371 throw e;
7372 }
chen xub97461a2018-10-26 14:17:57 -07007373 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007374 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007375 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
7378 try {
chen xub97461a2018-10-26 14:17:57 -07007379 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007380 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007381 mApp, phone.getSubId(), "getRadioAccessFamily");
7382 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
chen xub97461a2018-10-26 14:17:57 -07007386 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388
7389 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007390 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007391 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007392 try {
7393 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7394 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007395 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007396 }
7397 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007398 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007399 }
7400 RoleManager rm = mApp.getSystemService(RoleManager.class);
7401 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7402 if (!dialerRoleHolders.contains(callingPackage)) {
7403 throw new SecurityException("App must be the dialer role holder to"
7404 + " upload a call composer pic");
7405 }
7406
7407 Executors.newSingleThreadExecutor().execute(() -> {
7408 ByteArrayOutputStream output = new ByteArrayOutputStream(
7409 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7410 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7411 boolean readUntilEnd = false;
7412 int totalBytesRead = 0;
7413 byte[] buffer = new byte[16 * 1024];
7414 while (true) {
7415 int numRead;
7416 try {
7417 numRead = input.read(buffer);
7418 } catch (IOException e) {
7419 try {
7420 fd.checkError();
7421 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7422 null);
7423 } catch (IOException e1) {
7424 // This means that the other side closed explicitly with an error. If this
7425 // happens, log and ignore.
7426 loge("Remote end of call composer picture pipe closed: " + e1);
7427 }
7428 break;
7429 }
7430 if (numRead == -1) {
7431 readUntilEnd = true;
7432 break;
7433 }
7434 totalBytesRead += numRead;
7435 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7436 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7437 try {
7438 input.close();
7439 } catch (IOException e) {
7440 // ignore
7441 }
7442 break;
7443 }
7444 output.write(buffer, 0, numRead);
7445 }
7446 // Generally, the remote end will close the file descriptors. The only case where we
7447 // close is above, where the picture size is too big.
7448
7449 try {
7450 fd.checkError();
7451 } catch (IOException e) {
7452 loge("Remote end for call composer closed with an error: " + e);
7453 return;
7454 }
7455
Hall Liuaa4211e2021-01-20 15:43:39 -08007456 if (!readUntilEnd) {
7457 loge("Did not finish reading entire image; aborting");
7458 return;
7459 }
Hall Liu82694d52020-12-11 18:22:04 -08007460
Hall Liuaa4211e2021-01-20 15:43:39 -08007461 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7462 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7463 new CallComposerPictureTransfer.Factory() {},
7464 imageData,
7465 (result) -> {
7466 if (result.first != null) {
7467 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7468 Bundle outputResult = new Bundle();
7469 outputResult.putParcelable(
7470 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7471 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7472 outputResult);
7473 } else {
7474 callback.send(result.second, null);
7475 }
7476 }
7477 );
Hall Liu82694d52020-12-11 18:22:04 -08007478 });
7479 }
7480
7481 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007482 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 ImsManager.getInstance(defaultPhone.getContext(),
7489 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007493 }
7494
7495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7499 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007500 return false;
7501 }
Svet Ganovb320e182015-04-16 12:30:10 -07007502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 // Check the user preference and the system-level IMS setting. Even if the user has
7506 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7507 // In the long run, we may instead need to check if there exists a connection service
7508 // which can support video calling.
7509 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 return imsManager.isVtEnabledByPlatform()
7512 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7513 && imsManager.isVtEnabledByUser();
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007517 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007518
Andrew Leea1239f22015-03-02 17:44:07 -08007519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007520 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7521 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 mApp, subId, callingPackage, callingFeatureId,
7524 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 return false;
7526 }
7527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 CarrierConfigManager configManager =
7531 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
Andrew Leea1239f22015-03-02 17:44:07 -08007537 }
7538
7539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007542 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return false;
7544 }
7545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 CarrierConfigManager configManager =
7549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007550 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Andrew Leea1239f22015-03-02 17:44:07 -08007555 }
7556
Andrew Lee9431b832015-03-09 18:46:45 -07007557 @Override
7558 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007559 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007560 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007561 }
7562
7563 @Override
7564 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Andrew Lee9431b832015-03-09 18:46:45 -07007571 }
7572
Hall Liuf6668912018-10-31 17:05:23 -07007573 /**
7574 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7575 * support for the feature and device firmware support.
7576 *
7577 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7578 */
7579 @Override
7580 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 final Phone phone = getPhone(subscriptionId);
7583 if (phone == null) {
7584 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7585 return false;
7586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7590 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007591 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 return isCarrierSupported && isDeviceSupported;
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Hall Liu98187582018-01-22 19:15:32 -08007596 }
7597
Hall Liuf6668912018-10-31 17:05:23 -07007598 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007599 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7600 * RTT setting, will return true if the device and carrier both support RTT.
7601 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007602 */
7603 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 final long identity = Binder.clearCallingIdentity();
7605 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007606 boolean isRttSupported = isRttSupported(subscriptionId);
7607 boolean isUserRttSettingOn = Settings.Secure.getInt(
7608 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7609 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7610 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7611 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007615 }
7616
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007617 @Deprecated
7618 @Override
7619 public String getDeviceId(String callingPackage) {
7620 return getDeviceIdWithFeature(callingPackage, null);
7621 }
7622
Sanket Padawe7310cc72015-01-14 09:53:20 -08007623 /**
7624 * Returns the unique device ID of phone, for example, the IMEI for
7625 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7626 *
7627 * <p>Requires Permission:
7628 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7629 */
7630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007631 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007632 try {
7633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7634 } catch (SecurityException se) {
7635 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7636 throw new SecurityException("Package " + callingPackage + " does not belong to "
7637 + Binder.getCallingUid());
7638 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007639 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007640 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007641 return null;
7642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007643 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007644 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007646 return null;
7647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return phone.getDeviceId();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007655 }
7656
Ping Sunc67b7c22016-03-02 19:16:45 +08007657 /**
7658 * {@hide}
7659 * Returns the IMS Registration Status on a particular subid
7660 *
7661 * @param subId
7662 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isImsRegistered();
7667 } else {
7668 return false;
7669 }
7670 }
7671
Santos Cordon7a1885b2015-02-03 11:15:19 -08007672 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007673 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007677 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7678 }
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
7687 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007688 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007689 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007690 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007691 mApp,
7692 subscriptionId,
7693 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subscriptionId);
7697 if (phone == null) {
7698 return null;
7699 }
7700 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007706 /**
7707 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007708 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone != null) {
7714 return phone.isWifiCallingEnabled();
7715 } else {
7716 return false;
7717 }
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007720 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007721 }
7722
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007724 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007725 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007726 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = getPhone(subId);
7730 if (phone != null) {
7731 return phone.isVideoEnabled();
7732 } else {
7733 return false;
7734 }
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007737 }
7738 }
7739
7740 /**
7741 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7742 * defined in {@link ImsRegistrationImplBase}.
7743 */
7744 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = getPhone(subId);
7748 if (phone != null) {
7749 return phone.getImsRegistrationTech();
7750 } else {
7751 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007755 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007756 }
7757
Stuart Scott8eef64f2015-04-08 15:13:54 -07007758 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007759 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007760 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007761 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7762 return;
7763 }
Kai Shif70f46f2021-03-03 13:59:46 -08007764 Phone defaultPhone = getDefaultPhone();
7765 if (defaultPhone != null) {
7766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7767 mApp, getDefaultPhone().getSubId(), "factoryReset");
7768 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007769 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007770
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007772 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7773 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007774 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007775 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007776 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007777 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007778 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007780 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007781 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007782 // There has been issues when Sms raw table somehow stores orphan
7783 // fragments. They lead to garbled message when new fragments come
7784 // in and combined with those stale ones. In case this happens again,
7785 // user can reset all network settings which will clean up this table.
7786 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007787 // Clean up IMS settings as well here.
7788 int slotId = getSlotIndex(subId);
7789 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7790 ImsManager.getInstance(mApp, slotId).factoryReset();
7791 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007792
Kai Shif70f46f2021-03-03 13:59:46 -08007793 if (defaultPhone == null) {
7794 return;
7795 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007796 // Erase modem config if erase modem on network setting is enabled.
7797 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7798 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7799 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007800 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007801 }
Kai Shif70f46f2021-03-03 13:59:46 -08007802
7803 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007804 } finally {
7805 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007806 }
7807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007808
SongFerngWangfd89b102021-05-27 22:44:54 +08007809 @VisibleForTesting
7810 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7811 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7812 return;
7813 }
7814 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7815 RILConstants.PREFERRED_NETWORK_MODE);
7816 SubscriptionManager.setSubscriptionProperty(subId,
7817 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7818 "user=" + defaultNetworkType);
7819 phone.loadAllowedNetworksFromSubscriptionDatabase();
7820 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7821 defaultNetworkType, null);
7822 }
7823
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007824 private void cleanUpSmsRawTable(Context context) {
7825 ContentResolver resolver = context.getContentResolver();
7826 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7827 resolver.delete(uri, null, null);
7828 }
7829
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007831 public String getSimLocaleForSubscriber(int subId) {
7832 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7833 final Phone phone = getPhone(subId);
7834 if (phone == null) {
7835 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007836 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 final long identity = Binder.clearCallingIdentity();
7839 try {
chen xu5d3637b2019-01-21 23:31:38 -08007840 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007841 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007842 if (info == null) {
7843 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7844 return null;
7845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 // Try and fetch the locale from the carrier properties or from the SIM language
7847 // preferences (EF-PL and EF-LI)...
7848 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007850 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7851 if (localeFromDefaultSim != null) {
7852 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7853 if (DBG) log("Using locale from subId: " + subId + " locale: "
7854 + localeFromDefaultSim);
Greg Kaiser4380e732022-10-25 16:07:20 +00007855 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007856 } else {
7857 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 }
7859 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 // The SIM language preferences only store a language (e.g. fr = French), not an
7862 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7863 // the SIM and carrier preferences does not include a country we add the country
7864 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007865 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007867 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Greg Kaiser4380e732022-10-25 16:07:20 +00007868 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 }
7870
7871 if (DBG) log("No locale found - returning null");
7872 return null;
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007876 }
7877
tom hsu0b59d292022-09-29 23:49:21 +08007878 @VisibleForTesting
Greg Kaiser4380e732022-10-25 16:07:20 +00007879 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007880 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
Greg Kaiser4380e732022-10-25 16:07:20 +00007881 getDefaultPhone().getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007882 for (String localeTag : supportedLocale) {
7883 if (LocaleList.matchesLanguageAndScript(
7884 inputLocale, Locale.forLanguageTag(localeTag))
7885 && inputLocale.getCountry().equals(
7886 Locale.forLanguageTag(localeTag).getCountry())) {
7887 return localeTag;
7888 }
7889 }
7890 return inputLocale.toLanguageTag();
7891 }
7892
Narayan Kamath1c496c22015-04-16 14:40:19 +01007893 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007894 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007895 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007896 }
7897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 /**
7899 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7900 */
7901 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007902 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007903 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007904 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007905
Gary Jian3aa9a762022-01-24 16:41:19 +08007906 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7907 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007908
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007909 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007910 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7911 * representing the state of the modem.
7912 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007913 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7914 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007915 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007916 */
7917 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007918 public void requestModemActivityInfo(ResultReceiver result) {
7919 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007920 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921
7922 final long identity = Binder.clearCallingIdentity();
7923 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007924 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 } finally {
7926 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007927 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007928 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007929
Siddharth Rayb8114062018-06-17 15:02:38 -07007930 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7931 // less than total activity duration.
7932 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7933 if (info == null) {
7934 return false;
7935 }
7936 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007937 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7938 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7939
Siddharth Rayb8114062018-06-17 15:02:38 -07007940 return (info.isValid()
7941 && (info.getSleepTimeMillis() <= activityDurationMs)
7942 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007943 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007944 && (totalTxTimeMs <= activityDurationMs));
7945 }
7946
Gary Jian3aa9a762022-01-24 16:41:19 +08007947 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7948 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7949 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7950 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7951
7952 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7953 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7954 }
7955
7956 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7957 mLastModemActivityInfo.setReceiveTimeMillis(
7958 rat,
7959 freq,
7960 info.getReceiveTimeMillis(rat, freq)
7961 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7962 }
7963
7964 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7965 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7966 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7967 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7968
7969 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7970 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7971 }
7972 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7973 mLastModemActivityInfo.setReceiveTimeMillis(
7974 rat,
7975 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7976 }
7977
7978 /**
7979 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7980 * @param info recent ModemActivityInfo
7981 */
7982 private void mergeModemActivityInfo(ModemActivityInfo info) {
7983 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7984 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7985 boolean matched;
7986 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7987 matched = false;
7988 int rat = info.getSpecificInfoRat(i);
7989 int freq = info.getSpecificInfoFrequencyRange(i);
7990 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7991 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7992 //if it already exists
7993 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7994 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7995 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7996 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7997 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7998 updateLastModemActivityInfo(info, rat, freq);
7999 matched = true;
8000 }
8001 } else {
8002 updateLastModemActivityInfo(info, rat);
8003 matched = true;
8004 }
8005 }
8006 }
8007
8008 if (!matched) {
8009 mDeltaSpecificInfo =
8010 new ActivityStatsTechSpecificInfo(
8011 rat,
8012 freq,
8013 info.getTransmitTimeMillis(rat, freq),
8014 (int) info.getReceiveTimeMillis(rat, freq));
8015 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8016 }
8017 }
8018 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8019 mLastModemActivitySpecificInfo =
8020 new ActivityStatsTechSpecificInfo[merged.size()];
8021 merged.toArray(mLastModemActivitySpecificInfo);
8022
8023 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8024 mLastModemActivityInfo.setSleepTimeMillis(
8025 info.getSleepTimeMillis()
8026 + mLastModemActivityInfo.getSleepTimeMillis());
8027 mLastModemActivityInfo.setIdleTimeMillis(
8028 info.getIdleTimeMillis()
8029 + mLastModemActivityInfo.getIdleTimeMillis());
8030 }
8031
Jack Yu85bd38a2015-11-09 11:34:32 -08008032 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008033 * Returns the service state information on specified subscription.
8034 */
8035 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008036 public ServiceState getServiceStateForSubscriber(int subId,
8037 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8038 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008040 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008041 return null;
8042 }
8043
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008044 boolean hasFinePermission = false;
8045 boolean hasCoarsePermission = false;
8046 if (!renounceFineLocationAccess) {
8047 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8048 LocationAccessPolicy.checkLocationPermission(mApp,
8049 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8050 .setCallingPackage(callingPackage)
8051 .setCallingFeatureId(callingFeatureId)
8052 .setCallingPid(Binder.getCallingPid())
8053 .setCallingUid(Binder.getCallingUid())
8054 .setMethod("getServiceStateForSubscriber")
8055 .setLogAsInfo(true)
8056 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8058 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8059 .build());
8060 hasFinePermission =
8061 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8062 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008063
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008064 if (!renounceCoarseLocationAccess) {
8065 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8066 LocationAccessPolicy.checkLocationPermission(mApp,
8067 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8068 .setCallingPackage(callingPackage)
8069 .setCallingFeatureId(callingFeatureId)
8070 .setCallingPid(Binder.getCallingPid())
8071 .setCallingUid(Binder.getCallingUid())
8072 .setMethod("getServiceStateForSubscriber")
8073 .setLogAsInfo(true)
8074 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8075 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8076 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8077 .build());
8078 hasCoarsePermission =
8079 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8080 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008081
Jack Yu479f40e2020-10-27 21:29:25 -07008082 final Phone phone = getPhone(subId);
8083 if (phone == null) {
8084 return null;
8085 }
8086
Jordan Liu0f2bc442020-11-18 16:47:37 -08008087 final long identity = Binder.clearCallingIdentity();
8088
Jack Yu479f40e2020-10-27 21:29:25 -07008089 boolean isCallingPackageDataService = phone.getDataServicePackages()
8090 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008092 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8093 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8094 Rlog.d(LOG_TAG,
8095 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8096 return null;
8097 }
8098
Hall Liuf19c44f2018-11-27 14:38:17 -08008099 ServiceState ss = phone.getServiceState();
8100
8101 // Scrub out the location info in ServiceState depending on what level of access
8102 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008103 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008104 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8105 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 } finally {
8107 Binder.restoreCallingIdentity(identity);
8108 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008109 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008110
8111 /**
8112 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8113 *
8114 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8115 * voicemail ringtone.
8116 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8117 * PhoneAccount.
8118 */
8119 @Override
8120 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8124 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008125 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008132 }
8133
8134 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008135 * Sets the per-account voicemail ringtone.
8136 *
8137 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8138 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8139 *
8140 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8141 * voicemail ringtone.
8142 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8143 * PhoneAccount.
8144 */
8145 @Override
8146 public void setVoicemailRingtoneUri(String callingPackage,
8147 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008148 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008150 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8151 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8153 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8154 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8160 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008161 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 }
8163 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008167 }
8168
8169 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008170 * Returns whether vibration is set for voicemail notification in Phone settings.
8171 *
8172 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8173 * voicemail vibration setting.
8174 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8175 */
8176 @Override
8177 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8181 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008182 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008189 }
8190
Youhan Wange64578a2016-05-02 15:32:42 -07008191 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008192 * Sets the per-account voicemail vibration.
8193 *
8194 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8195 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8196 *
8197 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8198 * voicemail vibration setting.
8199 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8200 * specific PhoneAccount.
8201 */
8202 @Override
8203 public void setVoicemailVibrationEnabled(String callingPackage,
8204 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008205 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008207 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8208 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8210 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8211 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008212 }
8213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8217 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008218 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 }
8220 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008223 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008224 }
8225
8226 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008227 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8228 *
8229 * @throws SecurityException if the caller does not have the required permission
8230 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008231 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008232 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008233 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008234 }
8235
8236 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008237 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8238 * permission.
8239 *
8240 * @throws SecurityException if the caller does not have the required permission
8241 */
8242 private void enforceSendSmsPermission() {
8243 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8244 }
8245
8246 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008247 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008248 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008249 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008250 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008251 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 final long identity = Binder.clearCallingIdentity();
8253 try {
8254 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008255 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008256 if (componentName == null) {
8257 throw new SecurityException(
8258 "Caller not current active visual voicemail package[null]");
8259 }
8260 String vvmPackage = componentName.getPackageName();
8261 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008262 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 }
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008266 }
8267 }
8268
8269 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008270 * Return the application ID for the app type.
8271 *
8272 * @param subId the subscription ID that this request applies to.
8273 * @param appType the uicc app type.
8274 * @return Application ID for specificied app type, or null if no uicc.
8275 */
8276 @Override
8277 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008278 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008279 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008280
8281 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008282 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 if (phone == null) {
8284 return null;
8285 }
8286 String aid = null;
8287 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008288 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289 .getApplicationByType(appType).getAid();
8290 } catch (Exception e) {
8291 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8292 }
8293 return aid;
8294 } finally {
8295 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008296 }
Youhan Wange64578a2016-05-02 15:32:42 -07008297 }
8298
Youhan Wang4001d252016-05-11 10:29:41 -07008299 /**
8300 * Return the Electronic Serial Number.
8301 *
8302 * @param subId the subscription ID that this request applies to.
8303 * @return ESN or null if error.
8304 */
8305 @Override
8306 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008307 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008308 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309
8310 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008311 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008312 if (phone == null) {
8313 return null;
8314 }
8315 String esn = null;
8316 try {
8317 esn = phone.getEsn();
8318 } catch (Exception e) {
8319 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8320 }
8321 return esn;
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008324 }
Youhan Wang4001d252016-05-11 10:29:41 -07008325 }
8326
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008327 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008328 * Return the Preferred Roaming List Version.
8329 *
8330 * @param subId the subscription ID that this request applies to.
8331 * @return PRLVersion or null if error.
8332 */
8333 @Override
8334 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008335 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008336 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337
8338 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008339 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 if (phone == null) {
8341 return null;
8342 }
8343 String cdmaPrlVersion = null;
8344 try {
8345 cdmaPrlVersion = phone.getCdmaPrlVersion();
8346 } catch (Exception e) {
8347 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8348 }
8349 return cdmaPrlVersion;
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008352 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008353 }
8354
8355 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008356 * Get snapshot of Telephony histograms
8357 * @return List of Telephony histograms
8358 * @hide
8359 */
8360 @Override
8361 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8363 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
8366 try {
8367 return RIL.getTelephonyRILTimingHistograms();
8368 } finally {
8369 Binder.restoreCallingIdentity(identity);
8370 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008371 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008372
8373 /**
8374 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008375 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8376 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008377 * Require system privileges. In the future we may add this to carrier APIs.
8378 *
Michele Berionne482f8202018-11-27 18:57:59 -08008379 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008380 */
8381 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008382 @TelephonyManager.SetCarrierRestrictionResult
8383 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008384 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008386
Michele Berionne482f8202018-11-27 18:57:59 -08008387 if (carrierRestrictionRules == null) {
8388 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008389 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 final long identity = Binder.clearCallingIdentity();
8392 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008393 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008394 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 } finally {
8396 Binder.restoreCallingIdentity(identity);
8397 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008398 }
8399
8400 /**
8401 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008402 * Get the allowed carrier list and the excluded carrier list, including the priority between
8403 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008404 * Require system privileges. In the future we may add this to carrier APIs.
8405 *
Michele Berionne482f8202018-11-27 18:57:59 -08008406 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008407 */
8408 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008409 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008410 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412
8413 final long identity = Binder.clearCallingIdentity();
8414 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008415 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8416 if (response instanceof CarrierRestrictionRules) {
8417 return (CarrierRestrictionRules) response;
8418 }
8419 // Response is an Exception of some kind,
8420 // which is signalled to the user as a NULL retval
8421 return null;
8422 } catch (Exception e) {
8423 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8424 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008428 }
8429
fionaxu59545b42016-05-25 15:53:37 -07008430 /**
fionaxu59545b42016-05-25 15:53:37 -07008431 * Action set from carrier signalling broadcast receivers to enable/disable radio
8432 * @param subId the subscription ID that this action applies to.
8433 * @param enabled control enable or disable radio.
8434 * {@hide}
8435 */
8436 @Override
8437 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8438 enforceModifyPermission();
8439 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008442 if (phone == null) {
8443 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8444 return;
8445 }
8446 try {
8447 phone.carrierActionSetRadioEnabled(enabled);
8448 } catch (Exception e) {
8449 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 } finally {
8451 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008452 }
8453 }
8454
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008455 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008456 * Enable or disable Voice over NR (VoNR)
8457 * @param subId the subscription ID that this action applies to.
8458 * @param enabled enable or disable VoNR.
8459 * @return operation result.
8460 */
8461 @Override
8462 public int setVoNrEnabled(int subId, boolean enabled) {
8463 enforceModifyPermission();
8464 final Phone phone = getPhone(subId);
8465
8466 final long identity = Binder.clearCallingIdentity();
8467 if (phone == null) {
8468 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8469 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8470 }
8471
8472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8473 try {
8474 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8475 workSource);
8476 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008477
8478 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8479 if (DBG) {
8480 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8481 }
8482 SubscriptionManager.setSubscriptionProperty(
8483 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8484 (enabled ? "1" : "0"));
8485 }
8486
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008487 return result;
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
8492
8493 /**
8494 * Is voice over NR enabled
8495 * @return true if VoNR is enabled else false
8496 */
8497 @Override
8498 public boolean isVoNrEnabled(int subId) {
8499 enforceReadPrivilegedPermission("isVoNrEnabled");
8500 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8504 null, subId, workSource);
8505 if (DBG) log("isVoNrEnabled: " + isEnabled);
8506 return isEnabled;
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 }
8511
8512 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008513 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8514 * network status based on which carrier apps could apply actions accordingly,
8515 * enable/disable default url handler for example.
8516 *
8517 * @param subId the subscription ID that this action applies to.
8518 * @param report control start/stop reporting the default network status.
8519 * {@hide}
8520 */
8521 @Override
8522 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8523 enforceModifyPermission();
8524 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525
8526 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008527 if (phone == null) {
8528 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8529 return;
8530 }
8531 try {
8532 phone.carrierActionReportDefaultNetworkStatus(report);
8533 } catch (Exception e) {
8534 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535 } finally {
8536 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008537 }
8538 }
8539
8540 /**
fionaxud9622282017-07-17 17:51:30 -07008541 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8542 * @param subId the subscription ID that this action applies to.
8543 * {@hide}
8544 */
8545 @Override
8546 public void carrierActionResetAll(int subId) {
8547 enforceModifyPermission();
8548 final Phone phone = getPhone(subId);
8549 if (phone == null) {
8550 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8551 return;
8552 }
8553 try {
8554 phone.carrierActionResetAll();
8555 } catch (Exception e) {
8556 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8557 }
8558 }
8559
8560 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008561 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8562 * bug report is being generated.
8563 */
8564 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008565 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008566 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8567 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008568 writer.println("Permission Denial: can't dump Phone from pid="
8569 + Binder.getCallingPid()
8570 + ", uid=" + Binder.getCallingUid()
8571 + "without permission "
8572 + android.Manifest.permission.DUMP);
8573 return;
8574 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008575 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008576 }
Jack Yueb89b242016-06-22 13:27:47 -07008577
Brad Ebingerdac2f002018-04-03 15:17:52 -07008578 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008579 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8580 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8581 @NonNull String[] args) {
8582 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8583 this, in.getFileDescriptor(), out.getFileDescriptor(),
8584 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008585 }
8586
Jack Yueb89b242016-06-22 13:27:47 -07008587 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008588 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008589 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008590 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008591 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008592 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008593 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008594 */
8595 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008596 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008597 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008598 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8599 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8600 try {
8601 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008602 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008603 } catch (SecurityException se) {
8604 enforceModifyPermission();
8605 }
8606 } else {
8607 enforceModifyPermission();
8608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609
8610 final long identity = Binder.clearCallingIdentity();
8611 try {
8612 Phone phone = getPhone(subId);
8613 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008614 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8615 phone.carrierActionSetMeteredApnsEnabled(enabled);
8616 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008617 phone.getDataSettingsManager().setDataEnabled(
8618 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 }
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008623 }
8624 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008625
8626 /**
8627 * Get Client request stats
8628 * @return List of Client Request Stats
8629 * @hide
8630 */
8631 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008632 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8633 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008634 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008635 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008636 return null;
8637 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008638 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 final long identity = Binder.clearCallingIdentity();
8641 try {
8642 if (phone != null) {
8643 return phone.getClientRequestStats();
8644 }
8645
8646 return null;
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008650 }
8651
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008652 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008653 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008654 if (uid == Process.ROOT_UID && packageName == null) {
8655 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8656 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8657 // exception. ROOT_UID seems not to have a valid package name returned by
8658 // PackageManager, so just fake it here to avoid issues when running telephony shell
8659 // commands that plumb through the RIL as root, like so:
8660 // $ adb root
8661 // $ adb shell cmd phone ...
8662 packageName = "root";
8663 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008664 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008665 }
Jack Yueb4124c2017-02-16 15:32:43 -08008666
8667 /**
Grace Chen70990072017-03-24 17:21:30 -07008668 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008669 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008670 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008671 * @param state State of SIM (power down, power up, pass through)
8672 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8674 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008675 *
8676 **/
8677 @Override
Grace Chen70990072017-03-24 17:21:30 -07008678 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008679 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008680 Phone phone = PhoneFactory.getPhone(slotIndex);
8681
vagdeviaf9a5b92018-08-15 16:01:53 -07008682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008684 final long identity = Binder.clearCallingIdentity();
8685 try {
8686 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008687 phone.setSimPowerState(state, null, workSource);
8688 }
8689 } finally {
8690 Binder.restoreCallingIdentity(identity);
8691 }
8692 }
8693
8694 /**
8695 * Set SIM card power state.
8696 *
8697 * @param slotIndex SIM slot id.
8698 * @param state State of SIM (power down, power up, pass through)
8699 * @param callback callback to trigger after success or failure
8700 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8702 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8703 *
8704 **/
8705 @Override
8706 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8707 IIntegerConsumer callback) {
8708 enforceModifyPermission();
8709 Phone phone = PhoneFactory.getPhone(slotIndex);
8710
8711 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8712
8713 final long identity = Binder.clearCallingIdentity();
8714 try {
8715 if (phone != null) {
8716 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8717 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008718 }
8719 } finally {
8720 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008721 }
8722 }
Shuo Qiandd210312017-04-12 22:11:33 +00008723
Tyler Gunn65d45c22017-06-05 11:22:26 -07008724 private boolean isUssdApiAllowed(int subId) {
8725 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008726 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008727 if (configManager == null) {
8728 return false;
8729 }
8730 PersistableBundle pb = configManager.getConfigForSubId(subId);
8731 if (pb == null) {
8732 return false;
8733 }
8734 return pb.getBoolean(
8735 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8736 }
8737
Shuo Qiandd210312017-04-12 22:11:33 +00008738 /**
8739 * Check if phone is in emergency callback mode
8740 * @return true if phone is in emergency callback mode
8741 * @param subId sub id
8742 */
goneil9c5f4872017-12-05 14:07:56 -08008743 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008744 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008745 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008747
8748 final long identity = Binder.clearCallingIdentity();
8749 try {
8750 if (phone != null) {
8751 return phone.isInEcm();
8752 } else {
8753 return false;
8754 }
8755 } finally {
8756 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008757 }
8758 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008759
8760 /**
8761 * Get the current signal strength information for the given subscription.
8762 * Because this information is not updated when the device is in a low power state
8763 * it should not be relied-upon to be current.
8764 * @param subId Subscription index
8765 * @return the most recent cached signal strength info from the modem
8766 */
8767 @Override
8768 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 Phone p = getPhone(subId);
8772 if (p == null) {
8773 return null;
8774 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008776 return p.getSignalStrength();
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008780 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008781
Pengquan Meng77b7f132018-08-22 14:49:57 -07008782 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008783 * Get the current modem radio state for the given slot.
8784 * @param slotIndex slot index.
8785 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008786 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008787 * @return the current radio power state from the modem
8788 */
8789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008790 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008791 Phone phone = PhoneFactory.getPhone(slotIndex);
8792 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8794 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008795 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8796 }
8797
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
8800 return phone.getRadioPowerState();
8801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8806 }
8807
8808 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008809 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8810 *
8811 * <p>Requires one of the following permissions:
8812 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008813 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008814 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8815 * privileges.
8816 *
8817 * @param subId subscription id
8818 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8819 * {@code false}.
8820 */
8821 @Override
8822 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008823 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008824 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008825 try {
8826 mApp.enforceCallingOrSelfPermission(
8827 android.Manifest.permission.ACCESS_NETWORK_STATE,
8828 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008829 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008830 mApp.enforceCallingOrSelfPermission(
8831 permission.READ_BASIC_PHONE_STATE, functionName);
8832 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008833 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008834 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008835 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008836 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008837
Pengquan Menga1bb6272018-09-06 09:59:22 -07008838 boolean isEnabled = false;
8839 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008840 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008841 Phone phone = getPhone(subId);
8842 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008843 } finally {
8844 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008845 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008846 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008847 }
8848
8849
8850 /**
8851 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8852 *
8853 * <p> Requires permission:
8854 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8855 * privileges.
8856 *
8857 * @param subId subscription id
8858 * @param isEnabled {@code true} means enable, {@code false} means disable.
8859 */
8860 @Override
8861 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8863 mApp, subId, "setDataRoamingEnabled");
8864
Pengquan Menga1bb6272018-09-06 09:59:22 -07008865 final long identity = Binder.clearCallingIdentity();
8866 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008867 Phone phone = getPhone(subId);
8868 if (phone != null) {
8869 phone.setDataRoamingEnabled(isEnabled);
8870 }
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008873 }
8874 }
8875
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008876 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008877 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008878 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008879 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008880 mApp, subId, "isManualNetworkSelectionAllowed");
8881
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008882 boolean isAllowed = true;
8883 final long identity = Binder.clearCallingIdentity();
8884 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008885 Phone phone = getPhone(subId);
8886 if (phone != null) {
8887 isAllowed = phone.isCspPlmnEnabled();
8888 }
8889 } finally {
8890 Binder.restoreCallingIdentity(identity);
8891 }
8892 return isAllowed;
8893 }
8894
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008895 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8896 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008897 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008898 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008899 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008900 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8901 if (phone == null) {
8902 return false;
8903 }
8904 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8905 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8906 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008907 }
8908
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008909 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008910 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008911 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008912 mApp.getSystemService(AppOpsManager.class)
8913 .checkPackage(Binder.getCallingUid(), callingPackage);
8914
Jordan Liu1e142fc2019-04-22 15:10:43 -07008915 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008916 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008917 try {
8918 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008919 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008920 } catch (SecurityException e) {
8921 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8922 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008923 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008924 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008925 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008926 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008927 }
sandeepjsb6c87872021-09-27 15:34:44 +00008928 // checking compatibility, if calling app's target SDK is T and beyond.
8929 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8930 Binder.getCallingUid())) {
8931 isIccIdAccessRestricted = true;
8932 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008933 final long identity = Binder.clearCallingIdentity();
8934 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008935 UiccController uiccController = UiccController.getInstance();
8936 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008937 if (hasReadPermission) {
8938 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008939 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008940
8941 // Remove private info if the caller doesn't have access
8942 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8943 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008944 //setting the value after compatibility check
8945 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008946 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8947 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008948 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008949 if (card == null) {
8950 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008951 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008952 continue;
8953 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008954 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8955 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008956 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008957 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008958 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008959 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8960 for (UiccPortInfo portInfo : portInfos) {
8961 UiccPort port = uiccController.getUiccPortForSlot(
8962 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8963 if (port == null) {
8964 // assume no access if port is null
8965 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8966 continue;
8967 }
8968 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8969 uiccPortInfos.add(portInfo);
8970 } else {
8971 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8972 }
8973 }
8974 filteredInfos.add(new UiccCardInfo(
8975 cardInfo.isEuicc(),
8976 cardInfo.getCardId(),
8977 null,
8978 cardInfo.getPhysicalSlotIndex(),
8979 cardInfo.isRemovable(),
8980 cardInfo.isMultipleEnabledProfilesSupported(),
8981 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008982 }
8983 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008984 } finally {
8985 Binder.restoreCallingIdentity(identity);
8986 }
8987 }
8988
sandeepjsb6c87872021-09-27 15:34:44 +00008989 /**
8990 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8991 * generally private and require carrier privileges to view.
8992 *
8993 * @hide
8994 */
8995 @NonNull
8996 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8997 List<UiccPortInfo> portinfo = new ArrayList<>();
8998 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8999 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
9000 }
9001 return new UiccCardInfo(
9002 cardInfo.isEuicc(),
9003 cardInfo.getCardId(),
9004 null,
9005 cardInfo.getPhysicalSlotIndex(),
9006 cardInfo.isRemovable(),
9007 cardInfo.isMultipleEnabledProfilesSupported(),
9008 portinfo
9009 );
9010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009011
sandeepjsb6c87872021-09-27 15:34:44 +00009012 /**
9013 * @hide
9014 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9015 * These values are generally private and require carrier privileges to view.
9016 */
9017 @NonNull
9018 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9019 return new UiccPortInfo(
9020 UiccPortInfo.ICCID_REDACTED,
9021 portInfo.getPortIndex(),
9022 portInfo.getLogicalSlotIndex(),
9023 portInfo.isActive()
9024 );
9025 }
9026 @Override
9027 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009028 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009029 mApp.getSystemService(AppOpsManager.class)
9030 .checkPackage(Binder.getCallingUid(), callingPackage);
9031
sandeepjsb6c87872021-09-27 15:34:44 +00009032 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009033
Aman Guptaf3c90b32022-03-17 04:54:16 +00009034 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9035 // we are reading iccId which is PII data.
9036 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009037
9038 // checking compatibility, if calling app's target SDK is T and beyond.
9039 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9040 Binder.getCallingUid())) {
9041 isLogicalSlotAccessRestricted = true;
9042 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009043 final long identity = Binder.clearCallingIdentity();
9044 try {
9045 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009046 if (slots == null || slots.length == 0) {
9047 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048 return null;
9049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009050 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9051 for (int i = 0; i < slots.length; i++) {
9052 UiccSlot slot = slots[i];
9053 if (slot == null) {
9054 continue;
9055 }
9056
Jordan Liu7be7e652019-05-06 18:55:02 +00009057 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009058 UiccCard card = slot.getUiccCard();
9059 if (card != null) {
9060 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009061 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009062 cardId = slot.getEid();
9063 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009064 // If cardId is null, use iccId of default port as cardId.
9065 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009067 }
9068
Jordan Liu857451f2019-05-09 16:35:35 -07009069 if (cardId != null) {
9070 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9071 // if cardId is an EID, it's all digits so this is fine
9072 cardId = IccUtils.stripTrailingFs(cardId);
9073 }
9074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009075 int cardState = 0;
9076 switch (slot.getCardState()) {
9077 case CARDSTATE_ABSENT:
9078 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9079 break;
9080 case CARDSTATE_PRESENT:
9081 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9082 break;
9083 case CARDSTATE_ERROR:
9084 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9085 break;
9086 case CARDSTATE_RESTRICTED:
9087 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9088 break;
9089 default:
9090 break;
9091
9092 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009093 List<UiccPortInfo> portInfos = new ArrayList<>();
9094 int[] portIndexes = slot.getPortList();
9095 for (int portIdx : portIndexes) {
9096 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009097 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009098 portInfos.add(new UiccPortInfo(iccId, portIdx,
9099 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009102 slot.isEuicc(),
9103 cardId,
9104 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009105 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009106 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009107 //setting the value after compatibility check
9108 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009109 }
9110 return infos;
9111 } finally {
9112 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009113 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009114 }
9115
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009116 /* Returns null if doesn't have read permission or carrier privilege access. */
9117 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9118 boolean hasReadPermission) {
9119 String iccId = slot.getIccId(portIndex);
9120 if (hasReadPermission) { // if has read permission
9121 return iccId;
9122 } else {
9123 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9124 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9125 // if no read permission, checking carrier privilege access
9126 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9127 return iccId;
9128 }
9129 }
9130 }
9131 // No read permission or carrier privilege access.
9132 return UiccPortInfo.ICCID_REDACTED;
9133 }
9134
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009135 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009136 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009137 public boolean switchSlots(int[] physicalSlots) {
9138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139
9140 final long identity = Binder.clearCallingIdentity();
9141 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009142 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9143 for (int i = 0; i < physicalSlots.length; i++) {
9144 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9145 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9146 physicalSlots[i], i));
9147 }
9148 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009152 }
Jack Yu4c988042018-02-27 15:30:01 -08009153
9154 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009155 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9156 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9157 enforceModifyPermission();
9158
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009161 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
9166
9167 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009168 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 return UiccController.getInstance().getCardIdForDefaultEuicc();
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
Pengquan Meng85728fb2018-03-12 16:31:21 -07009177 /**
goneil47ffb6e2018-04-06 15:40:58 -07009178 * A test API to reload the UICC profile.
9179 *
9180 * <p>Requires that the calling app has permission
9181 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9182 * @hide
9183 */
9184 @Override
9185 public void refreshUiccProfile(int subId) {
9186 enforceModifyPermission();
9187
9188 final long identity = Binder.clearCallingIdentity();
9189 try {
9190 Phone phone = getPhone(subId);
9191 if (phone == null) {
9192 return;
9193 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009194 UiccPort uiccPort = phone.getUiccPort();
9195 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009196 return;
9197 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009198 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009199 if (uiccProfile == null) {
9200 return;
9201 }
9202 uiccProfile.refresh();
9203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
9206 }
9207
9208 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009209 * Returns false if the mobile data is disabled by default, otherwise return true.
9210 */
9211 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009212 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009213 }
9214
9215 /**
9216 * Returns true if the data roaming is enabled by default, i.e the system property
9217 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9218 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9219 */
9220 private boolean getDefaultDataRoamingEnabled(int subId) {
9221 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009222 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009223 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009224 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9225 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9226 return isDataRoamingEnabled;
9227 }
9228
9229 /**
9230 * Returns the default network type for the given {@code subId}, if the default network type is
9231 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9232 */
9233 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009234 List<Integer> list = TelephonyProperties.default_network();
9235 int phoneId = mSubscriptionController.getPhoneId(subId);
9236 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9237 return list.get(phoneId);
9238 }
9239 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009240 }
fionaxua13278b2018-03-21 00:08:13 -07009241
9242 @Override
9243 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009244 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009245 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009246
9247 final long identity = Binder.clearCallingIdentity();
9248 try {
9249 final Phone phone = getPhone(subId);
9250 if (phone == null) {
9251 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9252 return;
9253 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009254 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9255 if (cpt != null) {
9256 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9257 }
9258 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009259 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9260 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009261 if (carrierPrivilegeRules == null) {
9262 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9263 } else {
9264 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009266 } finally {
9267 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009268 }
fionaxua13278b2018-03-21 00:08:13 -07009269 }
9270
9271 @Override
9272 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009273 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009274
9275 final long identity = Binder.clearCallingIdentity();
9276 try {
9277 final Phone phone = getPhone(subId);
9278 if (phone == null) {
9279 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9280 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9281 }
9282 return phone.getCarrierIdListVersion();
9283 } finally {
9284 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009285 }
fionaxua13278b2018-03-21 00:08:13 -07009286 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009287
9288 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009289 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9290 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009292 mApp, subId, callingPackage, callingFeatureId,
9293 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009294 return -1;
9295 }
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009304
9305 @Override
9306 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009307 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009308 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009309 mApp, subId, "getCdmaRoamingMode");
9310
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
9318
9319 @Override
9320 public boolean setCdmaRoamingMode(int subId, int mode) {
9321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9322 mApp, subId, "setCdmaRoamingMode");
9323
9324 final long identity = Binder.clearCallingIdentity();
9325 try {
9326 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
9331
9332 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009333 public int getCdmaSubscriptionMode(int subId) {
9334 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009335 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009336 mApp, subId, "getCdmaSubscriptionMode");
9337
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9341 } finally {
9342 Binder.restoreCallingIdentity(identity);
9343 }
9344 }
9345
9346 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009347 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9349 mApp, subId, "setCdmaSubscriptionMode");
9350
9351 final long identity = Binder.clearCallingIdentity();
9352 try {
9353 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9354 } finally {
9355 Binder.restoreCallingIdentity(identity);
9356 }
9357 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009358
sqianc5eccab2018-10-19 18:46:41 -07009359 @Override
sqian8c685422019-02-22 15:55:18 -08009360 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009361 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009363 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9364 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009365 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9366 }
9367 final long identity = Binder.clearCallingIdentity();
9368 try {
sqian854d44b2018-12-12 16:48:18 -08009369 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9370 for (Phone phone: PhoneFactory.getPhones()) {
9371 if (phone.getEmergencyNumberTracker() != null
9372 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9373 emergencyNumberListInternal.put(
9374 phone.getSubId(),
9375 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9376 }
sqian11b7a0e2018-12-05 18:48:28 -08009377 }
sqian854d44b2018-12-12 16:48:18 -08009378 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
sqianc5eccab2018-10-19 18:46:41 -07009382 }
9383
9384 @Override
sqian8c685422019-02-22 15:55:18 -08009385 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009386 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009387 if (!exactMatch) {
9388 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009389 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009390 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009391 }
9392 final long identity = Binder.clearCallingIdentity();
9393 try {
sqian854d44b2018-12-12 16:48:18 -08009394 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009395 //Note: we ignore passed in param exactMatch. We can remove it once
9396 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009397 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009398 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009399 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009400 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009401 }
sqian11b7a0e2018-12-05 18:48:28 -08009402 }
9403 return false;
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 }
9408
sqianf4ca7ed2019-01-15 18:32:07 -08009409 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009410 * Start emergency callback mode for GsmCdmaPhone for testing.
9411 */
9412 @Override
9413 public void startEmergencyCallbackMode() {
9414 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9415 "startEmergencyCallbackMode");
9416 enforceModifyPermission();
9417 final long identity = Binder.clearCallingIdentity();
9418 try {
9419 for (Phone phone : PhoneFactory.getPhones()) {
9420 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9421 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9422 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9423 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9424 gsmCdmaPhone.obtainMessage(
9425 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9426 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9427 }
9428 }
9429 } finally {
9430 Binder.restoreCallingIdentity(identity);
9431 }
9432 }
9433
9434 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009435 * Update emergency number list for test mode.
9436 */
9437 @Override
9438 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9440 "updateEmergencyNumberListTestMode");
9441
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 for (Phone phone: PhoneFactory.getPhones()) {
9445 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9446 if (tracker != null) {
9447 tracker.executeEmergencyNumberTestModeCommand(action, num);
9448 }
9449 }
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
9454
9455 /**
9456 * Get the full emergency number list for test mode.
9457 */
9458 @Override
9459 public List<String> getEmergencyNumberListTestMode() {
9460 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9461 "getEmergencyNumberListTestMode");
9462
9463 final long identity = Binder.clearCallingIdentity();
9464 try {
9465 Set<String> emergencyNumbers = new HashSet<>();
9466 for (Phone phone: PhoneFactory.getPhones()) {
9467 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9468 if (tracker != null) {
9469 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9470 emergencyNumbers.add(num.getNumber());
9471 }
9472 }
9473 }
9474 return new ArrayList<>(emergencyNumbers);
9475 } finally {
9476 Binder.restoreCallingIdentity(identity);
9477 }
9478 }
9479
chen xud6b45bd2018-10-30 22:27:10 -07009480 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009481 public int getEmergencyNumberDbVersion(int subId) {
9482 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9483
9484 final long identity = Binder.clearCallingIdentity();
9485 try {
9486 final Phone phone = getPhone(subId);
9487 if (phone == null) {
9488 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9489 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9490 }
9491 return phone.getEmergencyNumberDbVersion();
9492 } finally {
9493 Binder.restoreCallingIdentity(identity);
9494 }
9495 }
9496
9497 @Override
9498 public void notifyOtaEmergencyNumberDbInstalled() {
9499 enforceModifyPermission();
9500
9501 final long identity = Binder.clearCallingIdentity();
9502 try {
9503 for (Phone phone: PhoneFactory.getPhones()) {
9504 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9505 if (tracker != null) {
9506 tracker.updateOtaEmergencyNumberDatabase();
9507 }
9508 }
9509 } finally {
9510 Binder.restoreCallingIdentity(identity);
9511 }
9512 }
9513
9514 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009515 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009516 enforceActiveEmergencySessionPermission();
9517
9518 final long identity = Binder.clearCallingIdentity();
9519 try {
9520 for (Phone phone: PhoneFactory.getPhones()) {
9521 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9522 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009523 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9524 }
9525 }
9526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
9530
9531 @Override
9532 public void resetOtaEmergencyNumberDbFilePath() {
9533 enforceActiveEmergencySessionPermission();
9534
9535 final long identity = Binder.clearCallingIdentity();
9536 try {
9537 for (Phone phone: PhoneFactory.getPhones()) {
9538 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9539 if (tracker != null) {
9540 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009541 }
9542 }
9543 } finally {
9544 Binder.restoreCallingIdentity(identity);
9545 }
9546 }
9547
9548 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009549 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9550 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9551 Phone phone = getPhone(subId);
9552 if (phone == null) {
9553 return null;
9554 }
9555 final long identity = Binder.clearCallingIdentity();
9556 try {
9557 UiccProfile profile = UiccController.getInstance()
9558 .getUiccProfileForPhone(phone.getPhoneId());
9559 if (profile != null) {
9560 return profile.getCertsFromCarrierPrivilegeAccessRules();
9561 }
9562 } finally {
9563 Binder.restoreCallingIdentity(identity);
9564 }
9565 return null;
9566 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009567
9568 /**
9569 * Enable or disable a modem stack.
9570 */
9571 @Override
9572 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9573 enforceModifyPermission();
9574
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 Phone phone = PhoneFactory.getPhone(slotIndex);
9578 if (phone == null) {
9579 return false;
9580 } else {
9581 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9582 }
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
Michelecea4cf22018-12-21 15:00:11 -08009587
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009588 /**
9589 * Whether a modem stack is enabled or not.
9590 */
9591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009592 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9593 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009594 Phone phone = PhoneFactory.getPhone(slotIndex);
9595 if (phone == null) return false;
9596
9597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009598 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9599 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009600 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9601 }
9602
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009605 try {
9606 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9607 } catch (NoSuchElementException ex) {
9608 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9609 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009610 } finally {
9611 Binder.restoreCallingIdentity(identity);
9612 }
9613 }
9614
Michelecea4cf22018-12-21 15:00:11 -08009615 @Override
Michele0ea7d782019-03-19 14:58:42 -07009616 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009617 enforceModifyPermission();
9618
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
9621 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009622 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009623 .commit();
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627 }
9628
9629 @Override
Michele0ea7d782019-03-19 14:58:42 -07009630 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009631 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009633 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9634 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009635 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009636 }
Michelecea4cf22018-12-21 15:00:11 -08009637
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
Michele0ea7d782019-03-19 14:58:42 -07009640 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009641 } finally {
9642 Binder.restoreCallingIdentity(identity);
9643 }
9644 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009645
Michele0ea7d782019-03-19 14:58:42 -07009646 @TelephonyManager.IsMultiSimSupportedResult
9647 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009648 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9649 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9650 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009651 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9652 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009653 }
9654 // Check if the hardware supports multisim functionality. If usage of multisim is not
9655 // supported by the modem, indicate that it is restricted.
9656 PhoneCapability staticCapability =
9657 mPhoneConfigurationManager.getStaticPhoneCapability();
9658 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009659 loge("isMultiSimSupportedInternal: no static configuration available");
9660 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009661 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009662 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009663 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009665 }
9666 // Check if support of multiple SIMs is restricted by carrier
9667 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009668 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009669 }
9670
Michele0ea7d782019-03-19 14:58:42 -07009671 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009672 }
9673
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009674 /**
9675 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009676 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9677 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9678 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009679 * @param numOfSims number of active sims we want to switch to
9680 */
9681 @Override
9682 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009683 if (numOfSims == 1) {
9684 enforceModifyPermission();
9685 } else {
9686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9687 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9688 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009689 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009690
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009691 try {
Michele30b57b22019-03-01 12:01:14 -08009692 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009693 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009694 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9695 return;
9696 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009697 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
9701 }
9702
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009703 @Override
9704 public boolean isApplicationOnUicc(int subId, int appType) {
9705 enforceReadPrivilegedPermission("isApplicationOnUicc");
9706 Phone phone = getPhone(subId);
9707 if (phone == null) {
9708 return false;
9709 }
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009712 UiccPort uiccPort = phone.getUiccPort();
9713 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009714 return false;
9715 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009716 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009717 if (uiccProfile == null) {
9718 return false;
9719 }
9720 if (TelephonyManager.APPTYPE_SIM <= appType
9721 && appType <= TelephonyManager.APPTYPE_ISIM) {
9722 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9723 }
9724 return false;
9725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009730 /**
chen xub4baa772019-04-03 10:23:41 -07009731 * Get whether making changes to modem configurations will trigger reboot.
9732 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009733 */
9734 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009735 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9736 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009737 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009738 mApp, subId, callingPackage, callingFeatureId,
9739 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009740 return false;
9741 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
Nathan Harold29f5f052019-02-15 13:41:57 -08009750 private void updateModemStateMetrics() {
9751 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9752 // TODO: check the state for each modem if the api is ready.
9753 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9754 }
9755
Pengquan Meng3889a572019-01-23 11:16:29 -08009756 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009757 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009758 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009759 // Verify that the callingPackage belongs to the calling UID
9760 mApp.getSystemService(AppOpsManager.class)
9761 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009762 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009763 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009764 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009765 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9766 if (slotInfos != null) {
9767 for (int i = 0; i < slotInfos.length; i++) {
9768 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9769 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9770 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9771 portInfo.getLogicalSlotIndex()));
9772 }
9773 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009774 }
9775 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009776 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009781
9782 /**
9783 * Get the IRadio HAL Version
9784 */
9785 @Override
9786 public int getRadioHalVersion() {
9787 Phone phone = getDefaultPhone();
9788 if (phone == null) return -1;
9789 HalVersion hv = phone.getHalVersion();
9790 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9791 return hv.major * 100 + hv.minor;
9792 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009793
9794 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009795 * Get the current calling package name.
9796 * @return the current calling package name
9797 */
9798 @Override
9799 public String getCurrentPackageName() {
9800 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9801 }
9802
9803 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009804 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9805 * corresponding network requests on a subId.
9806 *
9807 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009808 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009809 * 2) APN is un-metered for this subscription, or
9810 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009811 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009812 *
9813 * @return whether data is allowed for a apn type.
9814 *
9815 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009816 */
9817 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009818 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009819 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9820 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009821
9822 // Now that all security checks passes, perform the operation as ourselves.
9823 final long identity = Binder.clearCallingIdentity();
9824 try {
9825 Phone phone = getPhone(subId);
9826 if (phone == null) return false;
9827
Jack Yu27422a52022-03-21 10:38:05 -07009828 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009829 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009830 isMetered = phone.getDataNetworkController().getDataConfigManager()
9831 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9832 phone.getServiceState().getDataRoaming());
9833 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009834 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 }
9839
9840 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009841 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009842 enforceReadPrivilegedPermission("isApnMetered");
9843
9844 // Now that all security checks passes, perform the operation as ourselves.
9845 final long identity = Binder.clearCallingIdentity();
9846 try {
9847 Phone phone = getPhone(subId);
9848 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009849 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9850 DataUtils.apnTypeToNetworkCapability(apnType),
9851 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009856
9857 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009858 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9859 int subscriptionId, IBooleanConsumer resultCallback) {
9860 enforceModifyPermission();
9861 long token = Binder.clearCallingIdentity();
9862 try {
9863 Phone phone = getPhone(subscriptionId);
9864 if (phone == null) {
9865 try {
9866 if (resultCallback != null) {
9867 resultCallback.accept(false);
9868 }
9869 } catch (RemoteException e) {
9870 // ignore
9871 }
9872 return;
9873 }
9874 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9875 Pair.create(specifiers, (x) -> {
9876 try {
9877 if (resultCallback != null) {
9878 resultCallback.accept(x);
9879 }
9880 } catch (RemoteException e) {
9881 // ignore
9882 }
9883 });
9884 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9885 } finally {
9886 Binder.restoreCallingIdentity(token);
9887 }
9888 }
9889
9890 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009891 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9892 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009893 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009894 mApp, subId, "getSystemSelectionChannels");
9895 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9896 final long identity = Binder.clearCallingIdentity();
9897 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009898 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9899 if (result instanceof IllegalStateException) {
9900 throw (IllegalStateException) result;
9901 }
9902 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009903 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9904 return specifiers;
9905 } finally {
9906 Binder.restoreCallingIdentity(identity);
9907 }
9908 }
9909
9910 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009911 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009912 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009913 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009914 }
9915
9916 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009917 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9918 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009919 if (callingPackage == null) {
9920 callingPackage = getCurrentPackageName();
9921 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009922 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9923 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009924 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9925 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009926 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9927 }
9928 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9929 Intent intent = new Intent();
9930 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9931 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9932 // Bring up choose default SMS subscription dialog right now
9933 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9934 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9935 mApp.startActivity(intent);
9936 }
chen xud5ca2d52019-05-28 15:20:57 -07009937
9938 @Override
9939 public String getMmsUAProfUrl(int subId) {
9940 //TODO investigate if this API should require proper permission check in R b/133791609
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009943 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9944 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9945 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9946 return carrierUAProfUrl;
9947 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009948 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9949 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 @Override
9956 public String getMmsUserAgent(int subId) {
9957 //TODO investigate if this API should require proper permission check in R b/133791609
9958 final long identity = Binder.clearCallingIdentity();
9959 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009960 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9961 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9962 if (!TextUtils.isEmpty(carrierUserAgent)) {
9963 return carrierUserAgent;
9964 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009965 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9966 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009967 } finally {
9968 Binder.restoreCallingIdentity(identity);
9969 }
9970 }
Jack Yub07d4972019-05-28 16:12:25 -07009971
9972 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009973 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9974 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009975
Jack Yub07d4972019-05-28 16:12:25 -07009976 final long identity = Binder.clearCallingIdentity();
9977 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009978 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009979 if (phone == null) return false;
9980
Ling Maf188d502022-09-16 15:22:36 -07009981 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 }
9986
9987 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009988 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009989 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009990 enforceModifyPermission();
9991
changbettyd5c246e2019-12-24 15:40:37 +08009992 final long identity = Binder.clearCallingIdentity();
9993 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009994 Phone phone = getPhone(subscriptionId);
9995 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009996
Ling Maf188d502022-09-16 15:22:36 -07009997 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009998 } finally {
9999 Binder.restoreCallingIdentity(identity);
10000 }
10001 }
10002
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010003 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010004 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010005 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10006 * otherwise.
10007 */
10008 @Override
10009 public void setCepEnabled(boolean isCepEnabled) {
10010 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10011
10012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10015 for (Phone phone : PhoneFactory.getPhones()) {
10016 Phone defaultPhone = phone.getImsPhone();
10017 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10018 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10019 ImsPhoneCallTracker imsPhoneCallTracker =
10020 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10021 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10022 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10023 + imsPhone.getMsisdn());
10024 }
10025 }
10026 } finally {
10027 Binder.restoreCallingIdentity(identity);
10028 }
10029 }
allenwtsu46dcc572020-01-08 18:24:03 +080010030
10031 /**
10032 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10033 *
10034 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10035 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10036 * before being read.
10037 */
10038 @Override
10039 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10040 isCompressed) {
10041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10042 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010043 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10044 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10045 }
10046 if (!isImsAvailableOnDevice()) {
10047 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10048 "IMS not available on device.");
10049 }
10050
10051 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010052 try {
Hui Wang761a6682020-10-31 05:12:53 +000010053 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10054 } finally {
10055 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010056 }
10057 }
zoey chene02881a2019-12-30 16:11:23 +080010058
10059 @Override
10060 public boolean isIccLockEnabled(int subId) {
10061 enforceReadPrivilegedPermission("isIccLockEnabled");
10062
10063 // Now that all security checks passes, perform the operation as ourselves.
10064 final long identity = Binder.clearCallingIdentity();
10065 try {
10066 Phone phone = getPhone(subId);
10067 if (phone != null && phone.getIccCard() != null) {
10068 return phone.getIccCard().getIccLockEnabled();
10069 } else {
10070 return false;
10071 }
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 /**
10078 * Set the ICC pin lock enabled or disabled.
10079 *
10080 * @return an integer representing the status of IccLock enabled or disabled in the following
10081 * three cases:
10082 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10083 * successfully.
10084 * - Positive number and zero for remaining password attempts.
10085 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10086 *
10087 */
10088 @Override
10089 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10090 enforceModifyPermission();
10091
10092 Phone phone = getPhone(subId);
10093 if (phone == null) {
10094 return 0;
10095 }
10096 // Now that all security checks passes, perform the operation as ourselves.
10097 final long identity = Binder.clearCallingIdentity();
10098 try {
10099 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10100 new Pair<Boolean, String>(enabled, password), phone, null);
10101 return attemptsRemaining;
10102
10103 } catch (Exception e) {
10104 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10105 } finally {
10106 Binder.restoreCallingIdentity(identity);
10107 }
10108 return 0;
10109 }
10110
10111 /**
10112 * Change the ICC password used in ICC pin lock.
10113 *
10114 * @return an integer representing the status of IccLock changed in the following three cases:
10115 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10116 * - Positive number and zero for remaining password attempts.
10117 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10118 *
10119 */
10120 @Override
10121 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10122 enforceModifyPermission();
10123
10124 Phone phone = getPhone(subId);
10125 if (phone == null) {
10126 return 0;
10127 }
10128 // Now that all security checks passes, perform the operation as ourselves.
10129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10132 new Pair<String, String>(oldPassword, newPassword), phone, null);
10133 return attemptsRemaining;
10134
10135 } catch (Exception e) {
10136 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10137 } finally {
10138 Binder.restoreCallingIdentity(identity);
10139 }
10140 return 0;
10141 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010142
10143 /**
10144 * Request for receiving user activity notification
10145 */
10146 @Override
10147 public void requestUserActivityNotification() {
10148 if (!mNotifyUserActivity.get()
10149 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10150 mNotifyUserActivity.set(true);
10151 }
10152 }
10153
10154 /**
10155 * Called when userActivity is signalled in the power manager.
10156 * This is safe to call from any thread, with any window manager locks held or not.
10157 */
10158 @Override
10159 public void userActivity() {
10160 // ***************************************
10161 // * Inherited from PhoneWindowManager *
10162 // ***************************************
10163 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10164 // WITH ITS LOCKS HELD.
10165 //
10166 // This code must be VERY careful about the locks
10167 // it acquires.
10168 // In fact, the current code acquires way too many,
10169 // and probably has lurking deadlocks.
10170
10171 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10172 throw new SecurityException("Only the OS may call notifyUserActivity()");
10173 }
10174
10175 if (mNotifyUserActivity.getAndSet(false)) {
10176 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10177 USER_ACTIVITY_NOTIFICATION_DELAY);
10178 }
10179 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010180
10181 @Override
10182 public boolean canConnectTo5GInDsdsMode() {
10183 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10184 }
Jack Yud10cdd42020-09-28 20:28:01 -070010185
10186 @Override
10187 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10188 String callingFeatureId) {
10189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10190 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10191 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10192 }
10193
10194 Phone phone = getPhone(subId);
10195 if (phone == null) {
10196 throw new RuntimeException("phone is not available");
10197 }
10198 // Now that all security checks passes, perform the operation as ourselves.
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 return phone.getEquivalentHomePlmns();
10202 } finally {
10203 Binder.restoreCallingIdentity(identity);
10204 }
10205 }
Daniel Bright59e67312020-11-13 11:49:37 -080010206
10207 @Override
10208 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010209 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10210 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010211 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010212 if (radioInterfaceCapabilities == null) {
10213 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010214 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010215 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010216 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010217
Hui Wang641e81c2020-10-12 12:14:23 -070010218 @Override
10219 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10220 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010221 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10222 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10223 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10224 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10225 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010226 if (DBG) {
10227 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10228 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10229 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10230 }
10231
10232 if (!SubscriptionManager.isValidSubscriptionId(subId)
10233 || appType < TelephonyManager.APPTYPE_UNKNOWN
10234 || appType > TelephonyManager.APPTYPE_ISIM
10235 || nafUrl == null || securityProtocol == null || callback == null) {
10236 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10237 if (callback != null) {
10238 try {
10239 callback.onAuthenticationFailure(
10240 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10241 } catch (RemoteException exception) {
10242 log("Fail to notify onAuthenticationFailure due to " + exception);
10243 }
10244 return;
10245 }
10246 }
10247
10248 final long token = Binder.clearCallingIdentity();
10249 try {
10250 getGbaManager(subId).bootstrapAuthenticationRequest(
10251 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10252 forceBootStrapping, callback));
10253 } finally {
10254 Binder.restoreCallingIdentity(token);
10255 }
10256 }
10257
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010258 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010259 * Attempts to set the radio power state for all phones for thermal reason.
10260 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010261 * requested radio power state will actually be set. See {@link
10262 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10263 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010264 * @param enable {@code true} if trying to turn radio on.
10265 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10266 * false}.
10267 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010268 private boolean setRadioPowerForThermal(boolean enable) {
10269 boolean isPhoneAvailable = false;
10270 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10271 Phone phone = PhoneFactory.getPhone(i);
10272 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010273 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010274 isPhoneAvailable = true;
10275 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010277
10278 // return true if successfully informed the phone object about the thermal radio power
10279 // request.
10280 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010281 }
10282
10283 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010284 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010285 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10286 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10287 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10288 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10289 throw new IllegalArgumentException("modem does not support data throttling");
10290 }
10291
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010292 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10293 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010294 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010295 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10296 }
10297
Sarah Chinecc78c42022-03-31 21:16:48 -070010298 setDataEnabledForReason(
10299 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010300
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010301 if (isDataThrottlingSupported) {
10302 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010303 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010304 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10305 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10306 } else if (thermalMitigationResult
10307 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010308 log("Modem likely does not support data throttling on secondary carrier. Data " +
10309 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10310 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010311 }
10312 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010313 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010314
10315 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010316 }
10317
Jack Nudelman644b91a2021-03-12 14:09:48 -080010318 private static List<String> getThermalMitigationAllowlist(Context context) {
10319 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10320 for (String pckg : context.getResources()
10321 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10322 sThermalMitigationAllowlistedPackages.add(pckg);
10323 }
10324 }
10325
10326 return sThermalMitigationAllowlistedPackages;
10327 }
10328
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010329 private boolean isAnyPhoneInEmergencyState() {
10330 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10331 if (tm.isInEmergencyCall()) {
10332 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10333 return true;
10334 }
10335 for (Phone phone : PhoneFactory.getPhones()) {
10336 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10337 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10338 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10339 + phone.isInEcm());
10340 return true;
10341 }
10342 }
10343
10344 return false;
10345 }
10346
Jack Nudelman644b91a2021-03-12 14:09:48 -080010347 /**
10348 * Used by shell commands to add an authorized package name for thermal mitigation.
10349 * @param packageName name of package to be allowlisted
10350 * @param context
10351 */
10352 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10353 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10354 sThermalMitigationAllowlistedPackages.add(packageName);
10355 }
10356
10357 /**
10358 * Used by shell commands to remove an authorized package name for thermal mitigation.
10359 * @param packageName name of package to remove from allowlist
10360 * @param context
10361 */
10362 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10363 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10364 sThermalMitigationAllowlistedPackages.remove(packageName);
10365 }
10366
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010367 /**
10368 * Thermal mitigation request to control functionalities at modem.
10369 *
10370 * @param subId the id of the subscription.
10371 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010372 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010373 *
10374 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10375 */
10376 @Override
10377 @ThermalMitigationResult
10378 public int sendThermalMitigationRequest(
10379 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010380 ThermalMitigationRequest thermalMitigationRequest,
10381 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010382 enforceModifyPermission();
10383
Jack Nudelman644b91a2021-03-12 14:09:48 -080010384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10385 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10386 .contains(callingPackage)) {
10387 throw new SecurityException("Calling package must be configured in the device config. "
10388 + "calling package: " + callingPackage);
10389 }
10390
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010391 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10392 final long identity = Binder.clearCallingIdentity();
10393
10394 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10395 try {
10396 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10397 switch (thermalMitigationAction) {
10398 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10399 thermalMitigationResult =
10400 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010401 thermalMitigationRequest.getDataThrottlingRequest(),
10402 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 break;
10404 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10405 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10406 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10407 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10408 }
10409
10410 // Ensure that radio is on. If not able to power on due to phone being
10411 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010412 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010413 thermalMitigationResult =
10414 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10415 break;
10416 }
10417
10418 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010419 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010420 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10421 break;
10422 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10423 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10424 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10425 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10426 }
10427
10428 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10429 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010430 Phone phone = getPhone(subId);
10431 if (phone == null) {
10432 thermalMitigationResult =
10433 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10434 break;
10435 }
10436
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010437 TelephonyConnectionService service =
10438 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010439 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010440 Log.e(LOG_TAG, "An emergency call is pending");
10441 thermalMitigationResult =
10442 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10443 break;
10444 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010445 thermalMitigationResult =
10446 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10447 break;
10448 }
10449 } else {
10450 thermalMitigationResult =
10451 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10452 break;
10453 }
10454
10455 // Turn radio off. If not able to power off due to phone being unavailable,
10456 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010457 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010458 thermalMitigationResult =
10459 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10460 break;
10461 }
10462 thermalMitigationResult =
10463 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10464 break;
10465 default:
10466 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10467 + "not exist. Requested action: " + thermalMitigationAction);
10468 }
10469 } catch (IllegalArgumentException e) {
10470 throw e;
10471 } catch (Exception e) {
10472 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10473 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477
10478 if (DBG) {
10479 log("thermalMitigationRequest returning with thermalMitigationResult: "
10480 + thermalMitigationResult);
10481 }
10482
10483 return thermalMitigationResult;
10484 }
Hui Wang641e81c2020-10-12 12:14:23 -070010485
10486 /**
10487 * Set the GbaService Package Name that Telephony will bind to.
10488 *
10489 * @param subId The sim that the GbaService is associated with.
10490 * @param packageName The name of the package to be replaced with.
10491 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10492 */
10493 @Override
10494 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10495 enforceModifyPermission();
10496
10497 final long identity = Binder.clearCallingIdentity();
10498 try {
10499 return getGbaManager(subId).overrideServicePackage(packageName);
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
10505 /**
10506 * Return the package name of the currently bound GbaService.
10507 *
10508 * @param subId The sim that the GbaService is associated with.
10509 * @return the package name of the GbaService configuration, null if GBA is not supported.
10510 */
10511 @Override
10512 public String getBoundGbaService(int subId) {
10513 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10514
10515 final long identity = Binder.clearCallingIdentity();
10516 try {
10517 return getGbaManager(subId).getServicePackage();
10518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 /**
10524 * Set the release time for telephony to unbind GbaService.
10525 *
10526 * @param subId The sim that the GbaService is associated with.
10527 * @param interval The release time to unbind GbaService by millisecond.
10528 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10529 */
10530 @Override
10531 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10532 enforceModifyPermission();
10533
10534 final long identity = Binder.clearCallingIdentity();
10535 try {
10536 return getGbaManager(subId).overrideReleaseTime(interval);
10537 } finally {
10538 Binder.restoreCallingIdentity(identity);
10539 }
10540 }
10541
10542 /**
10543 * Return the release time for telephony to unbind GbaService.
10544 *
10545 * @param subId The sim that the GbaService is associated with.
10546 * @return The release time to unbind GbaService by millisecond.
10547 */
10548 @Override
10549 public int getGbaReleaseTime(int subId) {
10550 enforceReadPrivilegedPermission("getGbaReleaseTime");
10551
10552 final long identity = Binder.clearCallingIdentity();
10553 try {
10554 return getGbaManager(subId).getReleaseTime();
10555 } finally {
10556 Binder.restoreCallingIdentity(identity);
10557 }
10558 }
10559
10560 private GbaManager getGbaManager(int subId) {
10561 GbaManager instance = GbaManager.getInstance(subId);
10562 if (instance == null) {
10563 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10564 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10565 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10566 }
10567 return instance;
10568 }
Hui Wang761a6682020-10-31 05:12:53 +000010569
10570 /**
10571 * indicate whether the device and the carrier can support
10572 * RCS VoLTE single registration.
10573 */
10574 @Override
10575 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010576 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10577 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10578 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10579 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010580
10581 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10582 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10583 }
10584
10585 final long identity = Binder.clearCallingIdentity();
10586 try {
10587 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10588 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010589 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10590 if (isCapable != null) {
10591 return isCapable;
10592 }
Hui Wang761a6682020-10-31 05:12:53 +000010593 }
Hui Wang67af90e2021-06-04 16:57:15 -070010594 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10595 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
10600
10601 /**
10602 * Register RCS provisioning callback.
10603 */
10604 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010605 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010606 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010607 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010608 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010609 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10610 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010611
10612 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10613 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10614 }
10615 if (!isImsAvailableOnDevice()) {
10616 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10617 "IMS not available on device.");
10618 }
10619
10620 final long identity = Binder.clearCallingIdentity();
10621 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010622 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010623 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010624 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10625 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010626 }
Hui Wang761a6682020-10-31 05:12:53 +000010627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
10632 /**
10633 * Unregister RCS provisioning callback.
10634 */
10635 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010636 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010637 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010638 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010639 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010640 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10641 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010642
10643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10644 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10645 }
10646 if (!isImsAvailableOnDevice()) {
10647 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10648 "IMS not available on device.");
10649 }
10650
10651 final long identity = Binder.clearCallingIdentity();
10652 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010653 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010654 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
10660 /**
10661 * trigger RCS reconfiguration.
10662 */
10663 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010664 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10665 "triggerRcsReconfiguration",
10666 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010667
10668 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10669 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10670 }
10671 if (!isImsAvailableOnDevice()) {
10672 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10673 "IMS not available on device.");
10674 }
10675
10676 final long identity = Binder.clearCallingIdentity();
10677 try {
10678 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
10683
10684 /**
10685 * Provide the client configuration parameters of the RCS application.
10686 */
10687 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010688 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10689 "setRcsClientConfiguration",
10690 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010691
10692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10694 }
10695 if (!isImsAvailableOnDevice()) {
10696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10697 "IMS not available on device.");
10698 }
10699
10700 final long identity = Binder.clearCallingIdentity();
10701
10702 try {
10703 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10704 if (configBinder == null) {
10705 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010706 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10707 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010708 } else {
10709 configBinder.setRcsClientConfiguration(rcc);
10710 }
joonhunshin3e154242021-09-17 06:33:39 +000010711
10712 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10713 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010714 } catch (RemoteException e) {
10715 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010716 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10717 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010718 } finally {
10719 Binder.restoreCallingIdentity(identity);
10720 }
10721 }
10722
10723 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010724 * Enables or disables the test mode for RCS VoLTE single registration.
10725 */
10726 @Override
10727 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10728 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10729 "setRcsSingleRegistrationTestModeEnabled");
10730
10731 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10732 }
10733
10734 /**
10735 * Gets the test mode for RCS VoLTE single registration.
10736 */
10737 @Override
10738 public boolean getRcsSingleRegistrationTestModeEnabled() {
10739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10740 "getRcsSingleRegistrationTestModeEnabled");
10741
10742 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10743 }
10744
10745 /**
Hui Wang761a6682020-10-31 05:12:53 +000010746 * Overrides the config of RCS VoLTE single registration enabled for the device.
10747 */
10748 @Override
10749 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10751 "setDeviceSingleRegistrationEnabledOverride");
10752 enforceModifyPermission();
10753
10754 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10755 : Boolean.parseBoolean(enabledStr);
10756 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010757 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010758 }
10759
10760 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010761 * Sends a device to device communication message. Only usable via shell.
10762 * @param message message to send.
10763 * @param value message value.
10764 */
10765 @Override
10766 public void sendDeviceToDeviceMessage(int message, int value) {
10767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010768 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010769 enforceModifyPermission();
10770
10771 final long identity = Binder.clearCallingIdentity();
10772 try {
10773 TelephonyConnectionService service =
10774 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10775 if (service == null) {
10776 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10777 return;
10778 }
10779 service.sendTestDeviceToDeviceMessage(message, value);
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
10784
Tyler Gunnbabbda02021-02-10 11:05:02 -080010785 /**
10786 * Sets the specified device to device transport active.
10787 * @param transport The transport to set active.
10788 */
10789 @Override
10790 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10792 "setActiveDeviceToDeviceTransport");
10793 enforceModifyPermission();
10794
10795 final long identity = Binder.clearCallingIdentity();
10796 try {
10797 TelephonyConnectionService service =
10798 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10799 if (service == null) {
10800 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10801 return;
10802 }
10803 service.setActiveDeviceToDeviceTransport(transport);
10804 } finally {
10805 Binder.restoreCallingIdentity(identity);
10806 }
10807 }
Tyler Gunn92479152021-01-20 16:30:10 -080010808
Tyler Gunnd4339262021-05-03 14:46:49 -070010809 @Override
10810 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10812 "setDeviceToDeviceForceEnabled");
10813
10814 final long identity = Binder.clearCallingIdentity();
10815 try {
10816 Arrays.stream(PhoneFactory.getPhones()).forEach(
10817 p -> {
10818 Phone thePhone = p.getImsPhone();
10819 if (thePhone != null && thePhone instanceof ImsPhone) {
10820 ImsPhone imsPhone = (ImsPhone) thePhone;
10821 CallTracker tracker = imsPhone.getCallTracker();
10822 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10823 ImsPhoneCallTracker imsPhoneCallTracker =
10824 (ImsPhoneCallTracker) tracker;
10825 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10826 }
10827 }
10828 }
10829 );
10830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
10834
Tyler Gunn92479152021-01-20 16:30:10 -080010835 /**
Hui Wang761a6682020-10-31 05:12:53 +000010836 * Gets the config of RCS VoLTE single registration enabled for the device.
10837 */
10838 @Override
10839 public boolean getDeviceSingleRegistrationEnabled() {
10840 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10841 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10842 }
10843
10844 /**
10845 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10846 */
10847 @Override
10848 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10849 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10850 "setCarrierSingleRegistrationEnabledOverride");
10851 enforceModifyPermission();
10852
10853 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10854 : Boolean.parseBoolean(enabledStr);
10855 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10856 subId, enabled);
10857 }
10858
10859 /**
10860 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10861 */
10862 @Override
10863 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10864 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10865 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10866 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010867
10868 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010869 * Overrides the ims feature validation result
10870 */
10871 @Override
10872 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10874 "setImsFeatureValidationOverride");
10875
10876 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10877 : Boolean.parseBoolean(enabledStr);
10878 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10879 subId, enabled);
10880 }
10881
10882 /**
10883 * Gets the ims feature validation override value
10884 */
10885 @Override
10886 public boolean getImsFeatureValidationOverride(int subId) {
10887 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10888 "getImsFeatureValidationOverride");
10889 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10890 }
10891
10892 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010893 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10894 * their mobile plan.
10895 */
10896 @Override
10897 public String getMobileProvisioningUrl() {
10898 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10899 final long identity = Binder.clearCallingIdentity();
10900 try {
10901 return getDefaultPhone().getMobileProvisioningUrl();
10902 } finally {
10903 Binder.restoreCallingIdentity(identity);
10904 }
10905 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010906
James.cf Linbcdf8b32021-01-14 16:44:13 +080010907 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010908 * Get the EAB contact from the EAB database.
10909 */
10910 @Override
10911 public String getContactFromEab(String contact) {
10912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10913 enforceModifyPermission();
10914 final long identity = Binder.clearCallingIdentity();
10915 try {
10916 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
10921
10922 /**
Calvin Pana1434322021-07-01 19:27:01 +080010923 * Get the EAB capability from the EAB database.
10924 */
10925 @Override
10926 public String getCapabilityFromEab(String contact) {
10927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10928 enforceModifyPermission();
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
10936
10937 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010938 * Remove the EAB contacts from the EAB database.
10939 */
10940 @Override
10941 public int removeContactFromEab(int subId, String contacts) {
10942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10943 enforceModifyPermission();
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10947 } finally {
10948 Binder.restoreCallingIdentity(identity);
10949 }
10950 }
10951
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010952 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010953 public boolean getDeviceUceEnabled() {
10954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10955 final long identity = Binder.clearCallingIdentity();
10956 try {
10957 return mApp.getDeviceUceEnabled();
10958 } finally {
10959 Binder.restoreCallingIdentity(identity);
10960 }
10961 }
10962
10963 @Override
10964 public void setDeviceUceEnabled(boolean isEnabled) {
10965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10966 final long identity = Binder.clearCallingIdentity();
10967 try {
10968 mApp.setDeviceUceEnabled(isEnabled);
10969 } finally {
10970 Binder.restoreCallingIdentity(identity);
10971 }
10972 }
10973
Brad Ebinger14d467f2021-02-12 06:18:28 +000010974 /**
10975 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10976 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10977 */
10978 // Used for SHELL command only right now.
10979 @Override
10980 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10981 List<String> featureTags) {
10982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10983 "addUceRegistrationOverrideShell");
10984 final long identity = Binder.clearCallingIdentity();
10985 try {
10986 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10987 new ArraySet<>(featureTags));
10988 } catch (ImsException e) {
10989 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10990 } finally {
10991 Binder.restoreCallingIdentity(identity);
10992 }
10993 }
10994
10995 /**
10996 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10997 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10998 */
10999 // Used for SHELL command only right now.
11000 @Override
11001 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11002 List<String> featureTags) {
11003 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11004 "removeUceRegistrationOverrideShell");
11005 final long identity = Binder.clearCallingIdentity();
11006 try {
11007 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11008 new ArraySet<>(featureTags));
11009 } catch (ImsException e) {
11010 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11011 } finally {
11012 Binder.restoreCallingIdentity(identity);
11013 }
11014 }
11015
11016 /**
11017 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11018 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11019 */
11020 // Used for SHELL command only right now.
11021 @Override
11022 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11024 "clearUceRegistrationOverrideShell");
11025 final long identity = Binder.clearCallingIdentity();
11026 try {
11027 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11028 } catch (ImsException e) {
11029 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11030 } finally {
11031 Binder.restoreCallingIdentity(identity);
11032 }
11033 }
11034
11035 /**
11036 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11037 */
11038 // Used for SHELL command only right now.
11039 @Override
11040 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11042 "getLatestRcsContactUceCapabilityShell");
11043 final long identity = Binder.clearCallingIdentity();
11044 try {
11045 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11046 } catch (ImsException e) {
11047 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11048 } finally {
11049 Binder.restoreCallingIdentity(identity);
11050 }
11051 }
11052
11053 /**
11054 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11055 * device does not have an active PUBLISH.
11056 */
11057 // Used for SHELL command only right now.
11058 @Override
11059 public String getLastUcePidfXmlShell(int subId) {
11060 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11061 final long identity = Binder.clearCallingIdentity();
11062 try {
11063 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11064 } catch (ImsException e) {
11065 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11066 } finally {
11067 Binder.restoreCallingIdentity(identity);
11068 }
11069 }
11070
James.cf Line8713a42021-04-29 16:04:26 +080011071 /**
11072 * Remove UCE requests cannot be sent to the network status.
11073 */
11074 // Used for SHELL command only right now.
11075 @Override
11076 public boolean removeUceRequestDisallowedStatus(int subId) {
11077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11078 final long identity = Binder.clearCallingIdentity();
11079 try {
11080 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11081 } catch (ImsException e) {
11082 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11083 } finally {
11084 Binder.restoreCallingIdentity(identity);
11085 }
11086 }
11087
James.cf Lin18bb9002021-05-25 01:37:38 +080011088 /**
11089 * Remove UCE requests cannot be sent to the network status.
11090 */
11091 // Used for SHELL command only.
11092 @Override
11093 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
11097 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11098 } catch (ImsException e) {
11099 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11100 } finally {
11101 Binder.restoreCallingIdentity(identity);
11102 }
11103 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011104
James.cf Lin4b784aa2021-01-31 03:25:15 +080011105 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011106 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11107 String callingPackage) {
11108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11109 mApp, subId, "setSignalStrengthUpdateRequest");
11110
11111 final int callingUid = Binder.getCallingUid();
11112 // Verify that tha callingPackage belongs to the calling UID
11113 mApp.getSystemService(AppOpsManager.class)
11114 .checkPackage(callingUid, callingPackage);
11115
Rambo Wang3607f502021-02-01 21:51:40 -080011116 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011117
11118 final long identity = Binder.clearCallingIdentity();
11119 try {
11120 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11121 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11122
11123 if (result instanceof IllegalStateException) {
11124 throw (IllegalStateException) result;
11125 }
11126 } finally {
11127 Binder.restoreCallingIdentity(identity);
11128 }
11129 }
11130
11131 @Override
11132 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11133 String callingPackage) {
11134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11135 mApp, subId, "clearSignalStrengthUpdateRequest");
11136
11137 final int callingUid = Binder.getCallingUid();
11138 // Verify that tha callingPackage belongs to the calling UID
11139 mApp.getSystemService(AppOpsManager.class)
11140 .checkPackage(callingUid, callingPackage);
11141
11142 final long identity = Binder.clearCallingIdentity();
11143 try {
11144 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11145 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11146
11147 if (result instanceof IllegalStateException) {
11148 throw (IllegalStateException) result;
11149 }
11150 } finally {
11151 Binder.restoreCallingIdentity(identity);
11152 }
11153 }
11154
Rambo Wang3607f502021-02-01 21:51:40 -080011155 private static void validateSignalStrengthUpdateRequest(Context context,
11156 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011157 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11158 // phone/system process do not have further restriction on request
11159 return;
11160 }
11161
11162 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011163 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011164 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011165 context.enforceCallingOrSelfPermission(
11166 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11167 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011168 }
11169
11170 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11171 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11172 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11173 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11174 || info.isEnabled()) {
11175 throw new IllegalArgumentException(
11176 "Only system can set hide fields in SignalThresholdInfo");
11177 }
11178
11179 // Thresholds length for each RAN need in range. This has been validated in
11180 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11181 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11182 final int[] thresholds = info.getThresholds();
11183 Objects.requireNonNull(thresholds);
11184 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11185 || thresholds.length
11186 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11187 throw new IllegalArgumentException(
11188 "thresholds length is out of range: " + thresholds.length);
11189 }
11190 }
11191 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011192
11193 /**
11194 * Gets the current phone capability.
11195 *
11196 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11197 * @return the PhoneCapability which describes the data connection capability of modem.
11198 * It's used to evaluate possible phone config change, for example from single
11199 * SIM device to multi-SIM device.
11200 */
11201 @Override
11202 public PhoneCapability getPhoneCapability() {
11203 enforceReadPrivilegedPermission("getPhoneCapability");
11204 final long identity = Binder.clearCallingIdentity();
11205 try {
11206 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11207 } finally {
11208 Binder.restoreCallingIdentity(identity);
11209 }
11210 }
Michele Berionne5e411512020-11-13 02:36:59 +000011211
11212 /**
11213 * Prepare TelephonyManager for an unattended reboot. The reboot is
11214 * required to be done shortly after the API is invoked.
11215 */
11216 @Override
11217 @TelephonyManager.PrepareUnattendedRebootResult
11218 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011219 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011220 enforceRebootPermission();
11221
11222 final long identity = Binder.clearCallingIdentity();
11223 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011224 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011225 } finally {
11226 Binder.restoreCallingIdentity(identity);
11227 }
11228 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011229
11230 /**
11231 * Request to get the current slicing configuration including URSP rules and
11232 * NSSAIs (configured, allowed and rejected).
11233 *
11234 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11235 */
11236 @Override
11237 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011238 TelephonyPermissions
11239 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11240 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011241
11242 final long identity = Binder.clearCallingIdentity();
11243 try {
11244 Phone phone = getDefaultPhone();
11245 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11246 } finally {
11247 Binder.restoreCallingIdentity(identity);
11248 }
11249 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011250
11251 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011252 * Check whether the given premium capability is available for purchase from the carrier.
11253 *
11254 * @param capability The premium capability to check.
11255 * @param subId The subId to check the premium capability for.
11256 *
11257 * @return Whether the given premium capability is available to purchase.
11258 */
11259 @Override
11260 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11261 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11262 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11263 log("Premium capability "
11264 + TelephonyManager.convertPremiumCapabilityToString(capability)
11265 + " is not available for purchase due to missing permissions.");
11266 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11267 + "permission READ_BASIC_PHONE_STATE.");
11268 }
11269
11270 Phone phone = getPhone(subId);
11271 final long identity = Binder.clearCallingIdentity();
11272 try {
11273 return SliceStore.getInstance(phone)
11274 .isPremiumCapabilityAvailableForPurchase(capability);
11275 } finally {
11276 Binder.restoreCallingIdentity(identity);
11277 }
11278 }
11279
11280 /**
11281 * Purchase the given premium capability from the carrier.
11282 *
11283 * @param capability The premium capability to purchase.
11284 * @param callback The result of the purchase request.
11285 * @param subId The subId to purchase the premium capability for.
11286 */
11287 @Override
11288 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11289 log("purchasePremiumCapability: capability="
11290 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11291 + getCurrentPackageName());
11292
11293 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11294 mApp, "purchasePremiumCapability")) {
11295 log("purchasePremiumCapability "
11296 + TelephonyManager.convertPremiumCapabilityToString(capability)
11297 + " failed due to missing permissions.");
11298 throw new SecurityException("purchasePremiumCapability requires permission "
11299 + "READ_BASIC_PHONE_STATE.");
11300 }
11301
11302 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011303 String appName;
11304 try {
11305 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11306 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11307 } catch (PackageManager.NameNotFoundException e) {
11308 appName = "An application";
11309 }
11310 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11311 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011312 }
11313
11314 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011315 * Register an IMS connection state callback
11316 */
11317 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011318 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11319 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011320 if (feature == ImsFeature.FEATURE_MMTEL) {
11321 // ImsMmTelManager
11322 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11323 TelephonyPermissions
11324 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11325 mApp, subId, "registerImsStateCallback");
11326 } else if (feature == ImsFeature.FEATURE_RCS) {
11327 // ImsRcsManager or SipDelegateManager
11328 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11329 Binder.getCallingUid(), "registerImsStateCallback",
11330 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11331 Manifest.permission.READ_PRECISE_PHONE_STATE,
11332 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11333 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11334 }
11335
11336 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11338 "IMS not available on device.");
11339 }
11340
11341 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11342 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11343 }
11344
11345 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11346 if (controller == null) {
11347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11348 "IMS not available on device.");
11349 }
11350
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011351 if (callingPackage == null) {
11352 callingPackage = getCurrentPackageName();
11353 }
11354
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011355 final long token = Binder.clearCallingIdentity();
11356 try {
11357 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011358 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011359 } catch (ImsException e) {
11360 throw new ServiceSpecificException(e.getCode());
11361 } finally {
11362 Binder.restoreCallingIdentity(token);
11363 }
11364 }
11365
11366 /**
11367 * Unregister an IMS connection state callback
11368 */
11369 @Override
11370 public void unregisterImsStateCallback(IImsStateCallback cb) {
11371 final long token = Binder.clearCallingIdentity();
11372 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11373 if (controller == null) {
11374 return;
11375 }
11376 try {
11377 controller.unregisterImsStateCallback(cb);
11378 } finally {
11379 Binder.restoreCallingIdentity(token);
11380 }
11381 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011382
11383 /**
11384 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11385 *
11386 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11387 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11388 * SecurityException.
11389 * If there is current registered network this value will be same as the registered cell
11390 * identity. If the device goes out of service the previous cell identity is cached and
11391 * will be returned. If the cache age of the Cell identity is more than 24 hours
11392 * it will be cleared and null will be returned.
11393 *
11394 */
11395 @Override
11396 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11397 String callingFeatureId) {
11398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11399 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11400 LocationAccessPolicy.checkLocationPermission(mApp,
11401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11402 .setCallingPackage(callingPackage)
11403 .setCallingFeatureId(callingFeatureId)
11404 .setCallingPid(Binder.getCallingPid())
11405 .setCallingUid(Binder.getCallingUid())
11406 .setMethod("getLastKnownCellIdentity")
11407 .setLogAsInfo(true)
11408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11409 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11410 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11411 .build());
11412
11413 boolean hasFinePermission =
11414 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11415 if (!hasFinePermission
11416 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11417 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011418 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011419 }
11420
11421 final long identity = Binder.clearCallingIdentity();
11422 try {
11423 Phone phone = getPhone(subId);
11424 if (phone == null) return null;
11425 ServiceStateTracker sst = phone.getServiceStateTracker();
11426 if (sst == null) return null;
11427 return sst.getLastKnownCellIdentity();
11428 } finally {
11429 Binder.restoreCallingIdentity(identity);
11430 }
11431 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011432
jimsun3b9ccac2021-10-26 15:01:23 +080011433 /**
11434 * Sets the modem service class Name that Telephony will bind to.
11435 *
11436 * @param serviceName The class name of the modem service.
11437 * @return true if the operation is succeed, otherwise false.
11438 */
11439 public boolean setModemService(String serviceName) {
11440 Log.d(LOG_TAG, "setModemService - " + serviceName);
11441 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11443 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11444 "setModemService");
11445 return mPhoneConfigurationManager.setModemService(serviceName);
11446 }
11447
11448 /**
11449 * Return the class name of the currently bounded modem service.
11450 *
11451 * @return the class name of the modem service.
11452 */
11453 public String getModemService() {
11454 String result;
11455 Log.d(LOG_TAG, "getModemService");
11456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11457 TelephonyPermissions
11458 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11459 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11460 "getModemService");
11461 result = mPhoneConfigurationManager.getModemService();
11462 Log.d(LOG_TAG, "result = " + result);
11463 return result;
11464 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011465
11466 @Override
11467 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11468 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11469 mApp.enforceCallingOrSelfPermission(
11470 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11472
11473 final long identity = Binder.clearCallingIdentity();
11474 try {
11475 Phone phone = getPhone(subId);
11476 if (phone == null) return;
11477 phone.setVoiceServiceStateOverride(hasService);
11478 } finally {
11479 Binder.restoreCallingIdentity(identity);
11480 }
11481 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011482
11483 /**
11484 * set removable eSIM as default eUICC.
11485 *
11486 * @hide
11487 */
11488 @Override
11489 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11490 enforceModifyPermission();
11491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11492
11493 final long identity = Binder.clearCallingIdentity();
11494 try {
11495 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11496 } finally {
11497 Binder.restoreCallingIdentity(identity);
11498 }
11499 }
11500
11501 /**
11502 * Returns whether the removable eSIM is default eUICC or not.
11503 *
11504 * @hide
11505 */
11506 @Override
11507 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11508 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11510
11511 final long identity = Binder.clearCallingIdentity();
11512 try {
11513 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11514 } finally {
11515 Binder.restoreCallingIdentity(identity);
11516 }
11517 }
11518
11519
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011520}