blob: 27d1de39ed5d88b28efde2514dcde6218360b0e5 [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 Chin46355ba2022-11-01 23:51:16 -0700214import com.android.phone.slice.SlicePurchaseController;
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;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000388 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389
Peter Wangdafb9ac2020-01-15 14:13:38 -0800390 /** User Activity */
391 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800392 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
393
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700394 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
395
Derek Tan97ebb422014-09-05 16:55:38 -0700396 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
397 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800398 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800399 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700400
Michelecea4cf22018-12-21 15:00:11 -0800401 // String to store multi SIM allowed
402 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
403
Derek Tan740e1672017-06-27 14:56:27 -0700404 // The AID of ISD-R.
405 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
406
yinxub1bed742017-04-17 11:45:04 -0700407 private NetworkScanRequestTracker mNetworkScanRequestTracker;
408
David Kelly5e06a7f2018-03-12 14:10:59 +0000409 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
410 private static final int MANUFACTURER_CODE_LENGTH = 8;
411
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800412 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800413 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800414
Sarah Chin2ec39f62022-08-31 17:03:26 -0700415 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
416 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
417
Derek Tan89e89d42014-07-08 17:00:10 -0700418 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700419 * Experiment flag to enable erase modem config on reset network, default value is false
420 */
421 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
422 "reset_network_erase_modem_config_enabled";
423
Rambo Wang0f050d82021-02-12 11:43:36 -0800424 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800425
sandeepjsb6c87872021-09-27 15:34:44 +0000426 /**
427 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
428 * one ICCID active at the same time.
429 * Apps should use below API signatures if targeting SDK is T and beyond.
430 *
431 * @hide
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800436
Naina Nallurid63128d2019-09-17 14:10:30 -0700437 /**
Chen Xu540470b2021-12-14 17:15:47 -0800438 * Apps targeting on Android T and beyond will get exception whenever icc close channel
439 * operation fails.
440 */
441 @ChangeId
442 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
443 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
444
445 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 * A request object to use for transmitting data to an ICC.
447 */
448 private static final class IccAPDUArgument {
449 public int channel, cla, command, p1, p2, p3;
450 public String data;
451
452 public IccAPDUArgument(int channel, int cla, int command,
453 int p1, int p2, int p3, String data) {
454 this.channel = channel;
455 this.cla = cla;
456 this.command = command;
457 this.p1 = p1;
458 this.p2 = p2;
459 this.p3 = p3;
460 this.data = data;
461 }
462 }
463
464 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700465 * A request object to use for transmitting data to an ICC.
466 */
467 private static final class ManualNetworkSelectionArgument {
468 public OperatorInfo operatorInfo;
469 public boolean persistSelection;
470
471 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
472 this.operatorInfo = operatorInfo;
473 this.persistSelection = persistSelection;
474 }
475 }
476
Sarah Chin71b3a852022-09-28 15:54:19 -0700477 private static final class PurchasePremiumCapabilityArgument {
478 public @TelephonyManager.PremiumCapability int capability;
479 public @NonNull String appName;
480 public @NonNull IIntegerConsumer callback;
481
482 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
483 @NonNull String appName, @NonNull IIntegerConsumer callback) {
484 this.capability = capability;
485 this.appName = appName;
486 this.callback = callback;
487 }
488 }
489
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700490 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
492 * request after sending. The main thread will notify the request when it is complete.
493 */
494 private static final class MainThreadRequest {
495 /** The argument to use for the request */
496 public Object argument;
497 /** The result of the request that is run on the main thread */
498 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 // The subscriber id that this request applies to. Defaults to
500 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
501 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502
Nathan Harold92bed182018-10-12 18:16:49 -0700503 // In cases where subId is unavailable, the caller needs to specify the phone.
504 public Phone phone;
505
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 public WorkSource workSource;
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 public MainThreadRequest(Object argument) {
509 this.argument = argument;
510 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800511
Nathan Harold92bed182018-10-12 18:16:49 -0700512 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
513 this.argument = argument;
514 if (phone != null) {
515 this.phone = phone;
516 }
517 this.workSource = workSource;
518 }
519
vagdeviaf9a5b92018-08-15 16:01:53 -0700520 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800521 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800522 if (subId != null) {
523 this.subId = subId;
524 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700525 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 }
528
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800529 private static final class IncomingThirdPartyCallArgs {
530 public final ComponentName component;
531 public final String callId;
532 public final String callerDisplayName;
533
534 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
535 String callerDisplayName) {
536 this.component = component;
537 this.callId = callId;
538 this.callerDisplayName = callerDisplayName;
539 }
540 }
541
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 /**
543 * A handler that processes messages on the main thread in the phone process. Since many
544 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
545 * inbound binder threads to the main thread in the phone process. The Binder thread
546 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
547 * on, which will be notified when the operation completes and will contain the result of the
548 * request.
549 *
550 * <p>If a MainThreadRequest object is provided in the msg.obj field,
551 * note that request.result must be set to something non-null for the calling thread to
552 * unblock.
553 */
554 private final class MainThreadHandler extends Handler {
555 @Override
556 public void handleMessage(Message msg) {
557 MainThreadRequest request;
558 Message onCompleted;
559 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000560 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800562 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563
564 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 case CMD_HANDLE_USSD_REQUEST: {
566 request = (MainThreadRequest) msg.obj;
567 final Phone phone = getPhoneFromRequest(request);
568 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800569 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700571
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 if (!isUssdApiAllowed(request.subId)) {
573 // Carrier does not support use of this API, return failure.
574 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
575 UssdResponse response = new UssdResponse(ussdRequest, null);
576 Bundle returnData = new Bundle();
577 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
578 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700579
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 request.result = true;
581 notifyRequester(request);
582 return;
583 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700584
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 try {
586 request.result = phone != null
587 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
588 } catch (CallStateException cse) {
589 request.result = false;
590 }
591 // Wake up the requesting thread
592 notifyRequester(request);
593 break;
pkanwar32d516d2016-10-14 19:37:38 -0700594 }
595
Yorke Lee716f67e2015-06-17 15:39:16 -0700596 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700598 final Phone phone = getPhoneFromRequest(request);
599 request.result = phone != null ?
600 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
601 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000610 uiccPort = getUiccPortFromRequest(request);
611 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800613 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800617 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000618 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800619 iccArgument.channel, iccArgument.cla, iccArgument.command,
620 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
621 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 ar = (AsyncResult) msg.obj;
627 request = (MainThreadRequest) ar.userObj;
628 if (ar.exception == null && ar.result != null) {
629 request.result = ar.result;
630 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 if (ar.result == null) {
633 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800634 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800636 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
638 loge("iccTransmitApduLogicalChannel: Unknown exception");
639 }
640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 break;
643
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
646 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000647 uiccPort = getUiccPortFromRequest(request);
648 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800650 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 } else {
653 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800654 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000655 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800656 iccArgument.cla, iccArgument.command, iccArgument.p1,
657 iccArgument.p2,
658 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 break;
661
662 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 if (ar.result == null) {
670 loge("iccTransmitApduBasicChannel: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("iccTransmitApduBasicChannel: CommandException: " +
673 ar.exception);
674 } else {
675 loge("iccTransmitApduBasicChannel: Unknown exception");
676 }
677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 break;
680
681 case CMD_EXCHANGE_SIM_IO:
682 request = (MainThreadRequest) msg.obj;
683 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort = getUiccPortFromRequest(request);
685 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 } else {
690 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
691 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
694 iccArgument.data, onCompleted);
695 }
696 break;
697
698 case EVENT_EXCHANGE_SIM_IO_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
703 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
Derek Tan4d5e5c12014-02-04 11:54:58 -0800709 case CMD_SEND_ENVELOPE:
710 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
712 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800718 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 break;
721
722 case EVENT_SEND_ENVELOPE_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700725 if (ar.exception == null && ar.result != null) {
726 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800727 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800728 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700729 if (ar.result == null) {
730 loge("sendEnvelopeWithStatus: Empty response");
731 } else if (ar.exception instanceof CommandException) {
732 loge("sendEnvelopeWithStatus: CommandException: " +
733 ar.exception);
734 } else {
735 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
736 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800739 break;
740
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 case CMD_OPEN_CHANNEL:
742 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800744 IccLogicalChannelRequest openChannelRequest =
745 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800748 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800749 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800753 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
754 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_OPEN_CHANNEL_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 int[] result = (int[]) ar.result;
764 int channelId = result[0];
765 byte[] selectResponse = null;
766 if (result.length > 1) {
767 selectResponse = new byte[result.length - 1];
768 for (int i = 1; i < result.length; ++i) {
769 selectResponse[i - 1] = (byte) result[i];
770 }
771 }
772 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800773 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800774
775 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700776 if (uiccPort == null) {
777 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
778 } else {
779 IccLogicalChannelRequest channelRequest =
780 (IccLogicalChannelRequest) request.argument;
781 channelRequest.channel = channelId;
782 uiccPort.onLogicalChannelOpened(channelRequest);
783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 if (ar.result == null) {
786 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700788 if (ar.exception != null) {
789 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
790 }
791
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700792 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700793 if (ar.exception instanceof CommandException) {
794 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800795 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700796 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700797 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700798 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700799 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700800 }
801 }
802 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700805 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 break;
808
809 case CMD_CLOSE_CHANNEL:
810 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000811 uiccPort = getUiccPortFromRequest(request);
812 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700813 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800814 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800815 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800816 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700817 } else {
818 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000819 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 break;
822
823 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null) {
827 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700829 if (uiccPort == null) {
830 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
831 } else {
832 final int channelId = (Integer) request.argument;
833 uiccPort.onLogicalChannelClosed(channelId);
834 }
Chen Xu540470b2021-12-14 17:15:47 -0800835 } else {
836 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800837 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800838 if (ar.exception instanceof CommandException) {
839 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
840 CommandException.Error error =
841 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800842 if (error == CommandException.Error.INVALID_ARGUMENTS) {
843 // should only throw exceptions from the binder threads.
844 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800845 "iccCloseLogicalChannel: invalid argument ");
846 }
847 } else {
848 loge("iccCloseLogicalChannel: Unknown exception");
849 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800850 request.result = (exception != null) ? exception :
851 new IllegalStateException(
852 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800853 }
854 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800855 break;
856
857 case CMD_NV_READ_ITEM:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800860 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
861 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700869 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800870 request.result = "";
871 if (ar.result == null) {
872 loge("nvReadItem: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("nvReadItem: CommandException: " +
875 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800877 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700878 }
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 break;
882
Jake Hambye994d462014-02-03 13:10:13 -0800883 case CMD_NV_WRITE_ITEM:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
886 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700888 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800889 break;
890
891 case EVENT_NV_WRITE_ITEM_DONE:
892 handleNullReturnEvent(msg, "nvWriteItem");
893 break;
894
895 case CMD_NV_WRITE_CDMA_PRL:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800898 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800899 break;
900
901 case EVENT_NV_WRITE_CDMA_PRL_DONE:
902 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
903 break;
904
chen xu6dac5ab2018-10-26 17:39:23 -0700905 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800906 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700907 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800908 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
chen xu6dac5ab2018-10-26 17:39:23 -0700911 case EVENT_RESET_MODEM_CONFIG_DONE:
912 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800913 break;
914
Sooraj Sasindran37444802020-08-11 10:40:43 -0700915 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
918 request);
919 Phone phone = getPhoneFromRequest(request);
920 if (phone != null) {
921 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
922 } else {
923 loge("isNRDualConnectivityEnabled: No phone object");
924 request.result = false;
925 notifyRequester(request);
926 }
927 break;
928 }
929
930 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
931 ar = (AsyncResult) msg.obj;
932 request = (MainThreadRequest) ar.userObj;
933 if (ar.exception == null && ar.result != null) {
934 request.result = ar.result;
935 } else {
936 // request.result must be set to something non-null
937 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700938 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700939 request.result = ar.result;
940 } else {
941 request.result = false;
942 }
943 if (ar.result == null) {
944 loge("isNRDualConnectivityEnabled: Empty response");
945 } else if (ar.exception instanceof CommandException) {
946 loge("isNRDualConnectivityEnabled: CommandException: "
947 + ar.exception);
948 } else {
949 loge("isNRDualConnectivityEnabled: Unknown exception");
950 }
951 }
952 notifyRequester(request);
953 break;
954
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700955 case CMD_IS_VONR_ENABLED: {
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
958 request);
959 Phone phone = getPhoneFromRequest(request);
960 if (phone != null) {
961 phone.isVoNrEnabled(onCompleted, request.workSource);
962 } else {
963 loge("isVoNrEnabled: No phone object");
964 request.result = false;
965 notifyRequester(request);
966 }
967 break;
968 }
969
970 case EVENT_IS_VONR_ENABLED_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 if (ar.exception == null && ar.result != null) {
974 request.result = ar.result;
975 } else {
976 // request.result must be set to something non-null
977 // for the calling thread to unblock
978 if (ar.result != null) {
979 request.result = ar.result;
980 } else {
981 request.result = false;
982 }
983 if (ar.result == null) {
984 loge("isVoNrEnabled: Empty response");
985 } else if (ar.exception instanceof CommandException) {
986 loge("isVoNrEnabled: CommandException: "
987 + ar.exception);
988 } else {
989 loge("isVoNrEnabled: Unknown exception");
990 }
991 }
992 notifyRequester(request);
993 break;
994
Sooraj Sasindran37444802020-08-11 10:40:43 -0700995 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
998 Phone phone = getPhoneFromRequest(request);
999 if (phone != null) {
1000 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1001 request.workSource);
1002 } else {
1003 loge("enableNrDualConnectivity: No phone object");
1004 request.result =
1005 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1006 notifyRequester(request);
1007 }
1008 break;
1009 }
1010
1011 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception == null) {
1015 request.result =
1016 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1017 } else {
1018 request.result =
1019 TelephonyManager
1020 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1021 if (ar.exception instanceof CommandException) {
1022 CommandException.Error error =
1023 ((CommandException) (ar.exception)).getCommandError();
1024 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1025 request.result =
1026 TelephonyManager
1027 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001028 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1029 request.result =
1030 TelephonyManager
1031 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001032 }
1033 loge("enableNrDualConnectivity" + ": CommandException: "
1034 + ar.exception);
1035 } else {
1036 loge("enableNrDualConnectivity" + ": Unknown exception");
1037 }
1038 }
1039 notifyRequester(request);
1040 break;
1041 }
1042
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001043 case CMD_ENABLE_VONR: {
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1046 Phone phone = getPhoneFromRequest(request);
1047 if (phone != null) {
1048 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1049 request.workSource);
1050 } else {
1051 loge("setVoNrEnabled: No phone object");
1052 request.result =
1053 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1054 notifyRequester(request);
1055 }
1056 break;
1057 }
1058
1059 case EVENT_ENABLE_VONR_DONE: {
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 if (ar.exception == null) {
1063 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1064 } else {
1065 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1066 if (ar.exception instanceof CommandException) {
1067 CommandException.Error error =
1068 ((CommandException) (ar.exception)).getCommandError();
1069 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1070 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1071 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1072 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1073 } else {
1074 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1075 }
1076 loge("setVoNrEnabled" + ": CommandException: "
1077 + ar.exception);
1078 } else {
1079 loge("setVoNrEnabled" + ": Unknown exception");
1080 }
1081 }
1082 notifyRequester(request);
1083 break;
1084 }
1085
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1089 request);
1090 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null && ar.result != null) {
1097 request.result = ar.result; // Integer
1098 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301099 // request.result must be set to something non-null
1100 // for the calling thread to unblock
1101 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001103 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001104 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 loge("getAllowedNetworkTypesBitmask: CommandException: "
1106 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 }
1110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 break;
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1117 request);
1118 Pair<Integer, Long> reasonWithNetworkTypes =
1119 (Pair<Integer, Long>) request.argument;
1120 getPhoneFromRequest(request).setAllowedNetworkTypes(
1121 reasonWithNetworkTypes.first,
1122 reasonWithNetworkTypes.second,
1123 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 break;
1125
SongFerngWang3ef3e072020-12-21 16:41:52 +08001126 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1127 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 break;
1129
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001130 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1131 request = (MainThreadRequest)msg.obj;
1132 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001133 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001134 break;
1135
1136 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1137 ar = (AsyncResult)msg.obj;
1138 request = (MainThreadRequest)ar.userObj;
1139 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001141 break;
1142
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001143 case CMD_SET_VOICEMAIL_NUMBER:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1146 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001147 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1148 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001149 break;
1150
1151 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1152 handleNullReturnEvent(msg, "setVoicemailNumber");
1153 break;
1154
Stuart Scott54788802015-03-30 13:18:01 -07001155 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1158 request);
1159 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1160 break;
1161
1162 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1163 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1164 break;
1165
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 case CMD_PERFORM_NETWORK_SCAN:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1169 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1170 break;
1171
Hall Liu27d24262020-09-18 19:04:59 -07001172 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001175 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1176 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1177 request.argument;
1178 int callForwardingReason = args.first;
1179 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
Hall Liu27d24262020-09-18 19:04:59 -07001181 }
1182 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001185 TelephonyManager.CallForwardingInfoCallback callback =
1186 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1187 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001188 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001189 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1191 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1192 // Service Class is a bit mask per 3gpp 27.007. Search for
1193 // any service for voice call.
1194 if ((callForwardInfo.serviceClass
1195 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001196 callForwardingInfo = new CallForwardingInfo(
1197 callForwardInfo.status
1198 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001199 callForwardInfo.reason,
1200 callForwardInfo.number,
1201 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 break;
1203 }
1204 }
1205 // Didn't find a call forward info for voice call.
1206 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1208 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
Hall Liu27d24262020-09-18 19:04:59 -07001210 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 } else {
1212 if (ar.result == null) {
1213 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1214 }
1215 if (ar.exception != null) {
1216 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1217 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001218 int errorCode = TelephonyManager
1219 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 if (ar.exception instanceof CommandException) {
1221 CommandException.Error error =
1222 ((CommandException) (ar.exception)).getCommandError();
1223 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001224 errorCode = TelephonyManager
1225 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001227 errorCode = TelephonyManager
1228 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 }
1230 }
Hall Liu27d24262020-09-18 19:04:59 -07001231 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 request = (MainThreadRequest) msg.obj;
1238 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001239 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001240 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001241 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1242 request.argument).first;
1243 request.phone.setCallForwardingOption(
1244 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001245 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001246 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001247 callForwardingInfoToSet.getReason(),
1248 callForwardingInfoToSet.getNumber(),
1249 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 ar = (AsyncResult) msg.obj;
1255 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001256 Consumer<Integer> callback =
1257 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1258 request.argument).second;
1259 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 int errorCode = TelephonyManager.CallForwardingInfoCallback
1262 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001263 if (ar.exception instanceof CommandException) {
1264 CommandException.Error error =
1265 ((CommandException) (ar.exception)).getCommandError();
1266 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001267 errorCode = TelephonyManager.CallForwardingInfoCallback
1268 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001269 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager.CallForwardingInfoCallback
1271 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001272 }
1273 }
1274 callback.accept(errorCode);
1275 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001276 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280
Hall Liu27d24262020-09-18 19:04:59 -07001281 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001282 request = (MainThreadRequest) msg.obj;
1283 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1284 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1285 break;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
Shuo Qian4a594052020-01-23 11:59:30 -08001287
Hall Liu27d24262020-09-18 19:04:59 -07001288 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001291 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001292 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001293 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001294 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001295 // Service Class is a bit mask per 3gpp 27.007.
1296 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001297 if (callForwardResults.length > 1
1298 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001299 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001301 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1302 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001303 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
1306 } else {
1307 if (ar.result == null) {
1308 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1309 }
1310 if (ar.exception != null) {
1311 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1312 }
1313 if (ar.exception instanceof CommandException) {
1314 CommandException.Error error =
1315 ((CommandException) (ar.exception)).getCommandError();
1316 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001318 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1320 callWaitingStatus =
1321 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 }
1323 }
1324 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001325 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001332 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1333 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001334 break;
Hall Liu27d24262020-09-18 19:04:59 -07001335 }
Shuo Qian4a594052020-01-23 11:59:30 -08001336
Hall Liu27d24262020-09-18 19:04:59 -07001337 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001340 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1341 Consumer<Integer> callback =
1342 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1343 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001344 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001345 if (ar.exception instanceof CommandException) {
1346 CommandException.Error error =
1347 ((CommandException) (ar.exception)).getCommandError();
1348 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1349 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1351 callback.accept(
1352 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001353 } else {
1354 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1355 }
1356 } else {
1357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1358 }
1359 } else {
1360 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1361 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 }
Shuo Qian4a594052020-01-23 11:59:30 -08001363 break;
Hall Liu27d24262020-09-18 19:04:59 -07001364 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001365 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 CellNetworkScanResult cellScanResult;
1369 if (ar.exception == null && ar.result != null) {
1370 cellScanResult = new CellNetworkScanResult(
1371 CellNetworkScanResult.STATUS_SUCCESS,
1372 (List<OperatorInfo>) ar.result);
1373 } else {
1374 if (ar.result == null) {
1375 loge("getCellNetworkScanResults: Empty response");
1376 }
1377 if (ar.exception != null) {
1378 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1379 }
1380 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1381 if (ar.exception instanceof CommandException) {
1382 CommandException.Error error =
1383 ((CommandException) (ar.exception)).getCommandError();
1384 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1385 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1386 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1387 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1388 }
1389 }
1390 cellScanResult = new CellNetworkScanResult(errorCode, null);
1391 }
1392 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001394 break;
1395
1396 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1397 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001398 ManualNetworkSelectionArgument selArg =
1399 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1401 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001402 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1403 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001404 break;
1405
1406 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 if (ar.exception == null) {
1410 request.result = true;
1411 } else {
1412 request.result = false;
1413 loge("setNetworkSelectionModeManual " + ar.exception);
1414 }
1415 notifyRequester(request);
1416 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 break;
1418
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001419 case CMD_GET_MODEM_ACTIVITY_INFO:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001422 if (defaultPhone != null) {
1423 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001424 } else {
1425 ResultReceiver result = (ResultReceiver) request.argument;
1426 Bundle bundle = new Bundle();
1427 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001428 new ModemActivityInfo(0, 0, 0,
1429 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001431 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 break;
1433
Hall Liud0f208c2020-10-14 16:54:44 -07001434 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001438 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001439 if (mLastModemActivityInfo == null) {
1440 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1441 mLastModemActivitySpecificInfo[0] =
1442 new ActivityStatsTechSpecificInfo(
1443 0,
1444 0,
1445 new int[ModemActivityInfo.getNumTxPowerLevels()],
1446 0);
1447 mLastModemActivityInfo =
1448 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1449 }
1450
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 // Update the last modem activity info and the result of the request.
1453 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1454 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001455 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001457 mLastModemActivityInfo =
1458 new ModemActivityInfo(
1459 mLastModemActivityInfo.getTimestampMillis(),
1460 mLastModemActivityInfo.getSleepTimeMillis(),
1461 mLastModemActivityInfo.getIdleTimeMillis(),
1462 mLastModemActivitySpecificInfo);
1463
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 } else {
1465 if (ar.result == null) {
1466 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001467 error = TelephonyManager.ModemActivityInfoException
1468 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001470 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001471 error = TelephonyManager.ModemActivityInfoException
1472 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 } else {
1474 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001475 error = TelephonyManager.ModemActivityInfoException
1476 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 }
1478 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001480 if (mLastModemActivityInfo != null) {
1481 bundle.putParcelable(
1482 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1483 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001484 } else {
1485 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1486 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001488 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001490 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 case CMD_SET_ALLOWED_CARRIERS:
1493 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001494 CarrierRestrictionRules argument =
1495 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001497 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 if (ar.exception == null && ar.result != null) {
1504 request.result = ar.result;
1505 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001506 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1507 if (ar.exception instanceof CommandException) {
1508 loge("setAllowedCarriers: CommandException: " + ar.exception);
1509 CommandException.Error error =
1510 ((CommandException) (ar.exception)).getCommandError();
1511 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1512 request.result =
1513 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1514 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 } else {
1516 loge("setAllowedCarriers: Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 break;
1521
1522 case CMD_GET_ALLOWED_CARRIERS:
1523 request = (MainThreadRequest) msg.obj;
1524 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001525 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 break;
1527
1528 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception == null && ar.result != null) {
1532 request.result = ar.result;
1533 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001534 request.result = new IllegalStateException(
1535 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 if (ar.result == null) {
1537 loge("getAllowedCarriers: Empty response");
1538 } else if (ar.exception instanceof CommandException) {
1539 loge("getAllowedCarriers: CommandException: " +
1540 ar.exception);
1541 } else {
1542 loge("getAllowedCarriers: Unknown exception");
1543 }
1544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 break;
1547
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
1554 request.result = new IllegalArgumentException(
1555 "Failed to retrieve Forbidden Plmns");
1556 if (ar.result == null) {
1557 loge("getForbiddenPlmns: Empty response");
1558 } else {
1559 loge("getForbiddenPlmns: Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 break;
1564
1565 case CMD_GET_FORBIDDEN_PLMNS:
1566 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001567 uiccPort = getUiccPortFromRequest(request);
1568 if (uiccPort == null) {
1569 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001570 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001571 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001573 break;
1574 }
1575 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001576 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001577 if (uiccApp == null) {
1578 loge("getForbiddenPlmns() no app with specified type -- "
1579 + appType);
1580 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001582 break;
1583 } else {
1584 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1585 + " specified type -- " + appType);
1586 }
1587 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1588 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1589 onCompleted);
1590 break;
1591
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001592 case CMD_SWITCH_SLOTS:
1593 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001594 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001596 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001597 break;
1598
1599 case EVENT_SWITCH_SLOTS_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001603 notifyRequester(request);
1604 break;
1605 case CMD_GET_NETWORK_SELECTION_MODE:
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1608 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1609 break;
1610
1611 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1612 ar = (AsyncResult) msg.obj;
1613 request = (MainThreadRequest) ar.userObj;
1614 if (ar.exception != null) {
1615 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1616 } else {
1617 int mode = ((int[]) ar.result)[0];
1618 if (mode == 0) {
1619 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1620 } else {
1621 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1622 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001624 notifyRequester(request);
1625 break;
1626 case CMD_GET_CDMA_ROAMING_MODE:
1627 request = (MainThreadRequest) msg.obj;
1628 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1629 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1630 break;
1631 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception != null) {
1635 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1636 } else {
1637 request.result = ((int[]) ar.result)[0];
1638 }
1639 notifyRequester(request);
1640 break;
1641 case CMD_SET_CDMA_ROAMING_MODE:
1642 request = (MainThreadRequest) msg.obj;
1643 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1644 int mode = (int) request.argument;
1645 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1646 break;
1647 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 request.result = ar.exception == null;
1651 notifyRequester(request);
1652 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001653 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1654 request = (MainThreadRequest) msg.obj;
1655 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1656 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1657 break;
1658 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 if (ar.exception != null) {
1662 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1663 } else {
1664 request.result = ((int[]) ar.result)[0];
1665 }
1666 notifyRequester(request);
1667 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001668 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1671 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001672 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1673 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 break;
1675 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 request.result = ar.exception == null;
1679 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001681 case CMD_GET_ALL_CELL_INFO:
1682 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001683 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001684 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001686 case EVENT_GET_ALL_CELL_INFO_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001689 // If a timeout occurs, the response will be null
1690 request.result = (ar.exception == null && ar.result != null)
1691 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001692 synchronized (request) {
1693 request.notifyAll();
1694 }
1695 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 case CMD_REQUEST_CELL_INFO_UPDATE:
1697 request = (MainThreadRequest) msg.obj;
1698 request.phone.requestCellInfoUpdate(request.workSource,
1699 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1700 break;
1701 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1705 try {
1706 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001707 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001708 cb.onError(
1709 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1710 ar.exception.getClass().getName(),
1711 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001714 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001715 } else {
1716 // use the result as returned
1717 cb.onCellInfo((List<CellInfo>) ar.result);
1718 }
1719 } catch (RemoteException re) {
1720 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001724 request = (MainThreadRequest) msg.obj;
1725 WorkSource ws = (WorkSource) request.argument;
1726 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001727 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001728 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001729 }
1730 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 if (ar.exception == null) {
1734 request.result = ar.result;
1735 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001736 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001738 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 }
1740
1741 synchronized (request) {
1742 request.notifyAll();
1743 }
1744 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001745 }
chen xu6dac5ab2018-10-26 17:39:23 -07001746 case CMD_MODEM_REBOOT:
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001749 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001750 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001751 case EVENT_CMD_MODEM_REBOOT_DONE:
1752 handleNullReturnEvent(msg, "rebootModem");
1753 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001754 case CMD_REQUEST_ENABLE_MODEM:
1755 request = (MainThreadRequest) msg.obj;
1756 boolean enable = (boolean) request.argument;
1757 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001758 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001759 PhoneConfigurationManager.getInstance()
1760 .enablePhone(request.phone, enable, onCompleted);
1761 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001762 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001766 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001767 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001768 if ((boolean) request.result) {
1769 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1770 updateModemStateMetrics();
1771 } else {
1772 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1773 + ar.exception);
1774 }
1775 notifyRequester(request);
1776 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001777 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001778 case CMD_GET_MODEM_STATUS:
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1781 PhoneConfigurationManager.getInstance()
1782 .getPhoneStatusFromModem(request.phone, onCompleted);
1783 break;
1784 case EVENT_GET_MODEM_STATUS_DONE:
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 int id = request.phone.getPhoneId();
1788 if (ar.exception == null && ar.result != null) {
1789 request.result = ar.result;
1790 //update the cache as modem status has changed
1791 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1792 (boolean) request.result);
1793 } else {
1794 // Return true if modem status cannot be retrieved. For most cases,
1795 // modem status is on. And for older version modems, GET_MODEM_STATUS
1796 // and disable modem are not supported. Modem is always on.
1797 // TODO: this should be fixed in R to support a third
1798 // status UNKNOWN b/131631629
1799 request.result = true;
1800 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1801 + ar.exception);
1802 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001803 notifyRequester(request);
1804 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001805 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1806 request = (MainThreadRequest) msg.obj;
1807 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1808 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1809 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1810 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1811 break;
1812 }
1813 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1817 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1818 args.second.accept(ar.exception == null);
1819 notifyRequester(request);
1820 break;
1821 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1823 request = (MainThreadRequest) msg.obj;
1824 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1825 Phone phone = getPhoneFromRequest(request);
1826 if (phone != null) {
1827 phone.getSystemSelectionChannels(onCompleted);
1828 } else {
1829 loge("getSystemSelectionChannels: No phone object");
1830 request.result = new ArrayList<RadioAccessSpecifier>();
1831 notifyRequester(request);
1832 }
1833 break;
1834 }
1835 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null && ar.result != null) {
1839 request.result = ar.result;
1840 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001841 request.result = new IllegalStateException(
1842 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001843 if (ar.result == null) {
1844 loge("getSystemSelectionChannels: Empty response");
1845 } else {
1846 loge("getSystemSelectionChannels: Unknown exception");
1847 }
1848 }
1849 notifyRequester(request);
1850 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001851 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 if (ar.exception == null && ar.result != null) {
1855 request.result = ar.result;
1856 } else {
1857 request.result = -1;
1858 loge("Failed to set Forbidden Plmns");
1859 if (ar.result == null) {
1860 loge("setForbidenPlmns: Empty response");
1861 } else if (ar.exception != null) {
1862 loge("setForbiddenPlmns: Exception: " + ar.exception);
1863 request.result = -1;
1864 } else {
1865 loge("setForbiddenPlmns: Unknown exception");
1866 }
1867 }
1868 notifyRequester(request);
1869 break;
1870 case CMD_SET_FORBIDDEN_PLMNS:
1871 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001872 uiccPort = getUiccPortFromRequest(request);
1873 if (uiccPort == null) {
1874 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001875 request.result = -1;
1876 notifyRequester(request);
1877 break;
1878 }
1879 Pair<Integer, List<String>> setFplmnsArgs =
1880 (Pair<Integer, List<String>>) request.argument;
1881 appType = setFplmnsArgs.first;
1882 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001883 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001884 if (uiccApp == null) {
1885 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1886 request.result = -1;
1887 loge("Failed to get UICC App");
1888 notifyRequester(request);
1889 } else {
1890 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1891 ((SIMRecords) uiccApp.getIccRecords())
1892 .setForbiddenPlmns(onCompleted, fplmns);
1893 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001894 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001895 case CMD_ERASE_MODEM_CONFIG:
1896 request = (MainThreadRequest) msg.obj;
1897 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1898 defaultPhone.eraseModemConfig(onCompleted);
1899 break;
1900 case EVENT_ERASE_MODEM_CONFIG_DONE:
1901 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001902 break;
zoey chene02881a2019-12-30 16:11:23 +08001903
Kai Shif70f46f2021-03-03 13:59:46 -08001904 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1905 request = (MainThreadRequest) msg.obj;
1906 request.result = defaultPhone.eraseDataInSharedPreferences();
1907 notifyRequester(request);
1908 break;
1909
zoey chene02881a2019-12-30 16:11:23 +08001910 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1913 Pair<String, String> changed = (Pair<String, String>) request.argument;
1914 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1915 changed.first, changed.second, onCompleted);
1916 break;
1917 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null) {
1921 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001922 // If the operation is successful, update the PIN storage
1923 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1924 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001925 UiccController.getInstance().getPinStorage()
1926 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001927 } else {
1928 request.result = msg.arg1;
1929 }
1930 notifyRequester(request);
1931 break;
1932
Michele Berionne5e411512020-11-13 02:36:59 +00001933 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001934 request = (MainThreadRequest) msg.obj;
1935 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1936 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1937 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1938 enabled.first, enabled.second, onCompleted);
1939 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001940 }
zoey chene02881a2019-12-30 16:11:23 +08001941 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1942 ar = (AsyncResult) msg.obj;
1943 request = (MainThreadRequest) ar.userObj;
1944 if (ar.exception == null) {
1945 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001946 // If the operation is successful, update the PIN storage
1947 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1948 int phoneId = getPhoneFromRequest(request).getPhoneId();
1949 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001950 UiccController.getInstance().getPinStorage()
1951 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001952 } else {
1953 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1954 }
zoey chene02881a2019-12-30 16:11:23 +08001955 } else {
1956 request.result = msg.arg1;
1957 }
Michele Berionne5e411512020-11-13 02:36:59 +00001958
1959
zoey chene02881a2019-12-30 16:11:23 +08001960 notifyRequester(request);
1961 break;
1962
Peter Wangdafb9ac2020-01-15 14:13:38 -08001963 case MSG_NOTIFY_USER_ACTIVITY:
1964 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001965 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001966 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1967 getDefaultPhone().getContext().sendBroadcastAsUser(
1968 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1969 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001970
1971 case CMD_SET_DATA_THROTTLING: {
1972 request = (MainThreadRequest) msg.obj;
1973 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1974 DataThrottlingRequest dataThrottlingRequest =
1975 (DataThrottlingRequest) request.argument;
1976 Phone phone = getPhoneFromRequest(request);
1977 if (phone != null) {
1978 phone.setDataThrottling(onCompleted,
1979 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1980 dataThrottlingRequest.getCompletionDurationMillis());
1981 } else {
1982 loge("setDataThrottling: No phone object");
1983 request.result =
1984 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1985 notifyRequester(request);
1986 }
1987
1988 break;
1989 }
1990 case EVENT_SET_DATA_THROTTLING_DONE:
1991 ar = (AsyncResult) msg.obj;
1992 request = (MainThreadRequest) ar.userObj;
1993
1994 if (ar.exception == null) {
1995 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1996 } else if (ar.exception instanceof CommandException) {
1997 loge("setDataThrottling: CommandException: " + ar.exception);
1998 CommandException.Error error =
1999 ((CommandException) (ar.exception)).getCommandError();
2000
2001 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2002 request.result = TelephonyManager
2003 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2004 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2005 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2007 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002008 } else {
2009 request.result =
2010 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2011 }
2012 } else {
2013 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2014 }
2015 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2016 notifyRequester(request);
2017 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002018
2019 case CMD_SET_SIM_POWER: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2022 request = (MainThreadRequest) msg.obj;
2023 int stateToSet =
2024 ((Pair<Integer, IIntegerConsumer>)
2025 request.argument).first;
2026 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2027 break;
2028 }
2029 case EVENT_SET_SIM_POWER_DONE: {
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 IIntegerConsumer callback =
2033 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2034 if (ar.exception != null) {
2035 loge("setSimPower exception: " + ar.exception);
2036 int errorCode = TelephonyManager.CallForwardingInfoCallback
2037 .RESULT_ERROR_UNKNOWN;
2038 if (ar.exception instanceof CommandException) {
2039 CommandException.Error error =
2040 ((CommandException) (ar.exception)).getCommandError();
2041 if (error == CommandException.Error.SIM_ERR) {
2042 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2043 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2044 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2045 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2046 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2047 } else {
2048 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2049 }
2050 }
2051 try {
2052 callback.accept(errorCode);
2053 } catch (RemoteException e) {
2054 // Ignore if the remote process is no longer available to call back.
2055 Log.w(LOG_TAG, "setSimPower: callback not available.");
2056 }
2057 } else {
2058 try {
2059 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2060 } catch (RemoteException e) {
2061 // Ignore if the remote process is no longer available to call back.
2062 Log.w(LOG_TAG, "setSimPower: callback not available.");
2063 }
2064 }
2065 break;
2066 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002067 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2068 request = (MainThreadRequest) msg.obj;
2069
2070 final Phone phone = getPhoneFromRequest(request);
2071 if (phone == null || phone.getServiceStateTracker() == null) {
2072 request.result = new IllegalStateException("Phone or SST is null");
2073 notifyRequester(request);
2074 break;
2075 }
2076
2077 Pair<Integer, SignalStrengthUpdateRequest> pair =
2078 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2079 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2080 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002081 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002082 request.subId, pair.first /*callingUid*/,
2083 pair.second /*request*/, onCompleted);
2084 break;
2085 }
2086 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2087 ar = (AsyncResult) msg.obj;
2088 request = (MainThreadRequest) ar.userObj;
2089 // request.result will be the exception of ar if present, true otherwise.
2090 // Be cautious not to leave result null which will wait() forever
2091 request.result = ar.exception != null ? ar.exception : true;
2092 notifyRequester(request);
2093 break;
2094 }
2095 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2096 request = (MainThreadRequest) msg.obj;
2097
2098 Phone phone = getPhoneFromRequest(request);
2099 if (phone == null || phone.getServiceStateTracker() == null) {
2100 request.result = new IllegalStateException("Phone or SST is null");
2101 notifyRequester(request);
2102 break;
2103 }
2104
2105 Pair<Integer, SignalStrengthUpdateRequest> pair =
2106 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2107 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2108 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002109 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002110 request.subId, pair.first /*callingUid*/,
2111 pair.second /*request*/, onCompleted);
2112 break;
2113 }
2114 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 request.result = ar.exception != null ? ar.exception : true;
2118 notifyRequester(request);
2119 break;
2120 }
Jordan Liu109698e2020-11-24 14:50:34 -08002121
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 case CMD_GET_SLICING_CONFIG: {
2123 request = (MainThreadRequest) msg.obj;
2124 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2125 request.phone.getSlicingConfig(onCompleted);
2126 break;
2127 }
2128 case EVENT_GET_SLICING_CONFIG_DONE: {
2129 ar = (AsyncResult) msg.obj;
2130 request = (MainThreadRequest) ar.userObj;
2131 ResultReceiver result = (ResultReceiver) request.argument;
2132
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002133 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002134 Bundle bundle = new Bundle();
2135 int resultCode = 0;
2136 if (ar.exception != null) {
2137 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2138 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002139 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002140 } else if (ar.result == null) {
2141 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002142 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002143 } else {
2144 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002145 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2146 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002147 }
2148
2149 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002150 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002151 }
2152 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2153 result.send(resultCode, bundle);
2154 notifyRequester(request);
2155 break;
2156 }
2157
Sarah Chin71b3a852022-09-28 15:54:19 -07002158 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002159 request = (MainThreadRequest) msg.obj;
2160 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002161 PurchasePremiumCapabilityArgument arg =
2162 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin46355ba2022-11-01 23:51:16 -07002163 SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002164 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002165 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002166 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002167
Sarah Chin71b3a852022-09-28 15:54:19 -07002168 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002171 PurchasePremiumCapabilityArgument arg =
2172 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002173 try {
2174 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002178 + ", result= "
2179 + TelephonyManager.convertPurchaseResultToString(result));
2180 } catch (RemoteException e) {
2181 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002182 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002183 + " failed: " + e;
2184 if (DBG) log(logStr);
2185 AnomalyReporter.reportAnomaly(
2186 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2187 }
2188 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002189 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002190
Michele Berionne5e411512020-11-13 02:36:59 +00002191 case CMD_PREPARE_UNATTENDED_REBOOT:
2192 request = (MainThreadRequest) msg.obj;
2193 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002194 UiccController.getInstance().getPinStorage()
2195 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002196 notifyRequester(request);
2197 break;
2198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 default:
2200 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2201 break;
2202 }
2203 }
Jake Hambye994d462014-02-03 13:10:13 -08002204
Pengquan Menga1bb6272018-09-06 09:59:22 -07002205 private void notifyRequester(MainThreadRequest request) {
2206 synchronized (request) {
2207 request.notifyAll();
2208 }
2209 }
2210
Jake Hambye994d462014-02-03 13:10:13 -08002211 private void handleNullReturnEvent(Message msg, String command) {
2212 AsyncResult ar = (AsyncResult) msg.obj;
2213 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2214 if (ar.exception == null) {
2215 request.result = true;
2216 } else {
2217 request.result = false;
2218 if (ar.exception instanceof CommandException) {
2219 loge(command + ": CommandException: " + ar.exception);
2220 } else {
2221 loge(command + ": Unknown exception");
2222 }
2223 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002224 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 }
2227
2228 /**
2229 * Posts the specified command to be executed on the main thread,
2230 * waits for the request to complete, and returns the result.
2231 * @see #sendRequestAsync
2232 */
2233 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2235 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002236 }
2237
2238 /**
2239 * Posts the specified command to be executed on the main thread,
2240 * waits for the request to complete, and returns the result.
2241 * @see #sendRequestAsync
2242 */
2243 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2244 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002245 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002246 }
2247
2248 /**
2249 * Posts the specified command to be executed on the main thread,
2250 * waits for the request to complete, and returns the result.
2251 * @see #sendRequestAsync
2252 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002253 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002254 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2255 }
2256
2257 /**
2258 * Posts the specified command to be executed on the main thread,
2259 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2260 * if not timeout or null otherwise.
2261 * @see #sendRequestAsync
2262 */
2263 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2264 long timeoutInMs) {
2265 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002266 }
2267
2268 /**
2269 * Posts the specified command to be executed on the main thread,
2270 * waits for the request to complete, and returns the result.
2271 * @see #sendRequestAsync
2272 */
Nathan Harold92bed182018-10-12 18:16:49 -07002273 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002274 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002275 }
2276
2277 /**
2278 * Posts the specified command to be executed on the main thread,
2279 * waits for the request to complete, and returns the result.
2280 * @see #sendRequestAsync
2281 */
2282 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002283 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2284 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002285 }
2286
2287 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2289 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2290 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002291 * @see #sendRequestAsync
2292 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002293 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2294 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2296 throw new RuntimeException("This method will deadlock if called from the main thread.");
2297 }
2298
Nathan Harold92bed182018-10-12 18:16:49 -07002299 MainThreadRequest request = null;
2300 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2301 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2302 } else if (phone != null) {
2303 request = new MainThreadRequest(argument, phone, workSource);
2304 } else {
2305 request = new MainThreadRequest(argument, subId, workSource);
2306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 Message msg = mMainThreadHandler.obtainMessage(command, request);
2309 msg.sendToTarget();
2310
Rambo Wang0f050d82021-02-12 11:43:36 -08002311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002313 if (timeoutInMs >= 0) {
2314 // Wait for at least timeoutInMs before returning null request result
2315 long now = SystemClock.elapsedRealtime();
2316 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002317 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002318 try {
2319 request.wait(deadline - now);
2320 } catch (InterruptedException e) {
2321 // Do nothing, go back and check if request is completed or timeout
2322 } finally {
2323 now = SystemClock.elapsedRealtime();
2324 }
2325 }
2326 } else {
2327 // Wait for the request to complete
2328 while (request.result == null) {
2329 try {
2330 request.wait();
2331 } catch (InterruptedException e) {
2332 // Do nothing, go back and wait until the request is complete
2333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335 }
2336 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 if (request.result == null) {
2338 Log.wtf(LOG_TAG,
2339 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 return request.result;
2342 }
2343
2344 /**
2345 * Asynchronous ("fire and forget") version of sendRequest():
2346 * Posts the specified command to be executed on the main thread, and
2347 * returns immediately.
2348 * @see #sendRequest
2349 */
2350 private void sendRequestAsync(int command) {
2351 mMainThreadHandler.sendEmptyMessage(command);
2352 }
2353
2354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002357 */
2358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002359 sendRequestAsync(command, argument, null, null);
2360 }
2361
2362 /**
2363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2364 * @see {@link #sendRequest(int,Object)}
2365 */
2366 private void sendRequestAsync(
2367 int command, Object argument, Phone phone, WorkSource workSource) {
2368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002369 Message msg = mMainThreadHandler.obtainMessage(command, request);
2370 msg.sendToTarget();
2371 }
2372
2373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 * Initialize the singleton PhoneInterfaceManager instance.
2375 * This is only done once, at startup, from PhoneApp.onCreate().
2376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 synchronized (PhoneInterfaceManager.class) {
2379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 } else {
2382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2383 }
2384 return sInstance;
2385 }
2386 }
2387
2388 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002392 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002395 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002398 mTelephonySharedPreferences =
2399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002402 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002403 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002404 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002405 mTelephony2gUpdater = new Telephony2gUpdater(
2406 Executors.newSingleThreadExecutor(), mApp);
2407 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 publish();
2409 }
2410
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002411 private Phone getDefaultPhone() {
2412 Phone thePhone = getPhone(getDefaultSubscription());
2413 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 private void publish() {
2417 if (DBG) log("publish: " + this);
2418
Peter Wangc035ce42020-01-08 21:00:22 -08002419 TelephonyFrameworkInitializer
2420 .getTelephonyServiceManager()
2421 .getTelephonyServiceRegisterer()
2422 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
Stuart Scott584921c2015-01-15 17:10:34 -08002425 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002426 if (request.phone != null) {
2427 return request.phone;
2428 } else {
2429 return getPhoneFromSubId(request.subId);
2430 }
2431 }
2432
2433 private Phone getPhoneFromSubId(int subId) {
2434 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2435 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002436 }
2437
Rambo Wange53e07d2022-05-10 13:01:13 -07002438 @Nullable
2439 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 Phone phone = getPhoneFromRequest(request);
2441 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002442 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002443 }
2444
Wink Saville36469e72014-06-11 15:17:00 -07002445 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002447 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449
Kai Shif70f46f2021-03-03 13:59:46 -08002450 private void sendEraseModemConfig(@NonNull Phone phone) {
2451 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2452 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2453 }
2454
2455 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2456 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2457 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002458 }
2459
Peter Wang44b186e2020-01-13 23:33:09 -08002460 private boolean isImsAvailableOnDevice() {
2461 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2462 if (pm == null) {
2463 // For some reason package manger is not available.. This will fail internally anyway,
2464 // so do not throw error and allow.
2465 return true;
2466 }
2467 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2468 }
2469
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002471 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002472 }
2473
Wink Savilleb564aae2014-10-23 10:18:09 -07002474 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 if (DBG) log("dial: " + number);
2476 // No permission check needed here: This is just a wrapper around the
2477 // ACTION_DIAL intent, which is available to any app since it puts up
2478 // the UI before it does anything.
2479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 String url = createTelUrl(number);
2483 if (url == null) {
2484 return;
2485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487 // PENDING: should we just silently fail if phone is offhook or ringing?
2488 PhoneConstants.State state = mCM.getState(subId);
2489 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2490 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2492 mApp.startActivity(intent);
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497 }
2498
2499 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002500 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 if (DBG) log("call: " + number);
2505
2506 // This is just a wrapper around the ACTION_CALL intent, but we still
2507 // need to do a permission check since we're calling startActivity()
2508 // from the context of the phone app.
2509 enforceCallPermission();
2510
Jordan Liu1617b712019-07-10 15:06:26 -07002511 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 != AppOpsManager.MODE_ALLOWED) {
2513 return;
2514 }
2515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 String url = createTelUrl(number);
2519 if (url == null) {
2520 return;
2521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 boolean isValid = false;
2524 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2525 if (slist != null) {
2526 for (SubscriptionInfo subInfoRecord : slist) {
2527 if (subInfoRecord.getSubscriptionId() == subId) {
2528 isValid = true;
2529 break;
2530 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002531 }
Wink Saville08874612014-08-31 19:19:58 -07002532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 if (!isValid) {
2534 return;
2535 }
Wink Saville08874612014-08-31 19:19:58 -07002536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2538 intent.putExtra(SUBSCRIPTION_KEY, subId);
2539 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2540 mApp.startActivity(intent);
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 }
2545
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2549 }
2550
Wink Savilleb564aae2014-10-23 10:18:09 -07002551 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002552 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002553 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2554 }
2555
Wink Savilleb564aae2014-10-23 10:18:09 -07002556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558
2559 final long identity = Binder.clearCallingIdentity();
2560 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002561 Phone phone = getPhone(subId);
2562 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 checkSimPin.start();
2564 return checkSimPin.unlockSim(null, pin);
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002575 Phone phone = getPhone(subId);
2576 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 checkSimPuk.start();
2578 return checkSimPuk.unlockSim(puk, pin);
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002585 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 * a synchronous one.
2587 */
2588 private static class UnlockSim extends Thread {
2589
2590 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002591 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596
2597 // For replies from SimCard interface
2598 private Handler mHandler;
2599
2600 // For async handler to identify request type
2601 private static final int SUPPLY_PIN_COMPLETE = 100;
2602
Michele Berionne5e411512020-11-13 02:36:59 +00002603 UnlockSim(int phoneId, IccCard simCard) {
2604 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 mSimCard = simCard;
2606 }
2607
2608 @Override
2609 public void run() {
2610 Looper.prepare();
2611 synchronized (UnlockSim.this) {
2612 mHandler = new Handler() {
2613 @Override
2614 public void handleMessage(Message msg) {
2615 AsyncResult ar = (AsyncResult) msg.obj;
2616 switch (msg.what) {
2617 case SUPPLY_PIN_COMPLETE:
2618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002620 mRetryCount = msg.arg1;
2621 if (ar.exception != null) {
2622 if (ar.exception instanceof CommandException &&
2623 ((CommandException)(ar.exception)).getCommandError()
2624 == CommandException.Error.PASSWORD_INCORRECT) {
2625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002626 } //When UiccCardApp dispose,handle message and return exception
2627 else if (ar.exception instanceof CommandException &&
2628 ((CommandException) (ar.exception)).getCommandError()
2629 == CommandException.Error.ABORTED) {
2630 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002631 } else {
2632 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2633 }
2634 } else {
2635 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 mDone = true;
2638 UnlockSim.this.notifyAll();
2639 }
2640 break;
2641 }
2642 }
2643 };
2644 UnlockSim.this.notifyAll();
2645 }
2646 Looper.loop();
2647 }
2648
2649 /*
2650 * Use PIN or PUK to unlock SIM card
2651 *
2652 * If PUK is null, unlock SIM card with PIN
2653 *
2654 * If PUK is not null, unlock SIM card with PUK and set PIN code
2655 */
Wink Saville9de0f752013-10-22 19:04:03 -07002656 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657
2658 while (mHandler == null) {
2659 try {
2660 wait();
2661 } catch (InterruptedException e) {
2662 Thread.currentThread().interrupt();
2663 }
2664 }
2665 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2666
2667 if (puk == null) {
2668 mSimCard.supplyPin(pin, callback);
2669 } else {
2670 mSimCard.supplyPuk(puk, pin, callback);
2671 }
2672
2673 while (!mDone) {
2674 try {
2675 Log.d(LOG_TAG, "wait for done");
2676 wait();
2677 } catch (InterruptedException e) {
2678 // Restore the interrupted status
2679 Thread.currentThread().interrupt();
2680 }
2681 }
2682 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002683 int[] resultArray = new int[2];
2684 resultArray[0] = mResult;
2685 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002686
2687 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002688 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002689 }
2690
Wink Saville9de0f752013-10-22 19:04:03 -07002691 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693 }
2694
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002695 /**
2696 * This method has been removed due to privacy and stability concerns.
2697 */
2698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002700 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2701 return;
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
Nathan Harold1f889d82020-06-04 17:05:26 -07002704 @Override
2705 public void updateServiceLocationWithPackageName(String callingPackage) {
2706 mApp.getSystemService(AppOpsManager.class)
2707 .checkPackage(Binder.getCallingUid(), callingPackage);
2708
Nathan Haroldf096d982020-11-18 17:18:06 -08002709 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002710 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2711 // Callers targeting S have no business invoking this method.
2712 return;
2713 }
2714
2715 LocationAccessPolicy.LocationPermissionResult locationResult =
2716 LocationAccessPolicy.checkLocationPermission(mApp,
2717 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2718 .setCallingPackage(callingPackage)
2719 .setCallingFeatureId(null)
2720 .setCallingPid(Binder.getCallingPid())
2721 .setCallingUid(Binder.getCallingUid())
2722 .setMethod("updateServiceLocation")
2723 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2724 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2725 .build());
2726 // Apps that lack location permission have no business calling this method;
2727 // however, because no permission was declared in the public API, denials must
2728 // all be "soft".
2729 switch (locationResult) {
2730 case DENIED_HARD: /* fall through */
2731 case DENIED_SOFT:
2732 return;
2733 }
2734
2735 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002738 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002740 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002747 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002748 @Override
2749 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002750 return isRadioOnWithFeature(callingPackage, null);
2751 }
2752
2753
2754 @Override
2755 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2756 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2757 callingFeatureId);
2758 }
2759
2760 @Deprecated
2761 @Override
2762 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2763 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002771 return false;
2772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 return isRadioOnForSubscriber(subId);
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002780 }
2781
2782 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
2796 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002797 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
Wink Saville36469e72014-06-11 15:17:00 -07002799
Wink Savilleb564aae2014-10-23 10:18:09 -07002800 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
2814 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002815 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002816 }
2817
Wink Savilleb564aae2014-10-23 10:18:09 -07002818 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone == null) {
2825 return false;
2826 }
2827 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2828 toggleRadioOnOffForSubscriber(subId);
2829 }
2830 return true;
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
Wink Saville36469e72014-06-11 15:17:00 -07002835
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002836 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002837 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002838 /*
2839 * If any of the Radios are available, it will need to be
2840 * shutdown. So return true if any Radio is available.
2841 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2845 Phone phone = PhoneFactory.getPhone(i);
2846 if (phone != null && phone.isRadioAvailable()) return true;
2847 }
2848 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2849 return false;
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002852 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002853 }
2854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002856 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 enforceModifyPermission();
2858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2862 logv("Shutting down Phone " + i);
2863 shutdownRadioUsingPhoneId(i);
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 }
2868 }
2869
2870 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002871 Phone phone = PhoneFactory.getPhone(phoneId);
2872 if (phone != null && phone.isRadioAvailable()) {
2873 phone.shutdownRadio();
2874 }
2875 }
2876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2883 if (defaultPhone != null) {
2884 defaultPhone.setRadioPower(turnOn);
2885 return true;
2886 } else {
2887 loge("There's no default phone.");
2888 return false;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002892 }
Wink Saville36469e72014-06-11 15:17:00 -07002893 }
2894
Wink Savilleb564aae2014-10-23 10:18:09 -07002895 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 final Phone phone = getPhone(subId);
2901 if (phone != null) {
2902 phone.setRadioPower(turnOn);
2903 return true;
2904 } else {
2905 return false;
2906 }
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002912 /**
2913 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2914 * no reason to power it off. When any of the voters want to power it off, it will be turned
2915 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2916 * powering it off, and these radio off votes will be cleared.
2917 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2918 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2919 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2920 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2921 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2922 * check its vote.
2923 *
2924 * @param subId The subscription ID.
2925 * @param reason The reason for powering off radio.
2926 * @return true on success and false on failure.
2927 */
2928 public boolean requestRadioPowerOffForReason(int subId,
2929 @TelephonyManager.RadioPowerReason int reason) {
2930 enforceModifyPermission();
2931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 final Phone phone = getPhone(subId);
2935 if (phone != null) {
2936 phone.setRadioPowerForReason(false, reason);
2937 return true;
2938 } else {
2939 return false;
2940 }
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 /**
2947 * Remove the vote on powering off the radio for a reason, as requested by
2948 * {@link requestRadioPowerOffForReason}.
2949 *
2950 * @param subId The subscription ID.
2951 * @param reason The reason for powering off radio.
2952 * @return true on success and false on failure.
2953 */
2954 public boolean clearRadioPowerOffForReason(int subId,
2955 @TelephonyManager.RadioPowerReason int reason) {
2956 enforceModifyPermission();
2957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 final Phone phone = getPhone(subId);
2961 if (phone != null) {
2962 phone.setRadioPowerForReason(true, reason);
2963 return true;
2964 } else {
2965 return false;
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 /**
2973 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2974 *
2975 * @param subId The subscription ID.
2976 * @param callingPackage The package making the call.
2977 * @param callingFeatureId The feature in the package.
2978 * @return List of reasons for powering off radio.
2979 */
2980 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2981 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2982
2983 final long identity = Binder.clearCallingIdentity();
2984 List result = new ArrayList();
2985 try {
2986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2987 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2988 return result;
2989 }
2990
2991 final Phone phone = getPhone(subId);
2992 if (phone != null) {
2993 result.addAll(phone.getRadioPowerOffReasons());
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 return result;
2999 }
3000
Wink Saville36469e72014-06-11 15:17:00 -07003001 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003003 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 int subId = mSubscriptionController.getDefaultDataSubId();
3009 final Phone phone = getPhone(subId);
3010 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003011 phone.getDataSettingsManager().setDataEnabled(
3012 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 return true;
3014 } else {
3015 return false;
3016 }
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Wink Saville36469e72014-06-11 15:17:00 -07003022 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003023 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003024 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 int subId = mSubscriptionController.getDefaultDataSubId();
3030 final Phone phone = getPhone(subId);
3031 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003032 phone.getDataSettingsManager().setDataEnabled(
3033 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 return true;
3035 } else {
3036 return false;
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003044 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 final Phone phone = getPhone(subId);
3048 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003049 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 } else {
3051 return false;
3052 }
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
3058 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003059 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
pkanwarae03a6b2016-11-06 20:37:09 -08003062 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 enforceCallPermission();
3064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3068 return;
3069 }
3070 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3071 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
pkanwar32d516d2016-10-14 19:37:38 -07003075 };
3076
Wink Savilleb564aae2014-10-23 10:18:09 -07003077 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3083 return false;
3084 }
3085 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003091 /**
3092 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3093 * tag on getCallState Binder call.
3094 */
3095 @Deprecated
3096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003098 if (CompatChanges.isChangeEnabled(
3099 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3100 Binder.getCallingUid())) {
3101 // Do not allow this API to be called on API version 31+, it should only be
3102 // called on old apps using this Binder call directly.
3103 throw new SecurityException("This method can only be used for applications "
3104 + "targeting API version 30 or less.");
3105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003108 Phone phone = getPhone(getDefaultSubscription());
3109 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3110 PhoneConstantConversions.convertCallState(phone.getState());
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
3117 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3118 if (CompatChanges.isChangeEnabled(
3119 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3120 Binder.getCallingUid())) {
3121 // Check READ_PHONE_STATE for API version 31+
3122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3123 featureId, "getCallStateForSubscription")) {
3124 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3125 + "targeting API level 31+.");
3126 }
3127 }
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3132 PhoneConstantConversions.convertCallState(phone.getState());
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 }
3137
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003139 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003140 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3141 }
3142
3143 @Override
3144 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003149 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 } else {
3151 return PhoneConstantConversions.convertDataState(
3152 PhoneConstants.DataState.DISCONNECTED);
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003160 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003161 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3162 }
3163
3164 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003165 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003170 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 } else {
3172 return TelephonyManager.DATA_ACTIVITY_NONE;
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
3179 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003180 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003183
3184 LocationAccessPolicy.LocationPermissionResult locationResult =
3185 LocationAccessPolicy.checkLocationPermission(mApp,
3186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3187 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setCallingPid(Binder.getCallingPid())
3190 .setCallingUid(Binder.getCallingUid())
3191 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3194 .build());
3195 switch (locationResult) {
3196 case DENIED_HARD:
3197 throw new SecurityException("Not allowed to access cell location");
3198 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003199 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3200 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 }
3202
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003207 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003208 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Svetoslav64fad262015-04-14 14:35:21 -07003212 }
3213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003215 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003216 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3217 // registered cell info, so return a NULL country instead.
3218 final long identity = Binder.clearCallingIdentity();
3219 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003220 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3221 // Get default phone in this case.
3222 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3223 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003224 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003226 if (phone == null) return "";
3227 ServiceStateTracker sst = phone.getServiceStateTracker();
3228 if (sst == null) return "";
3229 LocaleTracker lt = sst.getLocaleTracker();
3230 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003231 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003235 }
3236
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003237 /**
3238 * This method was removed due to potential issues caused by performing partial
3239 * updates of service state, and lack of a credible use case.
3240 *
3241 * This has the ability to break the telephony implementation by disabling notification of
3242 * changes in device connectivity. DO NOT USE THIS!
3243 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003244 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 public void enableLocationUpdates() {
3246 mApp.enforceCallingOrSelfPermission(
3247 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003250 /**
3251 * This method was removed due to potential issues caused by performing partial
3252 * updates of service state, and lack of a credible use case.
3253 *
3254 * This has the ability to break the telephony implementation by disabling notification of
3255 * changes in device connectivity. DO NOT USE THIS!
3256 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 @Override
3258 public void disableLocationUpdates() {
3259 mApp.enforceCallingOrSelfPermission(
3260 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 @Override
3264 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003265 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3266 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003267 try {
3268 mApp.getSystemService(AppOpsManager.class)
3269 .checkPackage(Binder.getCallingUid(), callingPackage);
3270 } catch (SecurityException e) {
3271 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3272 throw e;
3273 }
3274
Nathan Haroldf096d982020-11-18 17:18:06 -08003275 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003276 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3277 throw new SecurityException(
3278 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3279 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003280
Jordan Liu1617b712019-07-10 15:06:26 -07003281 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3283 return null;
3284 }
Svetoslav64fad262015-04-14 14:35:21 -07003285
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003286 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003288 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003289 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290
Nathan Haroldf180aac2018-06-01 18:43:55 -07003291 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3292 for (CellInfo ci : info) {
3293 if (ci instanceof CellInfoGsm) {
3294 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3295 } else if (ci instanceof CellInfoWcdma) {
3296 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003299 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003302 private List<CellInfo> getCachedCellInfo() {
3303 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3304 for (Phone phone : PhoneFactory.getPhones()) {
3305 List<CellInfo> info = phone.getAllCellInfo();
3306 if (info != null) cellInfos.addAll(info);
3307 }
3308 return cellInfos;
3309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310
3311 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003312 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003314 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003315
3316 LocationAccessPolicy.LocationPermissionResult locationResult =
3317 LocationAccessPolicy.checkLocationPermission(mApp,
3318 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3319 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003320 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003321 .setCallingPid(Binder.getCallingPid())
3322 .setCallingUid(Binder.getCallingUid())
3323 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003324 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003325 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3326 .build());
3327 switch (locationResult) {
3328 case DENIED_HARD:
3329 throw new SecurityException("Not allowed to access cell info");
3330 case DENIED_SOFT:
3331 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003332 }
3333
Nathan Haroldf096d982020-11-18 17:18:06 -08003334 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003335 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3336 return getCachedCellInfo();
3337 }
3338
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003339 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3344 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003345 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003346 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 if (info != null) cellInfos.addAll(info);
3348 }
3349 return cellInfos;
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353 }
3354
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003355 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003356 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3357 String callingFeatureId) {
3358 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3359 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 }
3361
3362 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003363 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3364 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003365 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003366 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003367 }
3368
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003369 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3370 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003372 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003373
3374 LocationAccessPolicy.LocationPermissionResult locationResult =
3375 LocationAccessPolicy.checkLocationPermission(mApp,
3376 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3377 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003378 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003379 .setCallingPid(Binder.getCallingPid())
3380 .setCallingUid(Binder.getCallingUid())
3381 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003382 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3383 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003384 .build());
3385 switch (locationResult) {
3386 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003387 if (TelephonyPermissions
3388 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003389 // Safetynet logging for b/154934934
3390 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3391 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003392 throw new SecurityException("Not allowed to access cell info");
3393 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003394 if (TelephonyPermissions
3395 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003396 // Safetynet logging for b/154934934
3397 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3398 }
Nathan Harold5320c422019-05-09 10:26:08 -07003399 try {
3400 cb.onCellInfo(new ArrayList<CellInfo>());
3401 } catch (RemoteException re) {
3402 // Drop without consequences
3403 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 }
3406
Nathan Harolda939a962019-05-09 10:13:47 -07003407
3408 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003409 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3410
3411 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3412 }
3413
3414 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003415 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003416 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003421 Phone phone = getPhone(subId);
3422 if (phone == null) {
3423 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3424 } else {
3425 phone.setCellInfoListRate(rateInMillis, workSource);
3426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 }
3431
Shishir Agrawala9f32182016-04-12 12:00:16 -07003432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003433 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003434 Phone phone = PhoneFactory.getPhone(slotIndex);
3435 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 return null;
3437 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003439 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003440 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003441 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003442 return null;
3443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return phone.getImei();
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003451 }
3452
3453 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003454 public String getTypeAllocationCodeForSlot(int slotIndex) {
3455 Phone phone = PhoneFactory.getPhone(slotIndex);
3456 String tac = null;
3457 if (phone != null) {
3458 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003459 try {
3460 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3461 } catch (IndexOutOfBoundsException e) {
3462 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3463 return null;
3464 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003465 }
3466 return tac;
3467 }
3468
3469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003470 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003471 try {
3472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3473 } catch (SecurityException se) {
3474 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3475 throw new SecurityException("Package " + callingPackage + " does not belong to "
3476 + Binder.getCallingUid());
3477 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003478 Phone phone = PhoneFactory.getPhone(slotIndex);
3479 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003480 return null;
3481 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482
Jeff Davidson913390f2018-02-23 17:11:49 -08003483 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003484 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003485 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003486 return null;
3487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 return phone.getMeid();
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
Jack Yu2af8d712017-03-15 17:14:14 -07003495 }
3496
3497 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003498 public String getManufacturerCodeForSlot(int slotIndex) {
3499 Phone phone = PhoneFactory.getPhone(slotIndex);
3500 String manufacturerCode = null;
3501 if (phone != null) {
3502 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003503 try {
3504 manufacturerCode =
3505 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3506 } catch (IndexOutOfBoundsException e) {
3507 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3508 return null;
3509 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003510 }
3511 return manufacturerCode;
3512 }
3513
3514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3516 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 Phone phone = PhoneFactory.getPhone(slotIndex);
3518 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003519 return null;
3520 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 int subId = phone.getSubId();
3522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 mApp, subId, callingPackage, callingFeatureId,
3524 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003525 return null;
3526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 return phone.getDeviceSvn();
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003534 }
3535
fionaxu43304da2017-11-27 22:51:16 -08003536 @Override
3537 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
fionaxu43304da2017-11-27 22:51:16 -08003545 }
3546
3547 @Override
3548 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
3552 return phone == null ? null : phone.getCarrierName();
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
fionaxu43304da2017-11-27 22:51:16 -08003556 }
3557
calvinpanffe225e2018-11-01 19:43:06 +08003558 @Override
chen xu0026ca62019-03-06 15:28:50 -08003559 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003564 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
3568 }
3569
3570 @Override
chen xu0026ca62019-03-06 15:28:50 -08003571 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003575 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
chen xu651eec72018-11-11 19:03:44 -08003581 @Override
chen xu864e11c2018-12-06 22:10:03 -08003582 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3583 if (!isSubscriptionMccMnc) {
3584 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3585 }
chen xu651eec72018-11-11 19:03:44 -08003586 final Phone phone = PhoneFactory.getPhone(slotIndex);
3587 if (phone == null) {
3588 return TelephonyManager.UNKNOWN_CARRIER_ID;
3589 }
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003598 //
3599 // Internal helper methods.
3600 //
3601
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003602 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003603 * Make sure the caller is the calling package itself
3604 *
3605 * @throws SecurityException if the caller is not the calling package
3606 */
3607 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3608 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003609 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3610 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003611 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003612 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003613 } catch (PackageManager.NameNotFoundException e) {
3614 // packageUid is -1
3615 }
3616 if (packageUid != callingUid) {
3617 throw new SecurityException(message + ": Package " + callingPackage
3618 + " does not belong to " + callingUid);
3619 }
3620 }
3621
3622 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3624 *
3625 * @throws SecurityException if the caller does not have the required permission
3626 */
3627 private void enforceModifyPermission() {
3628 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3629 }
3630
Shuo Qian3b6ee772019-11-13 17:43:31 -08003631 private void enforceActiveEmergencySessionPermission() {
3632 mApp.enforceCallingOrSelfPermission(
3633 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3634 }
3635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 /**
3637 * Make sure the caller has the CALL_PHONE permission.
3638 *
3639 * @throws SecurityException if the caller does not have the required permission
3640 */
3641 private void enforceCallPermission() {
3642 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3643 }
3644
paulhu5a773602019-08-23 19:17:33 +08003645 private void enforceSettingsPermission() {
3646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003647 }
3648
Michele Berionne5e411512020-11-13 02:36:59 +00003649 private void enforceRebootPermission() {
3650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3651 }
3652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 private String createTelUrl(String number) {
3654 if (TextUtils.isEmpty(number)) {
3655 return null;
3656 }
3657
Jake Hambye994d462014-02-03 13:10:13 -08003658 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
Ihab Awadf9e92732013-12-05 18:02:52 -08003661 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3663 }
3664
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003665 private static void logv(String msg) {
3666 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3667 }
3668
Ihab Awadf9e92732013-12-05 18:02:52 -08003669 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3671 }
3672
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003673 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003674 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003675 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003676 }
3677
Sanket Padawe356d7632015-06-22 14:03:32 -07003678 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003679 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = PhoneFactory.getPhone(slotIndex);
3683 if (phone == null) {
3684 return PhoneConstants.PHONE_TYPE_NONE;
3685 } else {
3686 return phone.getPhoneType();
3687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003691 }
3692
3693 /**
3694 * Returns the CDMA ERI icon index to display
3695 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003697 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3698 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3699 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003700 }
3701
Sanket Padawe356d7632015-06-22 14:03:32 -07003702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003703 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3704 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 mApp, subId, callingPackage, callingFeatureId,
3707 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003708 return -1;
3709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 final Phone phone = getPhone(subId);
3714 if (phone != null) {
3715 return phone.getCdmaEriIconIndex();
3716 } else {
3717 return -1;
3718 }
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
3725 * Returns the CDMA ERI icon mode,
3726 * 0 - ON
3727 * 1 - FLASHING
3728 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003730 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3731 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3732 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003733 }
3734
Sanket Padawe356d7632015-06-22 14:03:32 -07003735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003736 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3737 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003739 mApp, subId, callingPackage, callingFeatureId,
3740 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003741 return -1;
3742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 final Phone phone = getPhone(subId);
3747 if (phone != null) {
3748 return phone.getCdmaEriIconMode();
3749 } else {
3750 return -1;
3751 }
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 }
3756
3757 /**
3758 * Returns the CDMA ERI text,
3759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3762 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003764 }
3765
Sanket Padawe356d7632015-06-22 14:03:32 -07003766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003770 mApp, subId, callingPackage, callingFeatureId,
3771 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 return null;
3773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 return phone.getCdmaEriText();
3780 } else {
3781 return null;
3782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 }
3787
3788 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003789 * Returns the CDMA MDN.
3790 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003792 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3794 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 return phone.getLine1Number();
3801 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 return null;
3804 }
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003807 }
3808 }
3809
3810 /**
3811 * Returns the CDMA MIN.
3812 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003813 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003814 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3816 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 final Phone phone = getPhone(subId);
3821 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3822 return phone.getCdmaMin();
3823 } else {
3824 return null;
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003828 }
3829 }
3830
Hall Liud892bec2018-11-30 14:51:45 -08003831 @Override
3832 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3833 INumberVerificationCallback callback, String callingPackage) {
3834 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3835 != PERMISSION_GRANTED) {
3836 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3837 }
3838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3839
3840 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3841 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003842 throw new SecurityException("Calling package must be configured in the device config: "
3843 + "calling package: " + callingPackage
3844 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003845 }
3846
3847 if (range == null) {
3848 throw new NullPointerException("Range must be non-null");
3849 }
3850
3851 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003852 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003853
3854 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3855 }
3856
Junda Liuca05d5d2014-08-14 22:36:34 -07003857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 * Returns true if CDMA provisioning needs to run.
3859 */
3860 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003863 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003867 }
3868
3869 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003870 * Sets the voice mail number of a given subId.
3871 */
3872 @Override
3873 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003874 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3875 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876
3877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3880 new Pair<String, String>(alphaTag, number), new Integer(subId));
3881 return success;
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003885 }
3886
Ta-wei Yen87c49842016-05-13 21:19:52 -07003887 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003888 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003890 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3891 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003892 if (!TextUtils.equals(callingPackage, systemDialer)) {
3893 throw new SecurityException("caller must be system dialer");
3894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3899 if (phoneAccountHandle == null) {
3900 return null;
3901 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003905 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003906 }
3907
3908 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003909 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3910 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 mApp, subId, callingPackage, callingFeatureId,
3914 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003915 return null;
3916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003918 final long identity = Binder.clearCallingIdentity();
3919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003924 }
3925
3926 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003927 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3928 VisualVoicemailSmsFilterSettings settings) {
3929 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003938 }
3939
3940 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003941 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003951 }
3952
3953 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003954 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3955 String callingPackage, int subId) {
3956 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003961 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003965 }
3966
3967 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003968 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003974 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003978 }
3979
3980 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003981 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3982 String callingAttributionTag, int subId, String number, int port, String text,
3983 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003985 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003986 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003987 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003988 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3989 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003990 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003991
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003992 /**
fionaxu0152e512016-11-14 13:36:14 -08003993 * Sets the voice activation state of a given subId.
3994 */
3995 @Override
3996 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3998 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999
4000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 final Phone phone = getPhone(subId);
4003 if (phone != null) {
4004 phone.setVoiceActivationState(activationState);
4005 } else {
4006 loge("setVoiceActivationState fails with invalid subId: " + subId);
4007 }
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004010 }
4011 }
4012
4013 /**
4014 * Sets the data activation state of a given subId.
4015 */
4016 @Override
4017 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4019 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 final Phone phone = getPhone(subId);
4024 if (phone != null) {
4025 phone.setDataActivationState(activationState);
4026 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004027 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028 }
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004031 }
4032 }
4033
4034 /**
4035 * Returns the voice activation state of a given subId.
4036 */
4037 @Override
4038 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040
fionaxu0152e512016-11-14 13:36:14 -08004041 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 if (phone != null) {
4045 return phone.getVoiceActivationState();
4046 } else {
4047 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4048 }
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004051 }
4052 }
4053
4054 /**
4055 * Returns the data activation state of a given subId.
4056 */
4057 @Override
4058 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060
fionaxu0152e512016-11-14 13:36:14 -08004061 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 if (phone != null) {
4065 return phone.getDataActivationState();
4066 } else {
4067 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4068 }
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004071 }
4072 }
4073
4074 /**
Wink Saville36469e72014-06-11 15:17:00 -07004075 * Returns the unread count of voicemails for a subId
4076 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004081 mApp, subId, callingPackage, callingFeatureId,
4082 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004083 return 0;
4084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 final Phone phone = getPhone(subId);
4088 if (phone != null) {
4089 return phone.getVoiceMessageCount();
4090 } else {
4091 return 0;
4092 }
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004096 }
4097
4098 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004099 * returns true, if the device is in a state where both voice and data
4100 * are supported simultaneously. This can change based on location or network condition.
4101 */
4102 @Override
4103 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
4107 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004111 }
4112
4113 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004114 * Send the dialer code if called from the current default dialer or the caller has
4115 * carrier privilege.
4116 * @param inputCode The dialer code to send
4117 */
4118 @Override
4119 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004122 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4123 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004124 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004125 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004126 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
fionaxu235cc5e2017-03-06 22:25:57 -08004135 }
4136
Pengquan Menga1bb6272018-09-06 09:59:22 -07004137 @Override
4138 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004140 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004141 mApp, subId, "getNetworkSelectionMode");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 if (!isActiveSubscription(subId)) {
4145 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4146 }
4147 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004150 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004151 }
4152
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004154 public boolean isInEmergencySmsMode() {
4155 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 for (Phone phone : PhoneFactory.getPhones()) {
4159 if (phone.isInEmergencySmsMode()) {
4160 return true;
4161 }
4162 }
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 return false;
4167 }
4168
shilu366312e2019-12-17 09:28:10 -08004169 /**
4170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param c The callback that will be used to send the result.
4173 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004175 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4176 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004178 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004179
4180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4182 "IMS not available on device.");
4183 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 final long token = Binder.clearCallingIdentity();
4185 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004186 int slotId = getSlotIndexOrException(subId);
4187 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004188
4189 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4190 if (controller != null) {
4191 ImsManager imsManager = controller.getImsManager(subId);
4192 if (imsManager != null) {
4193 imsManager.addRegistrationCallbackForSubscription(c, subId);
4194 } else {
4195 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4196 }
4197 } else {
4198 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4199 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (ImsException e) {
4201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 } finally {
4203 Binder.restoreCallingIdentity(token);
4204 }
4205 }
4206
shilu366312e2019-12-17 09:28:10 -08004207 /**
4208 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4209 * @param subId The subscription to use to check the configuration.
4210 * @param c The callback that will be used to send the result.
4211 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004213 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004214 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004215 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4217 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4218 }
Meng Wangafbc5852019-09-19 17:37:13 -07004219 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004220
Meng Wangafbc5852019-09-19 17:37:13 -07004221 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004222 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4223 if (controller != null) {
4224 ImsManager imsManager = controller.getImsManager(subId);
4225 if (imsManager != null) {
4226 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4227 } else {
4228 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4229 + "is inactive, ignoring unregister.");
4230 // If the ImsManager is not valid, just return, since the callback
4231 // will already have been removed internally.
4232 }
4233 }
Meng Wangafbc5852019-09-19 17:37:13 -07004234 } finally {
4235 Binder.restoreCallingIdentity(token);
4236 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 }
4238
Brad Ebingera34a6c22019-10-22 17:36:18 -07004239 /**
4240 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4241 */
4242 @Override
4243 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4244 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4247 "IMS not available on device.");
4248 }
4249 final long token = Binder.clearCallingIdentity();
4250 try {
4251 Phone phone = getPhone(subId);
4252 if (phone == null) {
4253 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4254 + subId + "'");
4255 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4256 }
4257 phone.getImsRegistrationState(regState -> {
4258 try {
4259 consumer.accept((regState == null)
4260 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4261 } catch (RemoteException e) {
4262 // Ignore if the remote process is no longer available to call back.
4263 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4264 }
4265 });
4266 } finally {
4267 Binder.restoreCallingIdentity(token);
4268 }
4269 }
4270
4271 /**
4272 * Get the transport type for the IMS service registration state.
4273 */
4274 @Override
4275 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004277 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004278 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4279 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4280 "IMS not available on device.");
4281 }
4282 final long token = Binder.clearCallingIdentity();
4283 try {
4284 Phone phone = getPhone(subId);
4285 if (phone == null) {
4286 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4287 + subId + "'");
4288 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4289 }
4290 phone.getImsRegistrationTech(regTech -> {
4291 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4292 int regTechConverted = (regTech == null)
4293 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4294 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4295 regTechConverted);
4296 try {
4297 consumer.accept(regTechConverted);
4298 } catch (RemoteException e) {
4299 // Ignore if the remote process is no longer available to call back.
4300 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4301 }
4302 });
4303 } finally {
4304 Binder.restoreCallingIdentity(token);
4305 }
4306 }
4307
shilu366312e2019-12-17 09:28:10 -08004308 /**
4309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 * @param c The callback that will be used to send the result.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004314 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4315 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004317 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004318 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4320 "IMS not available on device.");
4321 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 final long token = Binder.clearCallingIdentity();
4323 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004324 int slotId = getSlotIndexOrException(subId);
4325 verifyImsMmTelConfiguredOrThrow(slotId);
4326 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004327 } catch (ImsException e) {
4328 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 } finally {
4330 Binder.restoreCallingIdentity(token);
4331 }
4332 }
4333
shilu366312e2019-12-17 09:28:10 -08004334 /**
4335 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4336 * @param subId The subscription to use to check the configuration.
4337 * @param c The callback that will be used to send the result.
4338 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004340 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004341 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004342 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004343 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4344 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4345 }
Meng Wangafbc5852019-09-19 17:37:13 -07004346
4347 final long token = Binder.clearCallingIdentity();
4348 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004349 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004350 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004351 } catch (ImsException e) {
4352 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4353 + "is inactive, ignoring unregister.");
4354 // If the subscription is no longer active, just return, since the callback
4355 // will already have been removed internally.
4356 } finally {
4357 Binder.restoreCallingIdentity(token);
4358 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 }
4360
4361 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004362 public boolean isCapable(int subId, int capability, int regTech) {
4363 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 final long token = Binder.clearCallingIdentity();
4365 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004366 int slotId = getSlotIndexOrException(subId);
4367 verifyImsMmTelConfiguredOrThrow(slotId);
4368 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4369 } catch (com.android.ims.ImsException e) {
4370 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4371 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004373 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4374 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(token);
4377 }
4378 }
4379
4380 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004381 public boolean isAvailable(int subId, int capability, int regTech) {
4382 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 final long token = Binder.clearCallingIdentity();
4384 try {
4385 Phone phone = getPhone(subId);
4386 if (phone == null) return false;
4387 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004388 } catch (com.android.ims.ImsException e) {
4389 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4390 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 } finally {
4392 Binder.restoreCallingIdentity(token);
4393 }
4394 }
4395
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004396 /**
4397 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4398 * subscription.
4399 * @param subId The subscription to use to check the configuration.
4400 * @param callback The callback that will be used to send the result.
4401 * @param capability The MmTelFeature capability that will be used to send the result.
4402 * @param transportType The transport type of the MmTelFeature capability.
4403 */
4404 @Override
4405 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4406 int transportType) {
4407 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004408 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4409 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4410 "IMS not available on device.");
4411 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004412 final long token = Binder.clearCallingIdentity();
4413 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004414 int slotId = getSlotIndex(subId);
4415 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4416 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4417 + subId + "'");
4418 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4419 }
4420 verifyImsMmTelConfiguredOrThrow(slotId);
4421 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4422 transportType, aBoolean -> {
4423 try {
4424 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4425 } catch (RemoteException e) {
4426 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4427 + "running. Ignore");
4428 }
4429 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004432 } finally {
4433 Binder.restoreCallingIdentity(token);
4434 }
4435 }
4436
shilu366312e2019-12-17 09:28:10 -08004437 /**
4438 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4439 * @param subId The subscription to use to check the configuration.
4440 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 @Override
4442 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004444 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004445
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 final long token = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004449 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004451 } catch (ImsException e) {
4452 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 } finally {
4454 Binder.restoreCallingIdentity(token);
4455 }
4456 }
4457
4458 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004459 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004461 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004465 // This setting doesn't require an active ImsService connection, so do not verify. The
4466 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004468 } catch (ImsException e) {
4469 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
shilu366312e2019-12-17 09:28:10 -08004475 /**
4476 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4477 * @param subId The subscription to use to check the configuration.
4478 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004480 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004481 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004482 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 final long identity = Binder.clearCallingIdentity();
4484 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004486 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (ImsException e) {
4489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
4493 }
4494
4495 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004496 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004498 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 final long identity = Binder.clearCallingIdentity();
4500 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004502 // This setting doesn't require an active ImsService connection, so do not verify. The
4503 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004505 } catch (ImsException e) {
4506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
4510 }
4511
shilu366312e2019-12-17 09:28:10 -08004512 /**
4513 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4514 * @param subId The subscription to use to check the configuration.
4515 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 @Override
4517 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004518 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004519 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004523 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (ImsException e) {
4526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
4530 }
4531
4532 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004533 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004535 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004539 // This setting doesn't require an active ImsService connection, so do not verify. The
4540 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
shilu366312e2019-12-17 09:28:10 -08004549 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004550 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4551 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4552 * @param subId The subscription to use to check the configuration.
4553 */
4554 @Override
4555 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004556 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004557 mApp, subId, "isCrossSimCallingEnabledByUser");
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004561 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004563 } catch (ImsException e) {
4564 throw new ServiceSpecificException(e.getCode());
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
4570 /**
4571 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4572 * Requires MODIFY_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4575 * false otherwise
4576 */
4577 @Override
4578 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4580 "setCrossSimCallingEnabled");
4581 final long identity = Binder.clearCallingIdentity();
4582 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004584 // This setting doesn't require an active ImsService connection, so do not verify. The
4585 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004586 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004587 } catch (ImsException e) {
4588 throw new ServiceSpecificException(e.getCode());
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
4592 }
4593
4594 /**
shilu366312e2019-12-17 09:28:10 -08004595 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4596 * @param subId The subscription to use to check the configuration.
4597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004599
Brad Ebinger35c841c2018-10-01 10:40:55 -07004600 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004602 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 final long identity = Binder.clearCallingIdentity();
4604 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004605 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004606 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004607 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004608 } catch (ImsException e) {
4609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
4613 }
4614
4615 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004616 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004618 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 final long identity = Binder.clearCallingIdentity();
4620 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004621 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004622 // This setting doesn't require an active ImsService connection, so do not verify. The
4623 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004624 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004625 } catch (ImsException e) {
4626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
4632 @Override
4633 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4635 "setVoWiFiNonPersistent");
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004639 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (ImsException e) {
4642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
shilu366312e2019-12-17 09:28:10 -08004648 /**
4649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4650 * @param subId The subscription to use to check the configuration.
4651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 @Override
4653 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004655 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 final long identity = Binder.clearCallingIdentity();
4657 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004658 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004659 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004660 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (ImsException e) {
4662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
4669 public void setVoWiFiModeSetting(int subId, int mode) {
4670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4671 "setVoWiFiModeSetting");
4672 final long identity = Binder.clearCallingIdentity();
4673 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004675 // This setting doesn't require an active ImsService connection, so do not verify. The
4676 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (ImsException e) {
4679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
4686 public int getVoWiFiRoamingModeSetting(int subId) {
4687 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
4701 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4703 "setVoWiFiRoamingModeSetting");
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
4717 @Override
4718 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4720 "setRttCapabilityEnabled");
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004723 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004724 // This setting doesn't require an active ImsService connection, so do not verify. The
4725 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004727 } catch (ImsException e) {
4728 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 }
4733
shilu366312e2019-12-17 09:28:10 -08004734 /**
4735 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4736 * @param subId The subscription to use to check the configuration.
4737 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 @Override
4739 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004740 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004741 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 final long identity = Binder.clearCallingIdentity();
4743 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004745 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004747 } catch (ImsException e) {
4748 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 @Override
4755 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4756 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004757
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004760 if (!isImsAvailableOnDevice()) {
4761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4762 "IMS not available on device.");
4763 }
4764 int slotId = getSlotIndexOrException(subId);
4765 verifyImsMmTelConfiguredOrThrow(slotId);
4766 ImsManager.getInstance(mApp, slotId)
4767 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004768 } catch (ImsException e) {
4769 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
4773 }
4774
4775 @Override
4776 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4777 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004778
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4782 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004783 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004784 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004785 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004787 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4788 + "is inactive, ignoring unregister.");
4789 // If the subscription is no longer active, just return, since the callback will already
4790 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
4794 }
4795
joonhunshincffb7fc2021-11-28 07:32:01 +00004796 @Override
4797 public void registerFeatureProvisioningChangedCallback(int subId,
4798 IFeatureProvisioningCallback callback) {
4799 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4800 mApp, subId, "registerFeatureProvisioningChangedCallback");
4801
4802 final long identity = Binder.clearCallingIdentity();
4803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4805 }
4806
joonhunshin91bc1952022-04-29 08:47:15 +00004807 try {
4808 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4809 if (controller == null) {
4810 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4811 "Device does not support IMS");
4812 }
4813 controller.addFeatureProvisioningChangedCallback(subId, callback);
4814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004817 }
4818
4819 @Override
4820 public void unregisterFeatureProvisioningChangedCallback(int subId,
4821 IFeatureProvisioningCallback callback) {
4822 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4823 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4824
4825 final long identity = Binder.clearCallingIdentity();
4826 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4827 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4828 }
4829
joonhunshin91bc1952022-04-29 08:47:15 +00004830 try {
4831 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4832 if (controller == null) {
4833 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4834 return;
4835 }
4836 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004840 }
allenwtsu99c623b2020-01-03 18:24:23 +08004841
4842 private void checkModifyPhoneStatePermission(int subId, String message) {
4843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 message);
4845 }
4846
allenwtsu99c623b2020-01-03 18:24:23 +08004847 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004849 boolean isProvisioned) {
4850 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4851
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004854 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4855 if (controller == null) {
4856 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4857 return;
4858 }
4859 controller.setRcsProvisioningStatusForCapability(
4860 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
allenwtsu99c623b2020-01-03 18:24:23 +08004864 }
4865
4866
4867 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004868 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4869 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4870 mApp, subId, "getRcsProvisioningStatusForCapability");
4871
allenwtsu99c623b2020-01-03 18:24:23 +08004872 final long identity = Binder.clearCallingIdentity();
4873 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004874 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4875 if (controller == null) {
4876 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4877
4878 // device does not support IMS, this method will return true always.
4879 return true;
4880 }
4881 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004887 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4889 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004890 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004891
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004894 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4895 if (controller == null) {
4896 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4897 return;
4898 }
4899 controller.setImsProvisioningStatusForCapability(
4900 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004908 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4909 mApp, subId, "getProvisioningStatusForCapability");
4910
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004913 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4914 if (controller == null) {
4915 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916
joonhunshin91bc1952022-04-29 08:47:15 +00004917 // device does not support IMS, this method will return true always.
4918 return true;
4919 }
4920 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
4926 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004927 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4928 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4929 mApp, subId, "isProvisioningRequiredForCapability");
4930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004933 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4934 if (controller == null) {
4935 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4936
4937 // device does not support IMS, this method will return false
4938 return false;
4939 }
4940 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004941 } finally {
4942 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 }
4945
4946 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4948 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4949 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950
joonhunshincffb7fc2021-11-28 07:32:01 +00004951 final long identity = Binder.clearCallingIdentity();
4952 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004953 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4954 if (controller == null) {
4955 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4956
4957 // device does not support IMS, this method will return false
4958 return false;
4959 }
4960 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 }
4965
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4969 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4970 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004971 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4972 mApp, subId, "getImsProvisioningInt");
4973
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 int slotId = getSlotIndex(subId);
4978 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4979 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4980 + subId + "' for key:" + key);
4981 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4982 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004983
joonhunshin91bc1952022-04-29 08:47:15 +00004984 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4985 if (controller == null) {
4986 loge("getImsProvisioningInt: Device does not support IMS");
4987
4988 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4989 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4990 }
4991 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004992 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4993 return retVal;
4994 }
4995
calvinpanb5a34062021-02-08 19:59:36 +08004996 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4999 + subId + "' for key:" + key);
5000 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
5006 @Override
5007 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5009 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5010 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5012 mApp, subId, "getImsProvisioningString");
5013
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005017 int slotId = getSlotIndex(subId);
5018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5019 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5020 + subId + "' for key:" + key);
5021 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5022 }
calvinpanb5a34062021-02-08 19:59:36 +08005023 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005024 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5026 + subId + "' for key:" + key);
5027 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
5033 @Override
5034 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5036 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5037 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5039 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005040
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005041 final long identity = Binder.clearCallingIdentity();
5042 try {
5043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005044 int slotId = getSlotIndex(subId);
5045 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5046 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5047 + subId + "' for key:" + key);
5048 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5049 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005050
joonhunshin91bc1952022-04-29 08:47:15 +00005051 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5052 if (controller == null) {
5053 loge("setImsProvisioningInt: Device does not support IMS");
5054
5055 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5056 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5057 }
5058 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005059 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5060 return retVal;
5061 }
5062
calvinpanb5a34062021-02-08 19:59:36 +08005063 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5064 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005065 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005066 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
5071 }
5072
5073 @Override
5074 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5076 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5077 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5079 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005083 int slotId = getSlotIndex(subId);
5084 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5085 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5086 + subId + "' for key:" + key);
5087 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5088 }
calvinpanb5a34062021-02-08 19:59:36 +08005089 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5090 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005092 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005093 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
Brad Ebinger919631e2021-06-02 17:46:35 -07005099 /**
5100 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5101 * for the given slot ID or no ImsResolver instance has been created.
5102 * @param slotId The slot ID that the IMS service is created for.
5103 * @throws ImsException If there is no ImsService configured for this slot.
5104 */
5105 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5106 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5107 ImsFeature.FEATURE_MMTEL)) {
5108 throw new ImsException("This subscription does not support MMTEL over IMS",
5109 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5110 }
5111 }
5112
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005113 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 int slotId = SubscriptionManager.getSlotIndex(subId);
5115 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005116 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5117 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 }
5119 return slotId;
5120 }
5121
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005122 private int getSlotIndex(int subId) {
5123 int slotId = SubscriptionManager.getSlotIndex(subId);
5124 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5125 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5126 }
5127 return slotId;
5128 }
5129
Wink Saville36469e72014-06-11 15:17:00 -07005130 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005131 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005132 */
5133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005134 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5135 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005136 try {
5137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5138 } catch (SecurityException se) {
5139 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5140 throw new SecurityException("Package " + callingPackage + " does not belong to "
5141 + Binder.getCallingUid());
5142 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005143 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005144 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005146 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005147 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 mApp, subId, callingPackage, callingFeatureId,
5149 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5151 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 final Phone phone = getPhone(subId);
5156 if (phone != null) {
5157 return phone.getServiceState().getDataNetworkType();
5158 } else {
5159 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5160 }
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 }
5165
5166 /**
5167 * Returns the data network type
5168 */
5169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005170 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005171 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5172 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005173 }
5174
5175 /**
5176 * Returns the data network type for a subId
5177 */
5178 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005179 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5180 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005181 String functionName = "getDataNetworkTypeForSubscriber";
5182 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5183 mApp, functionName)) {
5184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5185 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5186 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5187 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005188 }
5189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 final Phone phone = getPhone(subId);
5193 if (phone != null) {
5194 return phone.getServiceState().getDataNetworkType();
5195 } else {
5196 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5197 }
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005201 }
5202
5203 /**
Wink Saville36469e72014-06-11 15:17:00 -07005204 * Returns the Voice network type for a subId
5205 */
5206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005207 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5208 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005209 String functionName = "getVoiceNetworkTypeForSubscriber";
5210 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5211 mApp, functionName)) {
5212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5213 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5214 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5215 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005216 }
5217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 final Phone phone = getPhone(subId);
5221 if (phone != null) {
5222 return phone.getServiceState().getVoiceNetworkType();
5223 } else {
5224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5225 }
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005229 }
5230
5231 /**
5232 * @return true if a ICC card is present
5233 */
5234 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005235 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005236 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5237 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005238 }
5239
5240 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005242 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 final Phone phone = PhoneFactory.getPhone(slotIndex);
5248 if (phone != null) {
5249 return phone.getIccCard().hasIccCard();
5250 } else {
5251 return false;
5252 }
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005256 }
5257
5258 /**
5259 * Return if the current radio is LTE on CDMA. This
5260 * is a tri-state return value as for a period of time
5261 * the mode may be unknown.
5262 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005263 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005264 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005265 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005266 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005268 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5269 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5270 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005271 }
5272
Sanket Padawe356d7632015-06-22 14:03:32 -07005273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005274 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5275 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005276 try {
5277 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5278 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005279 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5280 }
5281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 final Phone phone = getPhone(subId);
5285 if (phone == null) {
5286 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5287 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005288 return TelephonyProperties.lte_on_cdma_device()
5289 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 }
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005293 }
Wink Saville36469e72014-06-11 15:17:00 -07005294 }
5295
Wink Saville36469e72014-06-11 15:17:00 -07005296 /**
5297 * {@hide}
5298 * Returns Default subId, 0 in the case of single standby.
5299 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005300 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005301 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005302 }
5303
Shishir Agrawala9f32182016-04-12 12:00:16 -07005304 private int getSlotForDefaultSubscription() {
5305 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5306 }
5307
Wink Savilleb564aae2014-10-23 10:18:09 -07005308 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005309 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005310 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005311
Pengquan Menge92a50d2018-09-21 15:54:48 -07005312 private boolean isActiveSubscription(int subId) {
5313 return mSubscriptionController.isActiveSubId(subId);
5314 }
5315
Ihab Awadf2177b72013-11-25 13:33:23 -08005316 /**
5317 * @see android.telephony.TelephonyManager.WifiCallingChoices
5318 */
5319 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005322 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5324 getWhenToMakeWifiCallsDefaultPreference());
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005328 }
5329
5330 /**
5331 * @see android.telephony.TelephonyManager.WifiCallingChoices
5332 */
5333 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005337 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005342 }
5343
Sailesh Nepald1e68152013-12-12 19:08:02 -08005344 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005345 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005346 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005347 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005348
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005349 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5350 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5351 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005352 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005353 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5354 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005355 }
5356 return PhoneFactory.getPhone(phoneId);
5357 }
5358
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005360 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005361 @NonNull IccLogicalChannelRequest request) {
5362 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5363 /*message=*/ "iccOpenLogicalChannel");
5364
5365 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5366 // Verify that the callingPackage in the request belongs to the calling UID
5367 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5368
5369 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005371
Rambo Wanga1782702021-11-10 20:15:19 -08005372 private Phone getPhoneFromValidIccLogicalChannelRequest(
5373 @NonNull IccLogicalChannelRequest request, String message) {
5374 Phone phone;
5375 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, request.subId, message);
5378 phone = getPhoneFromSubId(request.subId);
5379 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5380 enforceModifyPermission();
5381 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5382 } else {
5383 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005384 }
Rambo Wanga1782702021-11-10 20:15:19 -08005385 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005386 }
5387
5388 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005389 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5395 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005396 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5397 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 loge("The calling package is not allowed to access ISD-R.");
5399 throw new SecurityException(
5400 "The calling package is not allowed to access ISD-R.");
5401 }
Derek Tan740e1672017-06-27 14:56:27 -07005402 }
Derek Tan740e1672017-06-27 14:56:27 -07005403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005405 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5406 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 return response;
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005411 }
5412
5413 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005414 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5415 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5416 /*message=*/"iccCloseLogicalChannel");
5417
5418 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5419
5420 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005422
Rambo Wanga1782702021-11-10 20:15:19 -08005423 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5424 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005425 // before this feature is enabled, this API should only return false if
5426 // the operation fails instead of throwing runtime exception for
5427 // backward-compatibility.
5428 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5429 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005432 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005433 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 }
Chen Xue9d737e2022-01-01 23:41:31 -08005435 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005436 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005437 Boolean success = false;
5438 if (result instanceof RuntimeException) {
5439 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005440 if (shouldThrowExceptionOnFailure) {
5441 throw (RuntimeException) result;
5442 } else {
5443 return false;
5444 }
Chen Xue9d737e2022-01-01 23:41:31 -08005445 } else if (result instanceof Boolean) {
5446 success = (Boolean) result;
5447 } else {
5448 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5449 }
Rambo Wanga1782702021-11-10 20:15:19 -08005450 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 return success;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 }
5456
5457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005458 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005459 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005462 if (DBG) {
5463 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5464 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5465 + p3 + " data=" + data);
5466 }
5467 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5468 command, p1, p2, p3, data);
5469 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005470
Jordan Liu4c733742019-02-28 12:03:40 -08005471 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5473 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005474 enforceModifyPermission();
5475 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005476 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5477 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5478 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005479 }
5480 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005481 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5482 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005483 }
5484
5485 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5486 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005489 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 return "";
5491 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005494 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5495 null /* workSource */);
5496 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 // Append the returned status code to the end of the response payload.
5499 String s = Integer.toHexString(
5500 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5501 if (response.payload != null) {
5502 s = IccUtils.bytesToHexString(response.payload) + s;
5503 }
5504 return s;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005507 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005508 }
Jake Hambye994d462014-02-03 13:10:13 -08005509
Evan Charltonc66da362014-05-16 14:06:40 -07005510 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005511 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5512 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005516 if (DBG) {
5517 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5518 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5519 }
5520 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5521 cla, command, p1, p2, p3, data);
5522 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005523
Jordan Liu4c733742019-02-28 12:03:40 -08005524 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005525 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5526 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005527 enforceModifyPermission();
5528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5529 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005530 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5531 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5532 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005533 }
5534
5535 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005536 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5537 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005538 }
5539
5540 // open APDU basic channel assuming the caller has sufficient permissions
5541 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5542 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5546 && TextUtils.equals(ISDR_AID, data)) {
5547 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005548 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5549 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 if (bestComponent == null
5551 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5552 loge("The calling package is not allowed to select ISD-R.");
5553 throw new SecurityException(
5554 "The calling package is not allowed to select ISD-R.");
5555 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005556 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005559 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5560 null /* workSource */);
5561 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 // Append the returned status code to the end of the response payload.
5564 String s = Integer.toHexString(
5565 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5566 if (response.payload != null) {
5567 s = IccUtils.bytesToHexString(response.payload) + s;
5568 }
5569 return s;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005572 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 }
5574
5575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005576 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005577 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (DBG) {
5584 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5585 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5586 }
5587
5588 IccIoResult response =
5589 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5590 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5591 subId);
5592
5593 if (DBG) {
5594 log("Exchange SIM_IO [R]" + response);
5595 }
5596
5597 byte[] result = null;
5598 int length = 2;
5599 if (response.payload != null) {
5600 length = 2 + response.payload.length;
5601 result = new byte[length];
5602 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5603 } else {
5604 result = new byte[length];
5605 }
5606
5607 result[length - 1] = (byte) response.sw2;
5608 result[length - 2] = (byte) response.sw1;
5609 return result;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005612 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005613 }
5614
Nathan Haroldb3014052017-01-25 15:57:32 -08005615 /**
5616 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5617 * on a particular subscription
5618 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005619 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5620 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005622 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005623 return null;
5624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 if (appType != TelephonyManager.APPTYPE_USIM
5629 && appType != TelephonyManager.APPTYPE_SIM) {
5630 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5631 return null;
5632 }
5633 Object response = sendRequest(
5634 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5635 if (response instanceof String[]) {
5636 return (String[]) response;
5637 }
yincheng zhao2737e882019-09-06 17:06:54 -07005638 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005640 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005643 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005644 }
5645
yincheng zhao2737e882019-09-06 17:06:54 -07005646 /**
5647 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5648 * subscription.
5649 *
5650 * @param subId the id of the subscription.
5651 * @param appType the uicc app type, must be USIM or SIM.
5652 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5653 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005654 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005655 * @return number of fplmns that is successfully written to the SIM.
5656 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5658 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, subId, "setForbiddenPlmns");
5661
yincheng zhao2737e882019-09-06 17:06:54 -07005662 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5663 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5664 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5665 }
5666 if (fplmns == null) {
5667 throw new IllegalArgumentException("Fplmn List provided is null");
5668 }
5669 for (String fplmn : fplmns) {
5670 if (!CellIdentity.isValidPlmn(fplmn)) {
5671 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5672 }
5673 }
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Object response = sendRequest(
5677 CMD_SET_FORBIDDEN_PLMNS,
5678 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5679 subId);
5680 return (int) response;
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
5684 }
5685
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005686 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005687 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5694 if (response.payload == null) {
5695 return "";
5696 }
Evan Charltonc66da362014-05-16 14:06:40 -07005697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 // Append the returned status code to the end of the response payload.
5699 String s = Integer.toHexString(
5700 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5701 s = IccUtils.bytesToHexString(response.payload) + s;
5702 return s;
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Evan Charltonc66da362014-05-16 14:06:40 -07005706 }
5707
Jake Hambye994d462014-02-03 13:10:13 -08005708 /**
5709 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5710 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5711 *
5712 * @param itemID the ID of the item to read
5713 * @return the NV item as a String, or null on error.
5714 */
5715 @Override
5716 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005717 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005724 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5726 return value;
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Jake Hambye994d462014-02-03 13:10:13 -08005730 }
5731
5732 /**
5733 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5734 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5735 *
5736 * @param itemID the ID of the item to read
5737 * @param itemValue the value to write, as a String
5738 * @return true on success; false on any failure
5739 */
5740 @Override
5741 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005742 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5744 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5749 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005750 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5752 return success;
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Jake Hambye994d462014-02-03 13:10:13 -08005756 }
5757
5758 /**
5759 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5760 * Used for device configuration by some CDMA operators.
5761 *
5762 * @param preferredRoamingList byte array containing the new PRL
5763 * @return true on success; false on any failure
5764 */
5765 @Override
5766 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5768 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5773 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5774 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5775 return success;
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Jake Hambye994d462014-02-03 13:10:13 -08005779 }
5780
5781 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005782 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005783 * Used for device configuration by some CDMA operators.
5784 *
chen xu6dac5ab2018-10-26 17:39:23 -07005785 * @param slotIndex - device slot.
5786 *
Jake Hambye994d462014-02-03 13:10:13 -08005787 * @return true on success; false on any failure
5788 */
5789 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005790 public boolean resetModemConfig(int slotIndex) {
5791 Phone phone = PhoneFactory.getPhone(slotIndex);
5792 if (phone != null) {
5793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5794 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
chen xu6dac5ab2018-10-26 17:39:23 -07005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5799 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5800 return success;
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 }
chen xu6dac5ab2018-10-26 17:39:23 -07005805 return false;
5806 }
5807
5808 /**
5809 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5810 *
5811 * @param slotIndex - device slot.
5812 *
5813 * @return true on success; false on any failure
5814 */
5815 @Override
5816 public boolean rebootModem(int slotIndex) {
5817 Phone phone = PhoneFactory.getPhone(slotIndex);
5818 if (phone != null) {
5819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5820 mApp, phone.getSubId(), "rebootModem");
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5825 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5826 return success;
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
5830 }
5831 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005832 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005833
Brad Ebinger51f743a2017-01-23 13:50:20 -08005834 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005835 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5836 * {@link #disableIms(int)}.
5837 * @param slotIndex device slot.
5838 */
5839 public void resetIms(int slotIndex) {
5840 enforceModifyPermission();
5841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 if (mImsResolver == null) {
5845 // may happen if the does not support IMS.
5846 return;
5847 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005848 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005855 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5856 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005857 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005858 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return;
5866 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005871 }
5872
5873 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005874 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5875 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005876 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005877 public void disableIms(int slotId) {
5878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005883 // may happen if the device does not support IMS.
5884 return;
5885 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005890 }
5891
5892 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005893 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5894 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005895 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005896 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005897 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005902 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005903 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5904 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005905 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005906 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005910 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005911 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005912 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5913 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005914 @Override
5915 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005916 enforceModifyPermission();
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005921 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
5925 }
5926
5927 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005928 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005929 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005930 */
5931 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005937 // may happen if the device does not support IMS.
5938 return null;
5939 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005944 }
5945
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005946 /**
5947 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005948 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005949 */
5950 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005956 // may happen if the device does not support IMS.
5957 return null;
5958 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005959 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005963 }
5964
Brad Ebinger884c07b2018-02-15 16:17:40 -08005965 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 * Sets the ImsService Package Name that Telephony will bind to.
5967 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005968 * @param slotIndex the slot ID that the ImsService should bind for.
5969 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 * @param featureTypes An integer array of feature types associated with a packageName.
5972 * @param packageName The name of the package that the current configuration will be replaced
5973 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005974 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005975 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005976 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5977 int[] featureTypes, String packageName) {
5978 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5981 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005987 // may happen if the device does not support IMS.
5988 return false;
5989 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 Map<Integer, String> featureConfig = new HashMap<>();
5991 for (int featureType : featureTypes) {
5992 featureConfig.put(featureType, packageName);
5993 }
5994 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5995 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005999 }
6000
6001 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006002 * Clears any carrier ImsService overrides for the slot index specified that were previously
6003 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6004 *
6005 * This should only be used for testing.
6006 *
6007 * @param slotIndex the slot ID that the ImsService should bind for.
6008 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6009 */
6010 @Override
6011 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6012 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6014 "clearCarrierImsServiceOverride");
6015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6016 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6017 "clearCarrierImsServiceOverride");
6018
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 if (mImsResolver == null) {
6022 // may happen if the device does not support IMS.
6023 return false;
6024 }
6025 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
6029 }
6030
6031 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006033 *
6034 * @param slotId The slot that the ImsService is associated with.
6035 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6036 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006038 * @return the package name of the ImsService configuration.
6039 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6041 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006042 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006043 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006044 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6046 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006051 // may happen if the device does not support IMS.
6052 return "";
6053 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006054 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6056 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006060 }
6061
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006062 /**
6063 * Get the MmTelFeature state associated with the requested subscription id.
6064 * @param subId The subscription that the MmTelFeature is associated with.
6065 * @param callback A callback with an integer containing the
6066 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6067 */
6068 @Override
6069 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6070 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006071 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6073 "IMS not available on device.");
6074 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006075 final long token = Binder.clearCallingIdentity();
6076 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006077 int slotId = getSlotIndex(subId);
6078 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6079 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6080 + subId + "'");
6081 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6082 }
6083 verifyImsMmTelConfiguredOrThrow(slotId);
6084 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6085 try {
6086 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6087 } catch (RemoteException e) {
6088 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6089 + "Ignore");
6090 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006091 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006092 } catch (ImsException e) {
6093 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006094 } finally {
6095 Binder.restoreCallingIdentity(token);
6096 }
6097 }
6098
Daniel Brightbb5840b2021-01-12 15:48:18 -08006099 /**
6100 * Sets the ims registration state on all valid {@link Phone}s.
6101 */
6102 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006107 // NOTE: Before S, this method only set the default phone.
6108 for (final Phone phone : PhoneFactory.getPhones()) {
6109 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6110 phone.setImsRegistrationState(registered);
6111 }
6112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Wink Saville36469e72014-06-11 15:17:00 -07006116 }
6117
6118 /**
Stuart Scott54788802015-03-30 13:18:01 -07006119 * Set the network selection mode to automatic.
6120 *
6121 */
6122 @Override
6123 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6125 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
shilufc958392020-01-20 11:36:01 -08006129 if (!isActiveSubscription(subId)) {
6130 return;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006133 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6134 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Stuart Scott54788802015-03-30 13:18:01 -07006138 }
6139
Jack Yud10cdd42020-09-28 20:28:01 -07006140 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006141 * Ask the radio to connect to the input network and change selection mode to manual.
6142 *
6143 * @param subId the id of the subscription.
6144 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6145 * the operator to attach to.
6146 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6147 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6148 * normal network selection next time.
6149 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006150 */
6151 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006152 public boolean setNetworkSelectionModeManual(
6153 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006156
6157 if (!isActiveSubscription(subId)) {
6158 return false;
6159 }
6160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 final long identity = Binder.clearCallingIdentity();
6162 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006163 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006165 if (DBG) {
6166 log("setNetworkSelectionModeManual: subId: " + subId
6167 + " operator: " + operatorInfo);
6168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006173 }
shilu84f6e8b2019-12-19 13:58:01 -08006174 /**
6175 * Get the manual network selection
6176 *
6177 * @param subId the id of the subscription.
6178 *
6179 * @return the previously saved user selected PLMN
6180 */
6181 @Override
6182 public String getManualNetworkSelectionPlmn(int subId) {
6183 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006184 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006185 mApp, subId, "getManualNetworkSelectionPlmn");
6186
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006190 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006191 }
6192
6193 final Phone phone = getPhone(subId);
6194 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006195 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006196 }
6197 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6198 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6199 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006204
6205 /**
6206 * Scans for available networks.
6207 */
6208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006209 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6210 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6212 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006213 LocationAccessPolicy.LocationPermissionResult locationResult =
6214 LocationAccessPolicy.checkLocationPermission(mApp,
6215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6216 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006217 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .setCallingPid(Binder.getCallingPid())
6219 .setCallingUid(Binder.getCallingUid())
6220 .setMethod("getCellNetworkScanResults")
6221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006222 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6223 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006224 .build());
6225 switch (locationResult) {
6226 case DENIED_HARD:
6227 throw new SecurityException("Not allowed to access scan results -- location");
6228 case DENIED_SOFT:
6229 return null;
6230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
Pengquan Menga1bb6272018-09-06 09:59:22 -07006232 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 try {
6234 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006235 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006240 }
6241
6242 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006243 * Get the call forwarding info, given the call forwarding reason.
6244 */
6245 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006246 public void getCallForwarding(int subId, int callForwardingReason,
6247 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006248 enforceReadPrivilegedPermission("getCallForwarding");
6249 long identity = Binder.clearCallingIdentity();
6250 try {
6251 if (DBG) {
6252 log("getCallForwarding: subId " + subId
6253 + " callForwardingReason" + callForwardingReason);
6254 }
Hall Liu27d24262020-09-18 19:04:59 -07006255
6256 Phone phone = getPhone(subId);
6257 if (phone == null) {
6258 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006259 callback.onError(
6260 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006261 } catch (RemoteException e) {
6262 // ignore
6263 }
6264 return;
6265 }
6266
6267 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6268 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6269 @Override
6270 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6271 try {
6272 callback.onCallForwardingInfoAvailable(info);
6273 } catch (RemoteException e) {
6274 // ignore
6275 }
6276 }
6277
6278 @Override
6279 public void onError(int error) {
6280 try {
6281 callback.onError(error);
6282 } catch (RemoteException e) {
6283 // ignore
6284 }
6285 }
6286 });
6287 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
6293 /**
6294 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6295 * reason, the number to forward, and the timeout before the forwarding is attempted.
6296 */
6297 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006298 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6299 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006300 enforceModifyPermission();
6301 long identity = Binder.clearCallingIdentity();
6302 try {
6303 if (DBG) {
6304 log("setCallForwarding: subId " + subId
6305 + " callForwardingInfo" + callForwardingInfo);
6306 }
Hall Liu27d24262020-09-18 19:04:59 -07006307
6308 Phone phone = getPhone(subId);
6309 if (phone == null) {
6310 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006311 callback.accept(
6312 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006313 } catch (RemoteException e) {
6314 // ignore
6315 }
6316 return;
6317 }
6318
6319 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6320 FunctionalUtils.ignoreRemoteException(callback::accept));
6321
6322 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
6328 /**
Hall Liu27d24262020-09-18 19:04:59 -07006329 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006330 */
6331 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006332 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006333 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006334 long identity = Binder.clearCallingIdentity();
6335 try {
Hall Liu27d24262020-09-18 19:04:59 -07006336 Phone phone = getPhone(subId);
6337 if (phone == null) {
6338 try {
6339 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6340 } catch (RemoteException e) {
6341 // ignore
6342 }
6343 return;
6344 }
SongFerngWang0e767992021-03-31 22:08:45 +08006345 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6346 PersistableBundle c = configManager.getConfigForSubId(subId);
6347 boolean requireUssd = c.getBoolean(
6348 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006349
Shuo Qian4a594052020-01-23 11:59:30 -08006350 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006351 if (requireUssd) {
6352 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6353 getSubscriptionCarrierId(subId));
6354 String newUssdCommand = "";
6355 try {
6356 newUssdCommand = carrierXmlParser.getFeature(
6357 CarrierXmlParser.FEATURE_CALL_WAITING)
6358 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6359 } catch (NullPointerException e) {
6360 loge("Failed to generate USSD number" + e);
6361 }
6362 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6363 mMainThreadHandler, callback, carrierXmlParser,
6364 CarrierXmlParser.SsEntry.SSAction.QUERY);
6365 final String ussdCommand = newUssdCommand;
6366 Executors.newSingleThreadExecutor().execute(() -> {
6367 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6368 });
6369 } else {
6370 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6371 callback::accept);
6372 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6373 }
Shuo Qian4a594052020-01-23 11:59:30 -08006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
6377 }
6378
6379 /**
Hall Liu27d24262020-09-18 19:04:59 -07006380 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006381 */
6382 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006383 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006384 enforceModifyPermission();
6385 long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu27d24262020-09-18 19:04:59 -07006387 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6388
6389 Phone phone = getPhone(subId);
6390 if (phone == null) {
6391 try {
6392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6393 } catch (RemoteException e) {
6394 // ignore
6395 }
6396 return;
6397 }
6398
SongFerngWang0e767992021-03-31 22:08:45 +08006399 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6400 PersistableBundle c = configManager.getConfigForSubId(subId);
6401 boolean requireUssd = c.getBoolean(
6402 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006403
SongFerngWang0e767992021-03-31 22:08:45 +08006404 if (DBG) log("getCallWaitingStatus: subId " + subId);
6405 if (requireUssd) {
6406 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6407 getSubscriptionCarrierId(subId));
6408 CarrierXmlParser.SsEntry.SSAction ssAction =
6409 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6410 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6411 String newUssdCommand = "";
6412 try {
6413 newUssdCommand = carrierXmlParser.getFeature(
6414 CarrierXmlParser.FEATURE_CALL_WAITING)
6415 .makeCommand(ssAction, null);
6416 } catch (NullPointerException e) {
6417 loge("Failed to generate USSD number" + e);
6418 }
6419 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6420 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6421 final String ussdCommand = newUssdCommand;
6422 Executors.newSingleThreadExecutor().execute(() -> {
6423 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6424 });
6425 } else {
6426 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6427 FunctionalUtils.ignoreRemoteException(callback::accept));
6428
6429 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6430 }
Shuo Qian4a594052020-01-23 11:59:30 -08006431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
yinxub1bed742017-04-17 11:45:04 -07006437 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006438 *
yinxub1bed742017-04-17 11:45:04 -07006439 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006440 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6441 * location related information which will be sent if the caller already possess
6442 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006443 * @param request contains the radio access networks with bands/channels to scan
6444 * @param messenger callback messenger for scan results or errors
6445 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006446 * @return the id of the requested scan which can be used to stop the scan.
6447 */
6448 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006449 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6450 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006451 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6453 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006454 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006455 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6456 if (!renounceFineLocationAccess) {
6457 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6458 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6459 .setCallingPackage(callingPackage)
6460 .setCallingFeatureId(callingFeatureId)
6461 .setCallingPid(Binder.getCallingPid())
6462 .setCallingUid(Binder.getCallingUid())
6463 .setMethod("requestNetworkScan")
6464 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6465 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6466 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6467 .build());
6468 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006469 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006470 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6471 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006472 if (e != null) {
6473 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6474 throw e;
6475 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006476 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006477 return TelephonyScanManager.INVALID_SCAN_ID;
6478 }
6479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 }
Hall Liu912dfd32019-04-25 14:02:26 -07006481 int callingUid = Binder.getCallingUid();
6482 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006486 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006487 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
yinxu504e1392017-04-12 16:03:22 -07006491 }
6492
Hall Liub2ac8ef2019-02-28 15:56:23 -08006493 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006494 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006495 boolean hasCarrierPriv;
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6499 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Hall Liu558027f2019-05-15 19:14:05 -07006503 boolean hasNetworkScanPermission =
6504 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6505 == PERMISSION_GRANTED;
6506
6507 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6508 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6509 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 }
6511
6512 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6513 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006514 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6515 return new SecurityException("Specific channels must not be"
6516 + " scanned without location access.");
6517 }
6518 }
6519 }
6520
Hall Liub2ac8ef2019-02-28 15:56:23 -08006521 return null;
6522 }
6523
yinxu504e1392017-04-12 16:03:22 -07006524 /**
6525 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006526 *
6527 * @param subId id of the subscription
6528 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006529 */
6530 @Override
6531 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6533 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
Hall Liu912dfd32019-04-25 14:02:26 -07006535 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 final long identity = Binder.clearCallingIdentity();
6537 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006538 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
yinxu504e1392017-04-12 16:03:22 -07006542 }
6543
6544 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006546 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006548 */
6549 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006551 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006552 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 if (DBG) log("getAllowedNetworkTypesBitmask");
6558 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6559 int networkTypesBitmask = (result != null ? result[0] : -1);
6560 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6561 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006565 }
6566
6567 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006568 * Get the allowed network types for certain reason.
6569 *
6570 * @param subId the id of the subscription.
6571 * @param reason the reason the allowed network type change is taking place
6572 * @return the allowed network types.
6573 */
6574 @Override
6575 public long getAllowedNetworkTypesForReason(int subId,
6576 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006577 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006578 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 }
6586
6587 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006588 * Enable/Disable E-UTRA-NR Dual Connectivity
6589 * @param subId subscription id of the sim card
6590 * @param nrDualConnectivityState expected NR dual connectivity state
6591 * This can be passed following states
6592 * <ol>
6593 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6594 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6595 * <li>Disable NR dual connectivity and force secondary cell to be released
6596 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6597 * </ol>
6598 * @return operation result.
6599 */
6600 @Override
6601 public int setNrDualConnectivityState(int subId,
6602 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6604 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006605 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006606 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6607 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6608 }
6609
Sooraj Sasindran37444802020-08-11 10:40:43 -07006610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6614 nrDualConnectivityState, subId,
6615 workSource);
6616 if (DBG) log("enableNRDualConnectivity result: " + result);
6617 return result;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
6624 * Is E-UTRA-NR Dual Connectivity enabled
6625 * @return true if dual connectivity is enabled else false
6626 */
6627 @Override
6628 public boolean isNrDualConnectivityEnabled(int subId) {
6629 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006631 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006632 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006633 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6634 return false;
6635 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006636 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6640 null, subId, workSource);
6641 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6642 return isEnabled;
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
6648 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006649 * Set the allowed network types of the device and
6650 * provide the reason triggering the allowed network change.
6651 *
6652 * @param subId the id of the subscription.
6653 * @param reason the reason the allowed network type change is taking place
6654 * @param allowedNetworkTypes the allowed network types.
6655 * @return true on success; false on any failure.
6656 */
6657 @Override
6658 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 @TelephonyManager.AllowedNetworkTypesReason int reason,
6660 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6662 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006663 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006664 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6665 return false;
6666 }
6667 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6668 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006669 return false;
6670 }
6671
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006672 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6673 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6674
6675
6676 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6677 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6678 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006679 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006680
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006681 final long identity = Binder.clearCallingIdentity();
6682 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006683 Boolean success = (Boolean) sendRequest(
6684 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6685 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6686
6687 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6688 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
6692 }
6693
6694 /**
Miaoa84611c2019-03-15 09:21:10 +08006695 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006696 *
Miaoa84611c2019-03-15 09:21:10 +08006697 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006698 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006699 * @hide
6700 */
6701 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006702 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006705 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 try {
Miaoa84611c2019-03-15 09:21:10 +08006707 if (phone != null) {
6708 return phone.hasMatchedTetherApnSetting();
6709 } else {
6710 return false;
6711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006714 }
Junda Liu475951f2014-11-07 16:45:03 -08006715 }
6716
6717 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006718 * Get the user enabled state of Mobile Data.
6719 *
6720 * TODO: remove and use isUserDataEnabled.
6721 * This can't be removed now because some vendor codes
6722 * calls through ITelephony directly while they should
6723 * use TelephonyManager.
6724 *
6725 * @return true on enabled
6726 */
6727 @Override
6728 public boolean getDataEnabled(int subId) {
6729 return isUserDataEnabled(subId);
6730 }
6731
6732 /**
6733 * Get whether mobile data is enabled per user setting.
6734 *
6735 * There are other factors deciding whether mobile data is actually enabled, but they are
6736 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006737 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006738 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6739 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006740 *
6741 * @return {@code true} if data is enabled else {@code false}
6742 */
6743 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006744 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006746 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 try {
6748 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6749 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006750 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006751 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6752 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006753 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006755 mApp, subId, functionName);
6756
Robert Greenwalt646120a2014-05-23 11:54:03 -07006757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 int phoneId = mSubscriptionController.getPhoneId(subId);
6762 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6763 Phone phone = PhoneFactory.getPhone(phoneId);
6764 if (phone != null) {
6765 boolean retVal = phone.isUserDataEnabled();
6766 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6767 return retVal;
6768 } else {
6769 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6770 return false;
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006774 }
6775 }
6776
6777 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006778 * Checks if the device is capable of mobile data by considering whether whether the
6779 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6780 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006781 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006782 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006783 */
6784 @Override
6785 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006787 try {
6788 try {
6789 mApp.enforceCallingOrSelfPermission(
6790 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006792 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 try {
6794 mApp.enforceCallingOrSelfPermission(
6795 android.Manifest.permission.READ_PHONE_STATE,
6796 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006797 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006798 mApp.enforceCallingOrSelfPermission(
6799 permission.READ_BASIC_PHONE_STATE, functionName);
6800 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006801 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006802 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006803 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 Phone phone = PhoneFactory.getPhone(phoneId);
6810 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006811 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006812 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 return retVal;
6814 } else {
6815 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6816 return false;
6817 }
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006820 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006821 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006822
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006823 /**
6824 * Check if data is enabled for a specific reason
6825 * @param subId Subscription index
6826 * @param reason the reason the data enable change is taking place
6827 * @return {@code true} if the overall data is enabled; {@code false} if not.
6828 */
6829 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006830 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006831 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006832 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006833 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006834 try {
6835 mApp.enforceCallingOrSelfPermission(
6836 android.Manifest.permission.ACCESS_NETWORK_STATE,
6837 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006838 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006839 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6840 functionName);
6841 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006842 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006843 try {
6844 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006845 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006846 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006848 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006849 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006850 }
6851
6852
6853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 int phoneId = mSubscriptionController.getPhoneId(subId);
6856 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006857 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006858 + " reason=" + reason);
6859 }
6860 Phone phone = PhoneFactory.getPhone(phoneId);
6861 if (phone != null) {
6862 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006863 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006864 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006865 return retVal;
6866 } else {
6867 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006868 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006869 + subId + " retVal=false");
6870 }
6871 return false;
6872 }
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006879 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006880 // No permission needed; this only lets the caller inspect their own status.
6881 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006882 }
Junda Liu29340342014-07-10 15:23:27 -07006883
6884 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006885 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006886 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006887 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6888 }
6889
6890 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6891 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006892 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006893 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006894 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6895 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006896 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6897 if (cpt == null) {
6898 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6900 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006901 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006902 }
6903
6904 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006905 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006907 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006909 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006910 Phone phone = getPhone(subId);
6911 if (phone == null) {
6912 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6914 }
6915 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6916 if (cpt == null) {
6917 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6919 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006921 }
6922
6923 @Override
6924 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006925 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006926 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6927 }
6928
6929 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006931 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006932 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006933 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6935 Phone phone = PhoneFactory.getPhone(phoneId);
6936 if (phone == null) {
6937 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006939 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6940 if (cpt == null) {
6941 continue;
6942 }
6943 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006944 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6945 break;
6946 }
6947 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006948 return result;
Junda Liu29340342014-07-10 15:23:27 -07006949 }
Derek Tan89e89d42014-07-08 17:00:10 -07006950
6951 @Override
Junda Liue64de782015-04-16 17:19:16 -07006952 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006953 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006954 Phone phone = PhoneFactory.getPhone(phoneId);
6955 if (phone == null) {
6956 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006957 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006958 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6959 if (cpt == null) {
6960 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006961 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006962 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006963 }
6964
Amith Yamasani6e118872016-02-19 12:53:51 -08006965 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006966 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006967 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006968 Phone phone = PhoneFactory.getPhone(phoneId);
6969 if (phone == null) {
6970 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006971 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006972 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6973 if (cpt == null) {
6974 return Collections.emptyList();
6975 }
6976 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006977 }
6978
chen xuf7e9fe82019-05-09 19:31:02 -07006979 @Override
6980 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006981 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006982 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006983 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006984 try {
6985 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6986 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6987 }
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006990 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006991 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006992 }
6993
Rambo Wang6812ffb2022-03-15 16:54:17 -07006994 @Override
6995 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6996 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6997
6998 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6999 if (phone == null) {
7000 return null;
7001 }
7002 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7003 if (cpt == null) {
7004 return null;
7005 }
7006 return cpt.getCarrierServicePackageName();
7007 }
7008
Wink Savilleb564aae2014-10-23 10:18:09 -07007009 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007010 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007011 UiccPort port = phone == null ? null : phone.getUiccPort();
7012 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007013 return null;
7014 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007015 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007016 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007017 return null;
7018 }
7019 return iccId;
7020 }
7021
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007022 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007023 public void setCallComposerStatus(int subId, int status) {
7024 enforceModifyPermission();
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone != null) {
7030 Phone defaultPhone = phone.getImsPhone();
7031 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7032 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7033 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7035 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007036 }
7037 }
Shuo Qian284ae752020-12-22 19:10:14 -08007038 } catch (ImsException e) {
7039 throw new ServiceSpecificException(e.getCode());
7040 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007041 Binder.restoreCallingIdentity(identity);
7042 }
7043 }
7044
7045 @Override
7046 public int getCallComposerStatus(int subId) {
7047 enforceReadPrivilegedPermission("getCallComposerStatus");
7048
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 Phone phone = getPhone(subId);
7052 if (phone != null) {
7053 Phone defaultPhone = phone.getImsPhone();
7054 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7055 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7056 return imsPhone.getCallComposerStatus();
7057 }
7058 }
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7063 }
7064
7065 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007066 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7067 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007068 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 final String iccId = getIccId(subId);
7074 final Phone phone = getPhone(subId);
7075 if (phone == null) {
7076 return false;
7077 }
7078 final String subscriberId = phone.getSubscriberId();
7079
7080 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007081 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 + subscriberId + " to " + number);
7083 }
7084
7085 if (TextUtils.isEmpty(iccId)) {
7086 return false;
7087 }
7088
7089 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7090
7091 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7092 if (alphaTag == null) {
7093 editor.remove(alphaTagPrefKey);
7094 } else {
7095 editor.putString(alphaTagPrefKey, alphaTag);
7096 }
7097
7098 // Record both the line number and IMSI for this ICCID, since we need to
7099 // track all merged IMSIs based on line number
7100 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7101 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7102 if (number == null) {
7103 editor.remove(numberPrefKey);
7104 editor.remove(subscriberPrefKey);
7105 } else {
7106 editor.putString(numberPrefKey, number);
7107 editor.putString(subscriberPrefKey, subscriberId);
7108 }
7109
7110 editor.commit();
7111 return true;
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007114 }
Derek Tan7226c842014-07-02 17:42:23 -07007115 }
7116
7117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 public String getLine1NumberForDisplay(int subId, String callingPackage,
7119 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007120 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007123 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007124 return null;
7125 }
Derek Tan97ebb422014-09-05 16:55:38 -07007126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 String iccId = getIccId(subId);
7130 if (iccId != null) {
7131 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7132 if (DBG_MERGE) {
7133 log("getLine1NumberForDisplay returning "
7134 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7135 }
7136 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7139 return null;
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007142 }
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
7144
7145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007146 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7147 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007149 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007150 return null;
7151 }
Derek Tan97ebb422014-09-05 16:55:38 -07007152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 String iccId = getIccId(subId);
7156 if (iccId != null) {
7157 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7158 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7159 }
7160 return null;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007163 }
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007165
7166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007167 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7168 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7170 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007173 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007174 return null;
7175 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007176
Jordan Liub49b04b2019-05-06 14:45:15 -07007177 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7178 // the process, where TelephonyManager was instantiated.
7179 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007180 final long identity = Binder.clearCallingIdentity();
7181 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007182 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 final TelephonyManager tele = TelephonyManager.from(context);
7184 final SubscriptionManager sub = SubscriptionManager.from(context);
7185
7186 // Figure out what subscribers are currently active
7187 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188
Jordan Liub49b04b2019-05-06 14:45:15 -07007189 // Only consider subs which match the current subId
7190 // This logic can be simplified. See b/131189269 for progress.
7191 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007192 activeSubscriberIds.add(tele.getSubscriberId(subId));
7193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 // First pass, find a number override for an active subscriber
7196 String mergeNumber = null;
7197 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7198 for (String key : prefs.keySet()) {
7199 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7200 final String subscriberId = (String) prefs.get(key);
7201 if (activeSubscriberIds.contains(subscriberId)) {
7202 final String iccId = key.substring(
7203 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7204 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7205 mergeNumber = (String) prefs.get(numberKey);
7206 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007207 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 + " for active subscriber " + subscriberId);
7209 }
7210 if (!TextUtils.isEmpty(mergeNumber)) {
7211 break;
7212 }
7213 }
7214 }
7215 }
7216
7217 // Shortcut when no active merged subscribers
7218 if (TextUtils.isEmpty(mergeNumber)) {
7219 return null;
7220 }
7221
7222 // Second pass, find all subscribers under that line override
7223 final ArraySet<String> result = new ArraySet<>();
7224 for (String key : prefs.keySet()) {
7225 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7226 final String number = (String) prefs.get(key);
7227 if (mergeNumber.equals(number)) {
7228 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7229 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7230 final String subscriberId = (String) prefs.get(subscriberKey);
7231 if (!TextUtils.isEmpty(subscriberId)) {
7232 result.add(subscriberId);
7233 }
7234 }
7235 }
7236 }
7237
7238 final String[] resultArray = result.toArray(new String[result.size()]);
7239 Arrays.sort(resultArray);
7240 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007241 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7243 }
7244 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007247 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 }
7249
7250 @Override
zoey chen38003472019-12-13 17:16:31 +08007251 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7252 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 final TelephonyManager telephonyManager = mApp.getSystemService(
7257 TelephonyManager.class);
7258 String subscriberId = telephonyManager.getSubscriberId(subId);
7259 if (subscriberId == null) {
7260 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007261 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007262 + subId);
7263 }
7264 return null;
7265 }
7266
7267 final SubscriptionInfo info = SubscriptionController.getInstance()
7268 .getSubscriptionInfo(subId);
7269 final ParcelUuid groupUuid = info.getGroupUuid();
7270 // If it doesn't belong to any group, return just subscriberId of itself.
7271 if (groupUuid == null) {
7272 return new String[]{subscriberId};
7273 }
7274
7275 // Get all subscriberIds from the group.
7276 final List<String> mergedSubscriberIds = new ArrayList<>();
7277 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007278 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007279 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007280 for (SubscriptionInfo subInfo : groupInfos) {
7281 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7282 if (subscriberId != null) {
7283 mergedSubscriberIds.add(subscriberId);
7284 }
7285 }
7286
7287 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7288 } finally {
7289 Binder.restoreCallingIdentity(identity);
7290
7291 }
7292 }
7293
7294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007295 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007296 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007297 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 final Phone phone = getPhone(subId);
7302 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007306 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007307
7308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007309 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007310 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7311 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007312 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7313 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 final Phone phone = getPhone(subId);
7318 if (phone == null) {
7319 return false;
7320 }
7321 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7322 cdmaNonRoamingList);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007325 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007326 }
7327
7328 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007329 @Deprecated
7330 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7331 enforceModifyPermission();
7332
7333 int returnValue = 0;
7334 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007335 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007336 if(result.exception == null) {
7337 if (result.result != null) {
7338 byte[] responseData = (byte[])(result.result);
7339 if(responseData.length > oemResp.length) {
7340 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7341 responseData.length + "bytes. Buffer Size is " +
7342 oemResp.length + "bytes.");
7343 }
7344 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7345 returnValue = responseData.length;
7346 }
7347 } else {
7348 CommandException ex = (CommandException) result.exception;
7349 returnValue = ex.getCommandError().ordinal();
7350 if(returnValue > 0) returnValue *= -1;
7351 }
7352 } catch (RuntimeException e) {
7353 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7354 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7355 if(returnValue > 0) returnValue *= -1;
7356 }
7357
7358 return returnValue;
7359 }
7360
7361 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007362 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007363 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007364 try {
7365 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007366 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007367 mApp, phone.getSubId(), "getRadioAccessFamily");
7368 } catch (SecurityException e) {
7369 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7370 throw e;
7371 }
chen xub97461a2018-10-26 14:17:57 -07007372 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007373 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007374 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 final long identity = Binder.clearCallingIdentity();
7377 try {
chen xub97461a2018-10-26 14:17:57 -07007378 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007379 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007380 mApp, phone.getSubId(), "getRadioAccessFamily");
7381 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
chen xub97461a2018-10-26 14:17:57 -07007385 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007386 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007387
7388 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007389 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007390 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007391 try {
7392 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7393 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007394 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007395 }
7396 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007397 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007398 }
7399 RoleManager rm = mApp.getSystemService(RoleManager.class);
7400 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7401 if (!dialerRoleHolders.contains(callingPackage)) {
7402 throw new SecurityException("App must be the dialer role holder to"
7403 + " upload a call composer pic");
7404 }
7405
7406 Executors.newSingleThreadExecutor().execute(() -> {
7407 ByteArrayOutputStream output = new ByteArrayOutputStream(
7408 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7409 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7410 boolean readUntilEnd = false;
7411 int totalBytesRead = 0;
7412 byte[] buffer = new byte[16 * 1024];
7413 while (true) {
7414 int numRead;
7415 try {
7416 numRead = input.read(buffer);
7417 } catch (IOException e) {
7418 try {
7419 fd.checkError();
7420 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7421 null);
7422 } catch (IOException e1) {
7423 // This means that the other side closed explicitly with an error. If this
7424 // happens, log and ignore.
7425 loge("Remote end of call composer picture pipe closed: " + e1);
7426 }
7427 break;
7428 }
7429 if (numRead == -1) {
7430 readUntilEnd = true;
7431 break;
7432 }
7433 totalBytesRead += numRead;
7434 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7435 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7436 try {
7437 input.close();
7438 } catch (IOException e) {
7439 // ignore
7440 }
7441 break;
7442 }
7443 output.write(buffer, 0, numRead);
7444 }
7445 // Generally, the remote end will close the file descriptors. The only case where we
7446 // close is above, where the picture size is too big.
7447
7448 try {
7449 fd.checkError();
7450 } catch (IOException e) {
7451 loge("Remote end for call composer closed with an error: " + e);
7452 return;
7453 }
7454
Hall Liuaa4211e2021-01-20 15:43:39 -08007455 if (!readUntilEnd) {
7456 loge("Did not finish reading entire image; aborting");
7457 return;
7458 }
Hall Liu82694d52020-12-11 18:22:04 -08007459
Hall Liuaa4211e2021-01-20 15:43:39 -08007460 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7461 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7462 new CallComposerPictureTransfer.Factory() {},
7463 imageData,
7464 (result) -> {
7465 if (result.first != null) {
7466 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7467 Bundle outputResult = new Bundle();
7468 outputResult.putParcelable(
7469 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7470 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7471 outputResult);
7472 } else {
7473 callback.send(result.second, null);
7474 }
7475 }
7476 );
Hall Liu82694d52020-12-11 18:22:04 -08007477 });
7478 }
7479
7480 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007481 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007482 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007483 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 ImsManager.getInstance(defaultPhone.getContext(),
7488 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007492 }
7493
7494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7498 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007499 return false;
7500 }
Svet Ganovb320e182015-04-16 12:30:10 -07007501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 // Check the user preference and the system-level IMS setting. Even if the user has
7505 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7506 // In the long run, we may instead need to check if there exists a connection service
7507 // which can support video calling.
7508 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007509 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 return imsManager.isVtEnabledByPlatform()
7511 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7512 && imsManager.isVtEnabledByUser();
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007516 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007517
Andrew Leea1239f22015-03-02 17:44:07 -08007518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7520 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007522 mApp, subId, callingPackage, callingFeatureId,
7523 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 return false;
7525 }
7526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 CarrierConfigManager configManager =
7530 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Andrew Leea1239f22015-03-02 17:44:07 -08007536 }
7537
7538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007539 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007541 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 return false;
7543 }
7544
7545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 CarrierConfigManager configManager =
7548 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Andrew Leea1239f22015-03-02 17:44:07 -08007554 }
7555
Andrew Lee9431b832015-03-09 18:46:45 -07007556 @Override
7557 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007558 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007559 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007560 }
7561
7562 @Override
7563 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007566 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Andrew Lee9431b832015-03-09 18:46:45 -07007570 }
7571
Hall Liuf6668912018-10-31 17:05:23 -07007572 /**
7573 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7574 * support for the feature and device firmware support.
7575 *
7576 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7577 */
7578 @Override
7579 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581 final Phone phone = getPhone(subscriptionId);
7582 if (phone == null) {
7583 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7584 return false;
7585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7589 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 return isCarrierSupported && isDeviceSupported;
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
Hall Liu98187582018-01-22 19:15:32 -08007595 }
7596
Hall Liuf6668912018-10-31 17:05:23 -07007597 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007598 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7599 * RTT setting, will return true if the device and carrier both support RTT.
7600 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007601 */
7602 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 final long identity = Binder.clearCallingIdentity();
7604 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007605 boolean isRttSupported = isRttSupported(subscriptionId);
7606 boolean isUserRttSettingOn = Settings.Secure.getInt(
7607 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7608 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7609 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7610 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007614 }
7615
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007616 @Deprecated
7617 @Override
7618 public String getDeviceId(String callingPackage) {
7619 return getDeviceIdWithFeature(callingPackage, null);
7620 }
7621
Sanket Padawe7310cc72015-01-14 09:53:20 -08007622 /**
7623 * Returns the unique device ID of phone, for example, the IMEI for
7624 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7625 *
7626 * <p>Requires Permission:
7627 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7628 */
7629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007631 try {
7632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7633 } catch (SecurityException se) {
7634 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7635 throw new SecurityException("Package " + callingPackage + " does not belong to "
7636 + Binder.getCallingUid());
7637 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007638 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007639 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007640 return null;
7641 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007642 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007643 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007644 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007645 return null;
7646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return phone.getDeviceId();
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007654 }
7655
Ping Sunc67b7c22016-03-02 19:16:45 +08007656 /**
7657 * {@hide}
7658 * Returns the IMS Registration Status on a particular subid
7659 *
7660 * @param subId
7661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007663 Phone phone = getPhone(subId);
7664 if (phone != null) {
7665 return phone.isImsRegistered();
7666 } else {
7667 return false;
7668 }
7669 }
7670
Santos Cordon7a1885b2015-02-03 11:15:19 -08007671 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007672 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007676 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7677 }
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
7684 }
7685
7686 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007687 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007688 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007689 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007690 mApp,
7691 subscriptionId,
7692 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subscriptionId);
7696 if (phone == null) {
7697 return null;
7698 }
7699 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
7704
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 /**
7706 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007707 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 Phone phone = getPhone(subId);
7712 if (phone != null) {
7713 return phone.isWifiCallingEnabled();
7714 } else {
7715 return false;
7716 }
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007719 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007720 }
7721
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007722 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007724 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007725 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 Phone phone = getPhone(subId);
7729 if (phone != null) {
7730 return phone.isVideoEnabled();
7731 } else {
7732 return false;
7733 }
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007736 }
7737 }
7738
7739 /**
7740 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7741 * defined in {@link ImsRegistrationImplBase}.
7742 */
7743 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 final long identity = Binder.clearCallingIdentity();
7745 try {
7746 Phone phone = getPhone(subId);
7747 if (phone != null) {
7748 return phone.getImsRegistrationTech();
7749 } else {
7750 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7751 }
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007754 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007755 }
7756
Stuart Scott8eef64f2015-04-08 15:13:54 -07007757 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007758 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007759 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007760 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7761 return;
7762 }
Kai Shif70f46f2021-03-03 13:59:46 -08007763 Phone defaultPhone = getDefaultPhone();
7764 if (defaultPhone != null) {
7765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7766 mApp, getDefaultPhone().getSubId(), "factoryReset");
7767 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007768 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007769
Svet Ganovcc087f82015-05-12 20:35:54 -07007770 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007771 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7772 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007773 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007774 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007775 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007776 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007777 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007778 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007779 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007780 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007781 // There has been issues when Sms raw table somehow stores orphan
7782 // fragments. They lead to garbled message when new fragments come
7783 // in and combined with those stale ones. In case this happens again,
7784 // user can reset all network settings which will clean up this table.
7785 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007786 // Clean up IMS settings as well here.
7787 int slotId = getSlotIndex(subId);
7788 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7789 ImsManager.getInstance(mApp, slotId).factoryReset();
7790 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007791
Kai Shif70f46f2021-03-03 13:59:46 -08007792 if (defaultPhone == null) {
7793 return;
7794 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007795 // Erase modem config if erase modem on network setting is enabled.
7796 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7797 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7798 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007799 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007800 }
Kai Shif70f46f2021-03-03 13:59:46 -08007801
7802 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007803 } finally {
7804 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007805 }
7806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007807
SongFerngWangfd89b102021-05-27 22:44:54 +08007808 @VisibleForTesting
7809 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7810 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7811 return;
7812 }
7813 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7814 RILConstants.PREFERRED_NETWORK_MODE);
7815 SubscriptionManager.setSubscriptionProperty(subId,
7816 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7817 "user=" + defaultNetworkType);
7818 phone.loadAllowedNetworksFromSubscriptionDatabase();
7819 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7820 defaultNetworkType, null);
7821 }
7822
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007823 private void cleanUpSmsRawTable(Context context) {
7824 ContentResolver resolver = context.getContentResolver();
7825 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7826 resolver.delete(uri, null, null);
7827 }
7828
Narayan Kamath1c496c22015-04-16 14:40:19 +01007829 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007830 public String getSimLocaleForSubscriber(int subId) {
7831 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7832 final Phone phone = getPhone(subId);
7833 if (phone == null) {
7834 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007835 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 final long identity = Binder.clearCallingIdentity();
7838 try {
chen xu5d3637b2019-01-21 23:31:38 -08007839 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007840 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007841 if (info == null) {
7842 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7843 return null;
7844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 // Try and fetch the locale from the carrier properties or from the SIM language
7846 // preferences (EF-PL and EF-LI)...
7847 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007849 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7850 if (localeFromDefaultSim != null) {
7851 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7852 if (DBG) log("Using locale from subId: " + subId + " locale: "
7853 + localeFromDefaultSim);
tom hsu60a8dc52022-10-27 00:10:04 +08007854 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007855 } else {
7856 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 }
7858 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 // The SIM language preferences only store a language (e.g. fr = French), not an
7861 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7862 // the SIM and carrier preferences does not include a country we add the country
7863 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007864 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007866 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu60a8dc52022-10-27 00:10:04 +08007867 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 }
7869
7870 if (DBG) log("No locale found - returning null");
7871 return null;
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007875 }
7876
tom hsu0b59d292022-09-29 23:49:21 +08007877 @VisibleForTesting
tom hsu60a8dc52022-10-27 00:10:04 +08007878 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007879 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu60a8dc52022-10-27 00:10:04 +08007880 phone.getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007881 for (String localeTag : supportedLocale) {
tom hsu60a8dc52022-10-27 00:10:04 +08007882 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7883 && TextUtils.equals(inputLocale.getCountry(),
tom hsu0b59d292022-09-29 23:49:21 +08007884 Locale.forLanguageTag(localeTag).getCountry())) {
7885 return localeTag;
7886 }
7887 }
7888 return inputLocale.toLanguageTag();
7889 }
7890
Narayan Kamath1c496c22015-04-16 14:40:19 +01007891 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007893 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007894 }
7895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 /**
7897 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7898 */
7899 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007900 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007901 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007902 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007903
Gary Jian3aa9a762022-01-24 16:41:19 +08007904 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7905 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007906
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007907 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007908 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7909 * representing the state of the modem.
7910 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007911 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7912 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007913 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007914 */
7915 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007916 public void requestModemActivityInfo(ResultReceiver result) {
7917 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007918 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007919
7920 final long identity = Binder.clearCallingIdentity();
7921 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007922 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 } finally {
7924 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007925 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007926 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007927
Siddharth Rayb8114062018-06-17 15:02:38 -07007928 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7929 // less than total activity duration.
7930 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7931 if (info == null) {
7932 return false;
7933 }
7934 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007935 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7936 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7937
Siddharth Rayb8114062018-06-17 15:02:38 -07007938 return (info.isValid()
7939 && (info.getSleepTimeMillis() <= activityDurationMs)
7940 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007941 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007942 && (totalTxTimeMs <= activityDurationMs));
7943 }
7944
Gary Jian3aa9a762022-01-24 16:41:19 +08007945 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7946 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7947 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7948 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7949
7950 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7951 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7952 }
7953
7954 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7955 mLastModemActivityInfo.setReceiveTimeMillis(
7956 rat,
7957 freq,
7958 info.getReceiveTimeMillis(rat, freq)
7959 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7960 }
7961
7962 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7963 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7964 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7965 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7966
7967 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7968 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7969 }
7970 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7971 mLastModemActivityInfo.setReceiveTimeMillis(
7972 rat,
7973 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7974 }
7975
7976 /**
7977 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7978 * @param info recent ModemActivityInfo
7979 */
7980 private void mergeModemActivityInfo(ModemActivityInfo info) {
7981 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7982 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7983 boolean matched;
7984 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7985 matched = false;
7986 int rat = info.getSpecificInfoRat(i);
7987 int freq = info.getSpecificInfoFrequencyRange(i);
7988 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7989 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7990 //if it already exists
7991 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7992 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7993 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7994 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7995 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7996 updateLastModemActivityInfo(info, rat, freq);
7997 matched = true;
7998 }
7999 } else {
8000 updateLastModemActivityInfo(info, rat);
8001 matched = true;
8002 }
8003 }
8004 }
8005
8006 if (!matched) {
8007 mDeltaSpecificInfo =
8008 new ActivityStatsTechSpecificInfo(
8009 rat,
8010 freq,
8011 info.getTransmitTimeMillis(rat, freq),
8012 (int) info.getReceiveTimeMillis(rat, freq));
8013 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8014 }
8015 }
8016 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8017 mLastModemActivitySpecificInfo =
8018 new ActivityStatsTechSpecificInfo[merged.size()];
8019 merged.toArray(mLastModemActivitySpecificInfo);
8020
8021 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8022 mLastModemActivityInfo.setSleepTimeMillis(
8023 info.getSleepTimeMillis()
8024 + mLastModemActivityInfo.getSleepTimeMillis());
8025 mLastModemActivityInfo.setIdleTimeMillis(
8026 info.getIdleTimeMillis()
8027 + mLastModemActivityInfo.getIdleTimeMillis());
8028 }
8029
Jack Yu85bd38a2015-11-09 11:34:32 -08008030 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008031 * Returns the service state information on specified subscription.
8032 */
8033 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008034 public ServiceState getServiceStateForSubscriber(int subId,
8035 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8036 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008038 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008039 return null;
8040 }
8041
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008042 boolean hasFinePermission = false;
8043 boolean hasCoarsePermission = false;
8044 if (!renounceFineLocationAccess) {
8045 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8046 LocationAccessPolicy.checkLocationPermission(mApp,
8047 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8048 .setCallingPackage(callingPackage)
8049 .setCallingFeatureId(callingFeatureId)
8050 .setCallingPid(Binder.getCallingPid())
8051 .setCallingUid(Binder.getCallingUid())
8052 .setMethod("getServiceStateForSubscriber")
8053 .setLogAsInfo(true)
8054 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8055 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8056 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8057 .build());
8058 hasFinePermission =
8059 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8060 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008061
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008062 if (!renounceCoarseLocationAccess) {
8063 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8064 LocationAccessPolicy.checkLocationPermission(mApp,
8065 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8066 .setCallingPackage(callingPackage)
8067 .setCallingFeatureId(callingFeatureId)
8068 .setCallingPid(Binder.getCallingPid())
8069 .setCallingUid(Binder.getCallingUid())
8070 .setMethod("getServiceStateForSubscriber")
8071 .setLogAsInfo(true)
8072 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8073 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8074 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8075 .build());
8076 hasCoarsePermission =
8077 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8078 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008079
Jack Yu479f40e2020-10-27 21:29:25 -07008080 final Phone phone = getPhone(subId);
8081 if (phone == null) {
8082 return null;
8083 }
8084
Jordan Liu0f2bc442020-11-18 16:47:37 -08008085 final long identity = Binder.clearCallingIdentity();
8086
Jack Yu479f40e2020-10-27 21:29:25 -07008087 boolean isCallingPackageDataService = phone.getDataServicePackages()
8088 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008090 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8091 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8092 Rlog.d(LOG_TAG,
8093 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8094 return null;
8095 }
8096
Hall Liuf19c44f2018-11-27 14:38:17 -08008097 ServiceState ss = phone.getServiceState();
8098
8099 // Scrub out the location info in ServiceState depending on what level of access
8100 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008101 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008102 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8103 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008108
8109 /**
8110 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8111 *
8112 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8113 * voicemail ringtone.
8114 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8115 * PhoneAccount.
8116 */
8117 @Override
8118 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8122 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008123 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
8129 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008130 }
8131
8132 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008133 * Sets the per-account voicemail ringtone.
8134 *
8135 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8136 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8137 *
8138 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8139 * voicemail ringtone.
8140 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8141 * PhoneAccount.
8142 */
8143 @Override
8144 public void setVoicemailRingtoneUri(String callingPackage,
8145 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008146 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008148 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8149 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8151 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8152 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154
8155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8158 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008159 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160 }
8161 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8162 } finally {
8163 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008164 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008165 }
8166
8167 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008168 * Returns whether vibration is set for voicemail notification in Phone settings.
8169 *
8170 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8171 * voicemail vibration setting.
8172 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8173 */
8174 @Override
8175 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008176 final long identity = Binder.clearCallingIdentity();
8177 try {
8178 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8179 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008180 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008183 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8184 } finally {
8185 Binder.restoreCallingIdentity(identity);
8186 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008187 }
8188
Youhan Wange64578a2016-05-02 15:32:42 -07008189 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008190 * Sets the per-account voicemail vibration.
8191 *
8192 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8193 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8194 *
8195 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8196 * voicemail vibration setting.
8197 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8198 * specific PhoneAccount.
8199 */
8200 @Override
8201 public void setVoicemailVibrationEnabled(String callingPackage,
8202 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008205 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8206 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8208 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8209 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008210 }
8211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212 final long identity = Binder.clearCallingIdentity();
8213 try {
8214 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8215 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008216 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217 }
8218 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008221 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008222 }
8223
8224 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008225 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8226 *
8227 * @throws SecurityException if the caller does not have the required permission
8228 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008229 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008230 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008231 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008232 }
8233
8234 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008235 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8236 * permission.
8237 *
8238 * @throws SecurityException if the caller does not have the required permission
8239 */
8240 private void enforceSendSmsPermission() {
8241 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8242 }
8243
8244 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008245 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008246 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008247 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008248 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008249 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 final long identity = Binder.clearCallingIdentity();
8251 try {
8252 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008253 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 if (componentName == null) {
8255 throw new SecurityException(
8256 "Caller not current active visual voicemail package[null]");
8257 }
8258 String vvmPackage = componentName.getPackageName();
8259 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008260 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261 }
8262 } finally {
8263 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008264 }
8265 }
8266
8267 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008268 * Return the application ID for the app type.
8269 *
8270 * @param subId the subscription ID that this request applies to.
8271 * @param appType the uicc app type.
8272 * @return Application ID for specificied app type, or null if no uicc.
8273 */
8274 @Override
8275 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008276 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008277 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278
8279 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008280 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008281 if (phone == null) {
8282 return null;
8283 }
8284 String aid = null;
8285 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008286 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 .getApplicationByType(appType).getAid();
8288 } catch (Exception e) {
8289 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8290 }
8291 return aid;
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008294 }
Youhan Wange64578a2016-05-02 15:32:42 -07008295 }
8296
Youhan Wang4001d252016-05-11 10:29:41 -07008297 /**
8298 * Return the Electronic Serial Number.
8299 *
8300 * @param subId the subscription ID that this request applies to.
8301 * @return ESN or null if error.
8302 */
8303 @Override
8304 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008305 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008306 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307
8308 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008309 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 if (phone == null) {
8311 return null;
8312 }
8313 String esn = null;
8314 try {
8315 esn = phone.getEsn();
8316 } catch (Exception e) {
8317 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8318 }
8319 return esn;
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008322 }
Youhan Wang4001d252016-05-11 10:29:41 -07008323 }
8324
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008325 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008326 * Return the Preferred Roaming List Version.
8327 *
8328 * @param subId the subscription ID that this request applies to.
8329 * @return PRLVersion or null if error.
8330 */
8331 @Override
8332 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008333 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008334 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008335
8336 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008337 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 if (phone == null) {
8339 return null;
8340 }
8341 String cdmaPrlVersion = null;
8342 try {
8343 cdmaPrlVersion = phone.getCdmaPrlVersion();
8344 } catch (Exception e) {
8345 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8346 }
8347 return cdmaPrlVersion;
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008350 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008351 }
8352
8353 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008354 * Get snapshot of Telephony histograms
8355 * @return List of Telephony histograms
8356 * @hide
8357 */
8358 @Override
8359 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8361 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008362
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 return RIL.getTelephonyRILTimingHistograms();
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008369 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008370
8371 /**
8372 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008373 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8374 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008375 * Require system privileges. In the future we may add this to carrier APIs.
8376 *
Michele Berionne482f8202018-11-27 18:57:59 -08008377 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008378 */
8379 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008380 @TelephonyManager.SetCarrierRestrictionResult
8381 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008382 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008383 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008384
Michele Berionne482f8202018-11-27 18:57:59 -08008385 if (carrierRestrictionRules == null) {
8386 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008387 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008391 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008392 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008396 }
8397
8398 /**
8399 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008400 * Get the allowed carrier list and the excluded carrier list, including the priority between
8401 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008402 * Require system privileges. In the future we may add this to carrier APIs.
8403 *
Michele Berionne482f8202018-11-27 18:57:59 -08008404 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008405 */
8406 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008407 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008408 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008413 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8414 if (response instanceof CarrierRestrictionRules) {
8415 return (CarrierRestrictionRules) response;
8416 }
8417 // Response is an Exception of some kind,
8418 // which is signalled to the user as a NULL retval
8419 return null;
8420 } catch (Exception e) {
8421 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8422 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008426 }
8427
fionaxu59545b42016-05-25 15:53:37 -07008428 /**
fionaxu59545b42016-05-25 15:53:37 -07008429 * Action set from carrier signalling broadcast receivers to enable/disable radio
8430 * @param subId the subscription ID that this action applies to.
8431 * @param enabled control enable or disable radio.
8432 * {@hide}
8433 */
8434 @Override
8435 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8436 enforceModifyPermission();
8437 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438
8439 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008440 if (phone == null) {
8441 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8442 return;
8443 }
8444 try {
8445 phone.carrierActionSetRadioEnabled(enabled);
8446 } catch (Exception e) {
8447 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448 } finally {
8449 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008450 }
8451 }
8452
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008453 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008454 * Enable or disable Voice over NR (VoNR)
8455 * @param subId the subscription ID that this action applies to.
8456 * @param enabled enable or disable VoNR.
8457 * @return operation result.
8458 */
8459 @Override
8460 public int setVoNrEnabled(int subId, boolean enabled) {
8461 enforceModifyPermission();
8462 final Phone phone = getPhone(subId);
8463
8464 final long identity = Binder.clearCallingIdentity();
8465 if (phone == null) {
8466 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8467 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8468 }
8469
8470 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8471 try {
8472 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8473 workSource);
8474 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008475
8476 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8477 if (DBG) {
8478 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8479 }
8480 SubscriptionManager.setSubscriptionProperty(
8481 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8482 (enabled ? "1" : "0"));
8483 }
8484
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008485 return result;
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
8488 }
8489 }
8490
8491 /**
8492 * Is voice over NR enabled
8493 * @return true if VoNR is enabled else false
8494 */
8495 @Override
8496 public boolean isVoNrEnabled(int subId) {
8497 enforceReadPrivilegedPermission("isVoNrEnabled");
8498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
8501 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8502 null, subId, workSource);
8503 if (DBG) log("isVoNrEnabled: " + isEnabled);
8504 return isEnabled;
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
8509
8510 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008511 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8512 * network status based on which carrier apps could apply actions accordingly,
8513 * enable/disable default url handler for example.
8514 *
8515 * @param subId the subscription ID that this action applies to.
8516 * @param report control start/stop reporting the default network status.
8517 * {@hide}
8518 */
8519 @Override
8520 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8521 enforceModifyPermission();
8522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523
8524 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008525 if (phone == null) {
8526 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8527 return;
8528 }
8529 try {
8530 phone.carrierActionReportDefaultNetworkStatus(report);
8531 } catch (Exception e) {
8532 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008533 } finally {
8534 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008535 }
8536 }
8537
8538 /**
fionaxud9622282017-07-17 17:51:30 -07008539 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8540 * @param subId the subscription ID that this action applies to.
8541 * {@hide}
8542 */
8543 @Override
8544 public void carrierActionResetAll(int subId) {
8545 enforceModifyPermission();
8546 final Phone phone = getPhone(subId);
8547 if (phone == null) {
8548 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8549 return;
8550 }
8551 try {
8552 phone.carrierActionResetAll();
8553 } catch (Exception e) {
8554 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8555 }
8556 }
8557
8558 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008559 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8560 * bug report is being generated.
8561 */
8562 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008563 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008564 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8565 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008566 writer.println("Permission Denial: can't dump Phone from pid="
8567 + Binder.getCallingPid()
8568 + ", uid=" + Binder.getCallingUid()
8569 + "without permission "
8570 + android.Manifest.permission.DUMP);
8571 return;
8572 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008573 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008574 }
Jack Yueb89b242016-06-22 13:27:47 -07008575
Brad Ebingerdac2f002018-04-03 15:17:52 -07008576 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008577 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8578 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8579 @NonNull String[] args) {
8580 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8581 this, in.getFileDescriptor(), out.getFileDescriptor(),
8582 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008583 }
8584
Jack Yueb89b242016-06-22 13:27:47 -07008585 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008586 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008587 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008588 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008589 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008590 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008591 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008592 */
8593 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008594 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008595 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008596 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8597 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8598 try {
8599 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008600 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008601 } catch (SecurityException se) {
8602 enforceModifyPermission();
8603 }
8604 } else {
8605 enforceModifyPermission();
8606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 Phone phone = getPhone(subId);
8611 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008612 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8613 phone.carrierActionSetMeteredApnsEnabled(enabled);
8614 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008615 phone.getDataSettingsManager().setDataEnabled(
8616 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008621 }
8622 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008623
8624 /**
8625 * Get Client request stats
8626 * @return List of Client Request Stats
8627 * @hide
8628 */
8629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008630 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8631 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008633 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008634 return null;
8635 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008636 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 if (phone != null) {
8641 return phone.getClientRequestStats();
8642 }
8643
8644 return null;
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008648 }
8649
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008650 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008651 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008652 if (uid == Process.ROOT_UID && packageName == null) {
8653 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8654 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8655 // exception. ROOT_UID seems not to have a valid package name returned by
8656 // PackageManager, so just fake it here to avoid issues when running telephony shell
8657 // commands that plumb through the RIL as root, like so:
8658 // $ adb root
8659 // $ adb shell cmd phone ...
8660 packageName = "root";
8661 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008662 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008663 }
Jack Yueb4124c2017-02-16 15:32:43 -08008664
8665 /**
Grace Chen70990072017-03-24 17:21:30 -07008666 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008667 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008668 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008669 * @param state State of SIM (power down, power up, pass through)
8670 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8671 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8672 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008673 *
8674 **/
8675 @Override
Grace Chen70990072017-03-24 17:21:30 -07008676 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008677 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008678 Phone phone = PhoneFactory.getPhone(slotIndex);
8679
vagdeviaf9a5b92018-08-15 16:01:53 -07008680 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008685 phone.setSimPowerState(state, null, workSource);
8686 }
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
8690 }
8691
8692 /**
8693 * Set SIM card power state.
8694 *
8695 * @param slotIndex SIM slot id.
8696 * @param state State of SIM (power down, power up, pass through)
8697 * @param callback callback to trigger after success or failure
8698 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8699 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8700 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8701 *
8702 **/
8703 @Override
8704 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8705 IIntegerConsumer callback) {
8706 enforceModifyPermission();
8707 Phone phone = PhoneFactory.getPhone(slotIndex);
8708
8709 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8710
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
8713 if (phone != null) {
8714 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8715 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008716 }
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008719 }
8720 }
Shuo Qiandd210312017-04-12 22:11:33 +00008721
Tyler Gunn65d45c22017-06-05 11:22:26 -07008722 private boolean isUssdApiAllowed(int subId) {
8723 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008724 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008725 if (configManager == null) {
8726 return false;
8727 }
8728 PersistableBundle pb = configManager.getConfigForSubId(subId);
8729 if (pb == null) {
8730 return false;
8731 }
8732 return pb.getBoolean(
8733 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8734 }
8735
Shuo Qiandd210312017-04-12 22:11:33 +00008736 /**
8737 * Check if phone is in emergency callback mode
8738 * @return true if phone is in emergency callback mode
8739 * @param subId sub id
8740 */
goneil9c5f4872017-12-05 14:07:56 -08008741 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008742 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008743 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 if (phone != null) {
8749 return phone.isInEcm();
8750 } else {
8751 return false;
8752 }
8753 } finally {
8754 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008755 }
8756 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008757
8758 /**
8759 * Get the current signal strength information for the given subscription.
8760 * Because this information is not updated when the device is in a low power state
8761 * it should not be relied-upon to be current.
8762 * @param subId Subscription index
8763 * @return the most recent cached signal strength info from the modem
8764 */
8765 @Override
8766 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 Phone p = getPhone(subId);
8770 if (p == null) {
8771 return null;
8772 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 return p.getSignalStrength();
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
8777 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008778 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008779
Pengquan Meng77b7f132018-08-22 14:49:57 -07008780 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008781 * Get the current modem radio state for the given slot.
8782 * @param slotIndex slot index.
8783 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008784 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008785 * @return the current radio power state from the modem
8786 */
8787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008788 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008789 Phone phone = PhoneFactory.getPhone(slotIndex);
8790 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8792 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008793 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8794 }
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 return phone.getRadioPowerState();
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8804 }
8805
8806 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008807 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8808 *
8809 * <p>Requires one of the following permissions:
8810 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008811 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008812 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8813 * privileges.
8814 *
8815 * @param subId subscription id
8816 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8817 * {@code false}.
8818 */
8819 @Override
8820 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008821 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008822 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008823 try {
8824 mApp.enforceCallingOrSelfPermission(
8825 android.Manifest.permission.ACCESS_NETWORK_STATE,
8826 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008827 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008828 mApp.enforceCallingOrSelfPermission(
8829 permission.READ_BASIC_PHONE_STATE, functionName);
8830 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008831 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008832 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008833 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008834 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008835
Pengquan Menga1bb6272018-09-06 09:59:22 -07008836 boolean isEnabled = false;
8837 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008838 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008839 Phone phone = getPhone(subId);
8840 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008841 } finally {
8842 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008843 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008844 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008845 }
8846
8847
8848 /**
8849 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8850 *
8851 * <p> Requires permission:
8852 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8853 * privileges.
8854 *
8855 * @param subId subscription id
8856 * @param isEnabled {@code true} means enable, {@code false} means disable.
8857 */
8858 @Override
8859 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8861 mApp, subId, "setDataRoamingEnabled");
8862
Pengquan Menga1bb6272018-09-06 09:59:22 -07008863 final long identity = Binder.clearCallingIdentity();
8864 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008865 Phone phone = getPhone(subId);
8866 if (phone != null) {
8867 phone.setDataRoamingEnabled(isEnabled);
8868 }
8869 } finally {
8870 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008871 }
8872 }
8873
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008874 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008875 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008876 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008877 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008878 mApp, subId, "isManualNetworkSelectionAllowed");
8879
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008880 boolean isAllowed = true;
8881 final long identity = Binder.clearCallingIdentity();
8882 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008883 Phone phone = getPhone(subId);
8884 if (phone != null) {
8885 isAllowed = phone.isCspPlmnEnabled();
8886 }
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
8890 return isAllowed;
8891 }
8892
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008893 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8894 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008895 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008896 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008897 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008898 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8899 if (phone == null) {
8900 return false;
8901 }
8902 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8903 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8904 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008905 }
8906
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008907 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008908 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008909 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008910 mApp.getSystemService(AppOpsManager.class)
8911 .checkPackage(Binder.getCallingUid(), callingPackage);
8912
Jordan Liu1e142fc2019-04-22 15:10:43 -07008913 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008914 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008915 try {
8916 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008917 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008918 } catch (SecurityException e) {
8919 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8920 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008921 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008922 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008923 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008924 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008925 }
sandeepjsb6c87872021-09-27 15:34:44 +00008926 // checking compatibility, if calling app's target SDK is T and beyond.
8927 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8928 Binder.getCallingUid())) {
8929 isIccIdAccessRestricted = true;
8930 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008931 final long identity = Binder.clearCallingIdentity();
8932 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008933 UiccController uiccController = UiccController.getInstance();
8934 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935 if (hasReadPermission) {
8936 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008937 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008938
8939 // Remove private info if the caller doesn't have access
8940 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8941 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008942 //setting the value after compatibility check
8943 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008944 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8945 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008946 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008947 if (card == null) {
8948 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008949 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008950 continue;
8951 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008952 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8953 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008954 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008955 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008956 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008957 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8958 for (UiccPortInfo portInfo : portInfos) {
8959 UiccPort port = uiccController.getUiccPortForSlot(
8960 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8961 if (port == null) {
8962 // assume no access if port is null
8963 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8964 continue;
8965 }
8966 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8967 uiccPortInfos.add(portInfo);
8968 } else {
8969 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8970 }
8971 }
8972 filteredInfos.add(new UiccCardInfo(
8973 cardInfo.isEuicc(),
8974 cardInfo.getCardId(),
8975 null,
8976 cardInfo.getPhysicalSlotIndex(),
8977 cardInfo.isRemovable(),
8978 cardInfo.isMultipleEnabledProfilesSupported(),
8979 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008980 }
8981 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008982 } finally {
8983 Binder.restoreCallingIdentity(identity);
8984 }
8985 }
8986
sandeepjsb6c87872021-09-27 15:34:44 +00008987 /**
8988 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8989 * generally private and require carrier privileges to view.
8990 *
8991 * @hide
8992 */
8993 @NonNull
8994 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8995 List<UiccPortInfo> portinfo = new ArrayList<>();
8996 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8997 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8998 }
8999 return new UiccCardInfo(
9000 cardInfo.isEuicc(),
9001 cardInfo.getCardId(),
9002 null,
9003 cardInfo.getPhysicalSlotIndex(),
9004 cardInfo.isRemovable(),
9005 cardInfo.isMultipleEnabledProfilesSupported(),
9006 portinfo
9007 );
9008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009009
sandeepjsb6c87872021-09-27 15:34:44 +00009010 /**
9011 * @hide
9012 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9013 * These values are generally private and require carrier privileges to view.
9014 */
9015 @NonNull
9016 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9017 return new UiccPortInfo(
9018 UiccPortInfo.ICCID_REDACTED,
9019 portInfo.getPortIndex(),
9020 portInfo.getLogicalSlotIndex(),
9021 portInfo.isActive()
9022 );
9023 }
9024 @Override
9025 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009026 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009027 mApp.getSystemService(AppOpsManager.class)
9028 .checkPackage(Binder.getCallingUid(), callingPackage);
9029
sandeepjsb6c87872021-09-27 15:34:44 +00009030 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009031
Aman Guptaf3c90b32022-03-17 04:54:16 +00009032 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9033 // we are reading iccId which is PII data.
9034 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009035
9036 // checking compatibility, if calling app's target SDK is T and beyond.
9037 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9038 Binder.getCallingUid())) {
9039 isLogicalSlotAccessRestricted = true;
9040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009041 final long identity = Binder.clearCallingIdentity();
9042 try {
9043 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009044 if (slots == null || slots.length == 0) {
9045 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 return null;
9047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9049 for (int i = 0; i < slots.length; i++) {
9050 UiccSlot slot = slots[i];
9051 if (slot == null) {
9052 continue;
9053 }
9054
Jordan Liu7be7e652019-05-06 18:55:02 +00009055 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 UiccCard card = slot.getUiccCard();
9057 if (card != null) {
9058 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009059 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009060 cardId = slot.getEid();
9061 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009062 // If cardId is null, use iccId of default port as cardId.
9063 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 }
9066
Jordan Liu857451f2019-05-09 16:35:35 -07009067 if (cardId != null) {
9068 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9069 // if cardId is an EID, it's all digits so this is fine
9070 cardId = IccUtils.stripTrailingFs(cardId);
9071 }
9072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009073 int cardState = 0;
9074 switch (slot.getCardState()) {
9075 case CARDSTATE_ABSENT:
9076 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9077 break;
9078 case CARDSTATE_PRESENT:
9079 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9080 break;
9081 case CARDSTATE_ERROR:
9082 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9083 break;
9084 case CARDSTATE_RESTRICTED:
9085 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9086 break;
9087 default:
9088 break;
9089
9090 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009091 List<UiccPortInfo> portInfos = new ArrayList<>();
9092 int[] portIndexes = slot.getPortList();
9093 for (int portIdx : portIndexes) {
9094 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009095 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009096 portInfos.add(new UiccPortInfo(iccId, portIdx,
9097 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100 slot.isEuicc(),
9101 cardId,
9102 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009103 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009104 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009105 //setting the value after compatibility check
9106 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009107 }
9108 return infos;
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009111 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009112 }
9113
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009114 /* Returns null if doesn't have read permission or carrier privilege access. */
9115 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9116 boolean hasReadPermission) {
9117 String iccId = slot.getIccId(portIndex);
9118 if (hasReadPermission) { // if has read permission
9119 return iccId;
9120 } else {
9121 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9122 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9123 // if no read permission, checking carrier privilege access
9124 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9125 return iccId;
9126 }
9127 }
9128 }
9129 // No read permission or carrier privilege access.
9130 return UiccPortInfo.ICCID_REDACTED;
9131 }
9132
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009133 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009134 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009135 public boolean switchSlots(int[] physicalSlots) {
9136 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009137
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009140 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9141 for (int i = 0; i < physicalSlots.length; i++) {
9142 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9143 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9144 physicalSlots[i], i));
9145 }
9146 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009150 }
Jack Yu4c988042018-02-27 15:30:01 -08009151
9152 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009153 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9154 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9155 enforceModifyPermission();
9156
9157 final long identity = Binder.clearCallingIdentity();
9158 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009159 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
9165 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009166 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009167 final long identity = Binder.clearCallingIdentity();
9168 try {
9169 return UiccController.getInstance().getCardIdForDefaultEuicc();
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
Pengquan Meng85728fb2018-03-12 16:31:21 -07009175 /**
goneil47ffb6e2018-04-06 15:40:58 -07009176 * A test API to reload the UICC profile.
9177 *
9178 * <p>Requires that the calling app has permission
9179 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9180 * @hide
9181 */
9182 @Override
9183 public void refreshUiccProfile(int subId) {
9184 enforceModifyPermission();
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 Phone phone = getPhone(subId);
9189 if (phone == null) {
9190 return;
9191 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009192 UiccPort uiccPort = phone.getUiccPort();
9193 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009194 return;
9195 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009196 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009197 if (uiccProfile == null) {
9198 return;
9199 }
9200 uiccProfile.refresh();
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009207 * Returns false if the mobile data is disabled by default, otherwise return true.
9208 */
9209 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009210 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009211 }
9212
9213 /**
9214 * Returns true if the data roaming is enabled by default, i.e the system property
9215 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9216 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9217 */
9218 private boolean getDefaultDataRoamingEnabled(int subId) {
9219 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009220 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009221 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009222 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9223 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9224 return isDataRoamingEnabled;
9225 }
9226
9227 /**
9228 * Returns the default network type for the given {@code subId}, if the default network type is
9229 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9230 */
9231 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009232 List<Integer> list = TelephonyProperties.default_network();
9233 int phoneId = mSubscriptionController.getPhoneId(subId);
9234 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9235 return list.get(phoneId);
9236 }
9237 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009238 }
fionaxua13278b2018-03-21 00:08:13 -07009239
9240 @Override
9241 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009242 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009243 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 final Phone phone = getPhone(subId);
9248 if (phone == null) {
9249 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9250 return;
9251 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009252 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9253 if (cpt != null) {
9254 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9255 }
9256 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009257 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9258 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009259 if (carrierPrivilegeRules == null) {
9260 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9261 } else {
9262 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009264 } finally {
9265 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009266 }
fionaxua13278b2018-03-21 00:08:13 -07009267 }
9268
9269 @Override
9270 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009271 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009272
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 final Phone phone = getPhone(subId);
9276 if (phone == null) {
9277 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9278 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9279 }
9280 return phone.getCarrierIdListVersion();
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009283 }
fionaxua13278b2018-03-21 00:08:13 -07009284 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009285
9286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009287 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9288 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009290 mApp, subId, callingPackage, callingFeatureId,
9291 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009292 return -1;
9293 }
9294
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
9297 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009302
9303 @Override
9304 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009305 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009306 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009307 mApp, subId, "getCdmaRoamingMode");
9308
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9312 } finally {
9313 Binder.restoreCallingIdentity(identity);
9314 }
9315 }
9316
9317 @Override
9318 public boolean setCdmaRoamingMode(int subId, int mode) {
9319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9320 mApp, subId, "setCdmaRoamingMode");
9321
9322 final long identity = Binder.clearCallingIdentity();
9323 try {
9324 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
9329
9330 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009331 public int getCdmaSubscriptionMode(int subId) {
9332 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009333 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009334 mApp, subId, "getCdmaSubscriptionMode");
9335
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9339 } finally {
9340 Binder.restoreCallingIdentity(identity);
9341 }
9342 }
9343
9344 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009345 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9347 mApp, subId, "setCdmaSubscriptionMode");
9348
9349 final long identity = Binder.clearCallingIdentity();
9350 try {
9351 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009356
sqianc5eccab2018-10-19 18:46:41 -07009357 @Override
sqian8c685422019-02-22 15:55:18 -08009358 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009359 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009361 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9362 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009363 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9364 }
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
sqian854d44b2018-12-12 16:48:18 -08009367 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9368 for (Phone phone: PhoneFactory.getPhones()) {
9369 if (phone.getEmergencyNumberTracker() != null
9370 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9371 emergencyNumberListInternal.put(
9372 phone.getSubId(),
9373 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9374 }
sqian11b7a0e2018-12-05 18:48:28 -08009375 }
sqian854d44b2018-12-12 16:48:18 -08009376 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
sqianc5eccab2018-10-19 18:46:41 -07009380 }
9381
9382 @Override
sqian8c685422019-02-22 15:55:18 -08009383 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009384 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009385 if (!exactMatch) {
9386 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009387 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009388 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009389 }
9390 final long identity = Binder.clearCallingIdentity();
9391 try {
sqian854d44b2018-12-12 16:48:18 -08009392 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009393 //Note: we ignore passed in param exactMatch. We can remove it once
9394 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009395 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009396 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009397 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009398 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009399 }
sqian11b7a0e2018-12-05 18:48:28 -08009400 }
9401 return false;
9402 } finally {
9403 Binder.restoreCallingIdentity(identity);
9404 }
9405 }
9406
sqianf4ca7ed2019-01-15 18:32:07 -08009407 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009408 * Start emergency callback mode for GsmCdmaPhone for testing.
9409 */
9410 @Override
9411 public void startEmergencyCallbackMode() {
9412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9413 "startEmergencyCallbackMode");
9414 enforceModifyPermission();
9415 final long identity = Binder.clearCallingIdentity();
9416 try {
9417 for (Phone phone : PhoneFactory.getPhones()) {
9418 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9419 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9420 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9421 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9422 gsmCdmaPhone.obtainMessage(
9423 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9424 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9425 }
9426 }
9427 } finally {
9428 Binder.restoreCallingIdentity(identity);
9429 }
9430 }
9431
9432 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009433 * Update emergency number list for test mode.
9434 */
9435 @Override
9436 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9438 "updateEmergencyNumberListTestMode");
9439
9440 final long identity = Binder.clearCallingIdentity();
9441 try {
9442 for (Phone phone: PhoneFactory.getPhones()) {
9443 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9444 if (tracker != null) {
9445 tracker.executeEmergencyNumberTestModeCommand(action, num);
9446 }
9447 }
9448 } finally {
9449 Binder.restoreCallingIdentity(identity);
9450 }
9451 }
9452
9453 /**
9454 * Get the full emergency number list for test mode.
9455 */
9456 @Override
9457 public List<String> getEmergencyNumberListTestMode() {
9458 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9459 "getEmergencyNumberListTestMode");
9460
9461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 Set<String> emergencyNumbers = new HashSet<>();
9464 for (Phone phone: PhoneFactory.getPhones()) {
9465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9466 if (tracker != null) {
9467 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9468 emergencyNumbers.add(num.getNumber());
9469 }
9470 }
9471 }
9472 return new ArrayList<>(emergencyNumbers);
9473 } finally {
9474 Binder.restoreCallingIdentity(identity);
9475 }
9476 }
9477
chen xud6b45bd2018-10-30 22:27:10 -07009478 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009479 public int getEmergencyNumberDbVersion(int subId) {
9480 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9481
9482 final long identity = Binder.clearCallingIdentity();
9483 try {
9484 final Phone phone = getPhone(subId);
9485 if (phone == null) {
9486 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9487 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9488 }
9489 return phone.getEmergencyNumberDbVersion();
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
9494
9495 @Override
9496 public void notifyOtaEmergencyNumberDbInstalled() {
9497 enforceModifyPermission();
9498
9499 final long identity = Binder.clearCallingIdentity();
9500 try {
9501 for (Phone phone: PhoneFactory.getPhones()) {
9502 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9503 if (tracker != null) {
9504 tracker.updateOtaEmergencyNumberDatabase();
9505 }
9506 }
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
9511
9512 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009513 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009514 enforceActiveEmergencySessionPermission();
9515
9516 final long identity = Binder.clearCallingIdentity();
9517 try {
9518 for (Phone phone: PhoneFactory.getPhones()) {
9519 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9520 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009521 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9522 }
9523 }
9524 } finally {
9525 Binder.restoreCallingIdentity(identity);
9526 }
9527 }
9528
9529 @Override
9530 public void resetOtaEmergencyNumberDbFilePath() {
9531 enforceActiveEmergencySessionPermission();
9532
9533 final long identity = Binder.clearCallingIdentity();
9534 try {
9535 for (Phone phone: PhoneFactory.getPhones()) {
9536 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9537 if (tracker != null) {
9538 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009539 }
9540 }
9541 } finally {
9542 Binder.restoreCallingIdentity(identity);
9543 }
9544 }
9545
9546 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009547 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9548 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9549 Phone phone = getPhone(subId);
9550 if (phone == null) {
9551 return null;
9552 }
9553 final long identity = Binder.clearCallingIdentity();
9554 try {
9555 UiccProfile profile = UiccController.getInstance()
9556 .getUiccProfileForPhone(phone.getPhoneId());
9557 if (profile != null) {
9558 return profile.getCertsFromCarrierPrivilegeAccessRules();
9559 }
9560 } finally {
9561 Binder.restoreCallingIdentity(identity);
9562 }
9563 return null;
9564 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009565
9566 /**
9567 * Enable or disable a modem stack.
9568 */
9569 @Override
9570 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9571 enforceModifyPermission();
9572
9573 final long identity = Binder.clearCallingIdentity();
9574 try {
9575 Phone phone = PhoneFactory.getPhone(slotIndex);
9576 if (phone == null) {
9577 return false;
9578 } else {
9579 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9580 }
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
Michelecea4cf22018-12-21 15:00:11 -08009585
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009586 /**
9587 * Whether a modem stack is enabled or not.
9588 */
9589 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009590 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9591 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009592 Phone phone = PhoneFactory.getPhone(slotIndex);
9593 if (phone == null) return false;
9594
9595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009596 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9597 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009598 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9599 }
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009603 try {
9604 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9605 } catch (NoSuchElementException ex) {
9606 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9607 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
9611 }
9612
Michelecea4cf22018-12-21 15:00:11 -08009613 @Override
Michele0ea7d782019-03-19 14:58:42 -07009614 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009615 enforceModifyPermission();
9616
9617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009620 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009621 .commit();
9622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 @Override
Michele0ea7d782019-03-19 14:58:42 -07009628 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009629 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009631 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9632 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009633 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009634 }
Michelecea4cf22018-12-21 15:00:11 -08009635
9636 final long identity = Binder.clearCallingIdentity();
9637 try {
Michele0ea7d782019-03-19 14:58:42 -07009638 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009639 } finally {
9640 Binder.restoreCallingIdentity(identity);
9641 }
9642 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009643
Michele0ea7d782019-03-19 14:58:42 -07009644 @TelephonyManager.IsMultiSimSupportedResult
9645 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009646 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9647 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9648 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009649 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9650 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009651 }
9652 // Check if the hardware supports multisim functionality. If usage of multisim is not
9653 // supported by the modem, indicate that it is restricted.
9654 PhoneCapability staticCapability =
9655 mPhoneConfigurationManager.getStaticPhoneCapability();
9656 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009657 loge("isMultiSimSupportedInternal: no static configuration available");
9658 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009659 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009660 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009661 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9662 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009663 }
9664 // Check if support of multiple SIMs is restricted by carrier
9665 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009666 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009667 }
9668
Michele0ea7d782019-03-19 14:58:42 -07009669 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009670 }
9671
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009672 /**
9673 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009674 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9675 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9676 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009677 * @param numOfSims number of active sims we want to switch to
9678 */
9679 @Override
9680 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009681 if (numOfSims == 1) {
9682 enforceModifyPermission();
9683 } else {
9684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9685 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9686 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009687 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009688
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009689 try {
Michele30b57b22019-03-01 12:01:14 -08009690 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009691 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009692 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9693 return;
9694 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009695 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699 }
9700
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009701 @Override
9702 public boolean isApplicationOnUicc(int subId, int appType) {
9703 enforceReadPrivilegedPermission("isApplicationOnUicc");
9704 Phone phone = getPhone(subId);
9705 if (phone == null) {
9706 return false;
9707 }
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009710 UiccPort uiccPort = phone.getUiccPort();
9711 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009712 return false;
9713 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009714 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009715 if (uiccProfile == null) {
9716 return false;
9717 }
9718 if (TelephonyManager.APPTYPE_SIM <= appType
9719 && appType <= TelephonyManager.APPTYPE_ISIM) {
9720 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9721 }
9722 return false;
9723 } finally {
9724 Binder.restoreCallingIdentity(identity);
9725 }
9726 }
9727
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009728 /**
chen xub4baa772019-04-03 10:23:41 -07009729 * Get whether making changes to modem configurations will trigger reboot.
9730 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009731 */
9732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009733 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9734 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009736 mApp, subId, callingPackage, callingFeatureId,
9737 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009738 return false;
9739 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009740 final long identity = Binder.clearCallingIdentity();
9741 try {
9742 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
9745 }
9746 }
9747
Nathan Harold29f5f052019-02-15 13:41:57 -08009748 private void updateModemStateMetrics() {
9749 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9750 // TODO: check the state for each modem if the api is ready.
9751 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9752 }
9753
Pengquan Meng3889a572019-01-23 11:16:29 -08009754 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009755 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009756 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009757 // Verify that the callingPackage belongs to the calling UID
9758 mApp.getSystemService(AppOpsManager.class)
9759 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009760 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009761 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009762 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009763 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9764 if (slotInfos != null) {
9765 for (int i = 0; i < slotInfos.length; i++) {
9766 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9767 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9768 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9769 portInfo.getLogicalSlotIndex()));
9770 }
9771 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009772 }
9773 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009774 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009775 } finally {
9776 Binder.restoreCallingIdentity(identity);
9777 }
9778 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009779
9780 /**
9781 * Get the IRadio HAL Version
9782 */
9783 @Override
9784 public int getRadioHalVersion() {
9785 Phone phone = getDefaultPhone();
9786 if (phone == null) return -1;
9787 HalVersion hv = phone.getHalVersion();
9788 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9789 return hv.major * 100 + hv.minor;
9790 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009791
9792 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009793 * Get the current calling package name.
9794 * @return the current calling package name
9795 */
9796 @Override
9797 public String getCurrentPackageName() {
9798 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9799 }
9800
9801 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009802 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9803 * corresponding network requests on a subId.
9804 *
9805 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009806 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009807 * 2) APN is un-metered for this subscription, or
9808 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009809 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009810 *
9811 * @return whether data is allowed for a apn type.
9812 *
9813 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009814 */
9815 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009816 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009817 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9818 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009819
9820 // Now that all security checks passes, perform the operation as ourselves.
9821 final long identity = Binder.clearCallingIdentity();
9822 try {
9823 Phone phone = getPhone(subId);
9824 if (phone == null) return false;
9825
Jack Yu27422a52022-03-21 10:38:05 -07009826 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009827 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009828 isMetered = phone.getDataNetworkController().getDataConfigManager()
9829 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9830 phone.getServiceState().getDataRoaming());
9831 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009832 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 }
9837
9838 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009839 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009840 enforceReadPrivilegedPermission("isApnMetered");
9841
9842 // Now that all security checks passes, perform the operation as ourselves.
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
9845 Phone phone = getPhone(subId);
9846 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009847 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9848 DataUtils.apnTypeToNetworkCapability(apnType),
9849 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009850 } finally {
9851 Binder.restoreCallingIdentity(identity);
9852 }
9853 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009854
9855 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009856 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9857 int subscriptionId, IBooleanConsumer resultCallback) {
9858 enforceModifyPermission();
9859 long token = Binder.clearCallingIdentity();
9860 try {
9861 Phone phone = getPhone(subscriptionId);
9862 if (phone == null) {
9863 try {
9864 if (resultCallback != null) {
9865 resultCallback.accept(false);
9866 }
9867 } catch (RemoteException e) {
9868 // ignore
9869 }
9870 return;
9871 }
9872 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9873 Pair.create(specifiers, (x) -> {
9874 try {
9875 if (resultCallback != null) {
9876 resultCallback.accept(x);
9877 }
9878 } catch (RemoteException e) {
9879 // ignore
9880 }
9881 });
9882 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9883 } finally {
9884 Binder.restoreCallingIdentity(token);
9885 }
9886 }
9887
9888 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009889 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9890 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009891 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009892 mApp, subId, "getSystemSelectionChannels");
9893 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9894 final long identity = Binder.clearCallingIdentity();
9895 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009896 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9897 if (result instanceof IllegalStateException) {
9898 throw (IllegalStateException) result;
9899 }
9900 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009901 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9902 return specifiers;
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009909 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009910 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009911 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009912 }
9913
9914 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009915 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9916 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009917 if (callingPackage == null) {
9918 callingPackage = getCurrentPackageName();
9919 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009920 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9921 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009922 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9923 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009924 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9925 }
9926 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9927 Intent intent = new Intent();
9928 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9929 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9930 // Bring up choose default SMS subscription dialog right now
9931 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9932 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9933 mApp.startActivity(intent);
9934 }
chen xud5ca2d52019-05-28 15:20:57 -07009935
9936 @Override
9937 public String getMmsUAProfUrl(int subId) {
9938 //TODO investigate if this API should require proper permission check in R b/133791609
9939 final long identity = Binder.clearCallingIdentity();
9940 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009941 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9942 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9943 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9944 return carrierUAProfUrl;
9945 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009946 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9947 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 }
9952
9953 @Override
9954 public String getMmsUserAgent(int subId) {
9955 //TODO investigate if this API should require proper permission check in R b/133791609
9956 final long identity = Binder.clearCallingIdentity();
9957 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009958 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9959 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9960 if (!TextUtils.isEmpty(carrierUserAgent)) {
9961 return carrierUserAgent;
9962 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009963 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9964 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
Jack Yub07d4972019-05-28 16:12:25 -07009969
9970 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009971 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9972 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009973
Jack Yub07d4972019-05-28 16:12:25 -07009974 final long identity = Binder.clearCallingIdentity();
9975 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009976 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009977 if (phone == null) return false;
9978
Ling Maf188d502022-09-16 15:22:36 -07009979 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009980 } finally {
9981 Binder.restoreCallingIdentity(identity);
9982 }
9983 }
9984
9985 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009986 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009987 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009988 enforceModifyPermission();
9989
changbettyd5c246e2019-12-24 15:40:37 +08009990 final long identity = Binder.clearCallingIdentity();
9991 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009992 Phone phone = getPhone(subscriptionId);
9993 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009994
Ling Maf188d502022-09-16 15:22:36 -07009995 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009996 } finally {
9997 Binder.restoreCallingIdentity(identity);
9998 }
9999 }
10000
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010001 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010002 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010003 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10004 * otherwise.
10005 */
10006 @Override
10007 public void setCepEnabled(boolean isCepEnabled) {
10008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10009
10010 final long identity = Binder.clearCallingIdentity();
10011 try {
10012 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10013 for (Phone phone : PhoneFactory.getPhones()) {
10014 Phone defaultPhone = phone.getImsPhone();
10015 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10016 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10017 ImsPhoneCallTracker imsPhoneCallTracker =
10018 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10019 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10020 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10021 + imsPhone.getMsisdn());
10022 }
10023 }
10024 } finally {
10025 Binder.restoreCallingIdentity(identity);
10026 }
10027 }
allenwtsu46dcc572020-01-08 18:24:03 +080010028
10029 /**
10030 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10031 *
10032 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10033 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10034 * before being read.
10035 */
10036 @Override
10037 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10038 isCompressed) {
10039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10040 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010041 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10042 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10043 }
10044 if (!isImsAvailableOnDevice()) {
10045 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10046 "IMS not available on device.");
10047 }
10048
10049 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010050 try {
Hui Wang761a6682020-10-31 05:12:53 +000010051 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10052 } finally {
10053 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010054 }
10055 }
zoey chene02881a2019-12-30 16:11:23 +080010056
10057 @Override
10058 public boolean isIccLockEnabled(int subId) {
10059 enforceReadPrivilegedPermission("isIccLockEnabled");
10060
10061 // Now that all security checks passes, perform the operation as ourselves.
10062 final long identity = Binder.clearCallingIdentity();
10063 try {
10064 Phone phone = getPhone(subId);
10065 if (phone != null && phone.getIccCard() != null) {
10066 return phone.getIccCard().getIccLockEnabled();
10067 } else {
10068 return false;
10069 }
10070 } finally {
10071 Binder.restoreCallingIdentity(identity);
10072 }
10073 }
10074
10075 /**
10076 * Set the ICC pin lock enabled or disabled.
10077 *
10078 * @return an integer representing the status of IccLock enabled or disabled in the following
10079 * three cases:
10080 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10081 * successfully.
10082 * - Positive number and zero for remaining password attempts.
10083 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10084 *
10085 */
10086 @Override
10087 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10088 enforceModifyPermission();
10089
10090 Phone phone = getPhone(subId);
10091 if (phone == null) {
10092 return 0;
10093 }
10094 // Now that all security checks passes, perform the operation as ourselves.
10095 final long identity = Binder.clearCallingIdentity();
10096 try {
10097 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10098 new Pair<Boolean, String>(enabled, password), phone, null);
10099 return attemptsRemaining;
10100
10101 } catch (Exception e) {
10102 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10103 } finally {
10104 Binder.restoreCallingIdentity(identity);
10105 }
10106 return 0;
10107 }
10108
10109 /**
10110 * Change the ICC password used in ICC pin lock.
10111 *
10112 * @return an integer representing the status of IccLock changed in the following three cases:
10113 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10114 * - Positive number and zero for remaining password attempts.
10115 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10116 *
10117 */
10118 @Override
10119 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10120 enforceModifyPermission();
10121
10122 Phone phone = getPhone(subId);
10123 if (phone == null) {
10124 return 0;
10125 }
10126 // Now that all security checks passes, perform the operation as ourselves.
10127 final long identity = Binder.clearCallingIdentity();
10128 try {
10129 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10130 new Pair<String, String>(oldPassword, newPassword), phone, null);
10131 return attemptsRemaining;
10132
10133 } catch (Exception e) {
10134 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10135 } finally {
10136 Binder.restoreCallingIdentity(identity);
10137 }
10138 return 0;
10139 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010140
10141 /**
10142 * Request for receiving user activity notification
10143 */
10144 @Override
10145 public void requestUserActivityNotification() {
10146 if (!mNotifyUserActivity.get()
10147 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10148 mNotifyUserActivity.set(true);
10149 }
10150 }
10151
10152 /**
10153 * Called when userActivity is signalled in the power manager.
10154 * This is safe to call from any thread, with any window manager locks held or not.
10155 */
10156 @Override
10157 public void userActivity() {
10158 // ***************************************
10159 // * Inherited from PhoneWindowManager *
10160 // ***************************************
10161 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10162 // WITH ITS LOCKS HELD.
10163 //
10164 // This code must be VERY careful about the locks
10165 // it acquires.
10166 // In fact, the current code acquires way too many,
10167 // and probably has lurking deadlocks.
10168
10169 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10170 throw new SecurityException("Only the OS may call notifyUserActivity()");
10171 }
10172
10173 if (mNotifyUserActivity.getAndSet(false)) {
10174 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10175 USER_ACTIVITY_NOTIFICATION_DELAY);
10176 }
10177 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010178
10179 @Override
10180 public boolean canConnectTo5GInDsdsMode() {
10181 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10182 }
Jack Yud10cdd42020-09-28 20:28:01 -070010183
10184 @Override
10185 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10186 String callingFeatureId) {
10187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10188 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10189 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10190 }
10191
10192 Phone phone = getPhone(subId);
10193 if (phone == null) {
10194 throw new RuntimeException("phone is not available");
10195 }
10196 // Now that all security checks passes, perform the operation as ourselves.
10197 final long identity = Binder.clearCallingIdentity();
10198 try {
10199 return phone.getEquivalentHomePlmns();
10200 } finally {
10201 Binder.restoreCallingIdentity(identity);
10202 }
10203 }
Daniel Bright59e67312020-11-13 11:49:37 -080010204
10205 @Override
10206 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010207 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10208 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010209 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010210 if (radioInterfaceCapabilities == null) {
10211 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010212 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010213 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010214 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010215
Hui Wang641e81c2020-10-12 12:14:23 -070010216 @Override
10217 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10218 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010219 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10220 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10221 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10222 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10223 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010224 if (DBG) {
10225 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10226 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10227 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10228 }
10229
10230 if (!SubscriptionManager.isValidSubscriptionId(subId)
10231 || appType < TelephonyManager.APPTYPE_UNKNOWN
10232 || appType > TelephonyManager.APPTYPE_ISIM
10233 || nafUrl == null || securityProtocol == null || callback == null) {
10234 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10235 if (callback != null) {
10236 try {
10237 callback.onAuthenticationFailure(
10238 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10239 } catch (RemoteException exception) {
10240 log("Fail to notify onAuthenticationFailure due to " + exception);
10241 }
10242 return;
10243 }
10244 }
10245
10246 final long token = Binder.clearCallingIdentity();
10247 try {
10248 getGbaManager(subId).bootstrapAuthenticationRequest(
10249 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10250 forceBootStrapping, callback));
10251 } finally {
10252 Binder.restoreCallingIdentity(token);
10253 }
10254 }
10255
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010256 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010257 * Attempts to set the radio power state for all phones for thermal reason.
10258 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010259 * requested radio power state will actually be set. See {@link
10260 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10261 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010262 * @param enable {@code true} if trying to turn radio on.
10263 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10264 * false}.
10265 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010266 private boolean setRadioPowerForThermal(boolean enable) {
10267 boolean isPhoneAvailable = false;
10268 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10269 Phone phone = PhoneFactory.getPhone(i);
10270 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010271 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010272 isPhoneAvailable = true;
10273 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010274 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010275
10276 // return true if successfully informed the phone object about the thermal radio power
10277 // request.
10278 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010279 }
10280
10281 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010282 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010283 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10284 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10285 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10286 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10287 throw new IllegalArgumentException("modem does not support data throttling");
10288 }
10289
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10291 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010292 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010293 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10294 }
10295
Sarah Chinecc78c42022-03-31 21:16:48 -070010296 setDataEnabledForReason(
10297 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010298
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010299 if (isDataThrottlingSupported) {
10300 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010301 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010302 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10303 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10304 } else if (thermalMitigationResult
10305 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010306 log("Modem likely does not support data throttling on secondary carrier. Data " +
10307 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10308 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010309 }
10310 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010312
10313 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010314 }
10315
Jack Nudelman644b91a2021-03-12 14:09:48 -080010316 private static List<String> getThermalMitigationAllowlist(Context context) {
10317 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10318 for (String pckg : context.getResources()
10319 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10320 sThermalMitigationAllowlistedPackages.add(pckg);
10321 }
10322 }
10323
10324 return sThermalMitigationAllowlistedPackages;
10325 }
10326
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010327 private boolean isAnyPhoneInEmergencyState() {
10328 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10329 if (tm.isInEmergencyCall()) {
10330 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10331 return true;
10332 }
10333 for (Phone phone : PhoneFactory.getPhones()) {
10334 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10335 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10336 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10337 + phone.isInEcm());
10338 return true;
10339 }
10340 }
10341
10342 return false;
10343 }
10344
Jack Nudelman644b91a2021-03-12 14:09:48 -080010345 /**
10346 * Used by shell commands to add an authorized package name for thermal mitigation.
10347 * @param packageName name of package to be allowlisted
10348 * @param context
10349 */
10350 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10351 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10352 sThermalMitigationAllowlistedPackages.add(packageName);
10353 }
10354
10355 /**
10356 * Used by shell commands to remove an authorized package name for thermal mitigation.
10357 * @param packageName name of package to remove from allowlist
10358 * @param context
10359 */
10360 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10361 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10362 sThermalMitigationAllowlistedPackages.remove(packageName);
10363 }
10364
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010365 /**
10366 * Thermal mitigation request to control functionalities at modem.
10367 *
10368 * @param subId the id of the subscription.
10369 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010370 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010371 *
10372 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10373 */
10374 @Override
10375 @ThermalMitigationResult
10376 public int sendThermalMitigationRequest(
10377 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010378 ThermalMitigationRequest thermalMitigationRequest,
10379 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010380 enforceModifyPermission();
10381
Jack Nudelman644b91a2021-03-12 14:09:48 -080010382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10383 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10384 .contains(callingPackage)) {
10385 throw new SecurityException("Calling package must be configured in the device config. "
10386 + "calling package: " + callingPackage);
10387 }
10388
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010389 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10390 final long identity = Binder.clearCallingIdentity();
10391
10392 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10393 try {
10394 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10395 switch (thermalMitigationAction) {
10396 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10397 thermalMitigationResult =
10398 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010399 thermalMitigationRequest.getDataThrottlingRequest(),
10400 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010401 break;
10402 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10403 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10404 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10405 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10406 }
10407
10408 // Ensure that radio is on. If not able to power on due to phone being
10409 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010410 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010411 thermalMitigationResult =
10412 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10413 break;
10414 }
10415
10416 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010417 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010418 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10419 break;
10420 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10421 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10422 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10423 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10424 }
10425
10426 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10427 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010428 Phone phone = getPhone(subId);
10429 if (phone == null) {
10430 thermalMitigationResult =
10431 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10432 break;
10433 }
10434
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010435 TelephonyConnectionService service =
10436 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010437 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010438 Log.e(LOG_TAG, "An emergency call is pending");
10439 thermalMitigationResult =
10440 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10441 break;
10442 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010443 thermalMitigationResult =
10444 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10445 break;
10446 }
10447 } else {
10448 thermalMitigationResult =
10449 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10450 break;
10451 }
10452
10453 // Turn radio off. If not able to power off due to phone being unavailable,
10454 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010455 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010456 thermalMitigationResult =
10457 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10458 break;
10459 }
10460 thermalMitigationResult =
10461 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10462 break;
10463 default:
10464 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10465 + "not exist. Requested action: " + thermalMitigationAction);
10466 }
10467 } catch (IllegalArgumentException e) {
10468 throw e;
10469 } catch (Exception e) {
10470 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10471 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10472 } finally {
10473 Binder.restoreCallingIdentity(identity);
10474 }
10475
10476 if (DBG) {
10477 log("thermalMitigationRequest returning with thermalMitigationResult: "
10478 + thermalMitigationResult);
10479 }
10480
10481 return thermalMitigationResult;
10482 }
Hui Wang641e81c2020-10-12 12:14:23 -070010483
10484 /**
10485 * Set the GbaService Package Name that Telephony will bind to.
10486 *
10487 * @param subId The sim that the GbaService is associated with.
10488 * @param packageName The name of the package to be replaced with.
10489 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10490 */
10491 @Override
10492 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10493 enforceModifyPermission();
10494
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 return getGbaManager(subId).overrideServicePackage(packageName);
10498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 /**
10504 * Return the package name of the currently bound GbaService.
10505 *
10506 * @param subId The sim that the GbaService is associated with.
10507 * @return the package name of the GbaService configuration, null if GBA is not supported.
10508 */
10509 @Override
10510 public String getBoundGbaService(int subId) {
10511 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10512
10513 final long identity = Binder.clearCallingIdentity();
10514 try {
10515 return getGbaManager(subId).getServicePackage();
10516 } finally {
10517 Binder.restoreCallingIdentity(identity);
10518 }
10519 }
10520
10521 /**
10522 * Set the release time for telephony to unbind GbaService.
10523 *
10524 * @param subId The sim that the GbaService is associated with.
10525 * @param interval The release time to unbind GbaService by millisecond.
10526 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10527 */
10528 @Override
10529 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10530 enforceModifyPermission();
10531
10532 final long identity = Binder.clearCallingIdentity();
10533 try {
10534 return getGbaManager(subId).overrideReleaseTime(interval);
10535 } finally {
10536 Binder.restoreCallingIdentity(identity);
10537 }
10538 }
10539
10540 /**
10541 * Return the release time for telephony to unbind GbaService.
10542 *
10543 * @param subId The sim that the GbaService is associated with.
10544 * @return The release time to unbind GbaService by millisecond.
10545 */
10546 @Override
10547 public int getGbaReleaseTime(int subId) {
10548 enforceReadPrivilegedPermission("getGbaReleaseTime");
10549
10550 final long identity = Binder.clearCallingIdentity();
10551 try {
10552 return getGbaManager(subId).getReleaseTime();
10553 } finally {
10554 Binder.restoreCallingIdentity(identity);
10555 }
10556 }
10557
10558 private GbaManager getGbaManager(int subId) {
10559 GbaManager instance = GbaManager.getInstance(subId);
10560 if (instance == null) {
10561 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10562 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10563 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10564 }
10565 return instance;
10566 }
Hui Wang761a6682020-10-31 05:12:53 +000010567
10568 /**
10569 * indicate whether the device and the carrier can support
10570 * RCS VoLTE single registration.
10571 */
10572 @Override
10573 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010574 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10575 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10576 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10577 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010578
10579 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10580 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10581 }
10582
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10586 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010587 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10588 if (isCapable != null) {
10589 return isCapable;
10590 }
Hui Wang761a6682020-10-31 05:12:53 +000010591 }
Hui Wang67af90e2021-06-04 16:57:15 -070010592 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10593 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
10599 /**
10600 * Register RCS provisioning callback.
10601 */
10602 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010603 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010604 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010605 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010606 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010607 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10608 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010609
10610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10611 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10612 }
10613 if (!isImsAvailableOnDevice()) {
10614 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10615 "IMS not available on device.");
10616 }
10617
10618 final long identity = Binder.clearCallingIdentity();
10619 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010620 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010621 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010622 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10623 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010624 }
Hui Wang761a6682020-10-31 05:12:53 +000010625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
10629
10630 /**
10631 * Unregister RCS provisioning callback.
10632 */
10633 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010634 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010635 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010636 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010637 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010638 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10639 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010640
10641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10643 }
10644 if (!isImsAvailableOnDevice()) {
10645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10646 "IMS not available on device.");
10647 }
10648
10649 final long identity = Binder.clearCallingIdentity();
10650 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010651 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010652 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
10658 /**
10659 * trigger RCS reconfiguration.
10660 */
10661 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010662 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10663 "triggerRcsReconfiguration",
10664 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010665
10666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10667 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10668 }
10669 if (!isImsAvailableOnDevice()) {
10670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10671 "IMS not available on device.");
10672 }
10673
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10677 } finally {
10678 Binder.restoreCallingIdentity(identity);
10679 }
10680 }
10681
10682 /**
10683 * Provide the client configuration parameters of the RCS application.
10684 */
10685 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010686 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10687 "setRcsClientConfiguration",
10688 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010689
10690 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10691 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10692 }
10693 if (!isImsAvailableOnDevice()) {
10694 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10695 "IMS not available on device.");
10696 }
10697
10698 final long identity = Binder.clearCallingIdentity();
10699
10700 try {
10701 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10702 if (configBinder == null) {
10703 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10705 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010706 } else {
10707 configBinder.setRcsClientConfiguration(rcc);
10708 }
joonhunshin3e154242021-09-17 06:33:39 +000010709
10710 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10711 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010712 } catch (RemoteException e) {
10713 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010714 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10715 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010716 } finally {
10717 Binder.restoreCallingIdentity(identity);
10718 }
10719 }
10720
10721 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010722 * Enables or disables the test mode for RCS VoLTE single registration.
10723 */
10724 @Override
10725 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10726 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10727 "setRcsSingleRegistrationTestModeEnabled");
10728
10729 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10730 }
10731
10732 /**
10733 * Gets the test mode for RCS VoLTE single registration.
10734 */
10735 @Override
10736 public boolean getRcsSingleRegistrationTestModeEnabled() {
10737 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10738 "getRcsSingleRegistrationTestModeEnabled");
10739
10740 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10741 }
10742
10743 /**
Hui Wang761a6682020-10-31 05:12:53 +000010744 * Overrides the config of RCS VoLTE single registration enabled for the device.
10745 */
10746 @Override
10747 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10749 "setDeviceSingleRegistrationEnabledOverride");
10750 enforceModifyPermission();
10751
10752 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10753 : Boolean.parseBoolean(enabledStr);
10754 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010755 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010756 }
10757
10758 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010759 * Sends a device to device communication message. Only usable via shell.
10760 * @param message message to send.
10761 * @param value message value.
10762 */
10763 @Override
10764 public void sendDeviceToDeviceMessage(int message, int value) {
10765 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010766 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010767 enforceModifyPermission();
10768
10769 final long identity = Binder.clearCallingIdentity();
10770 try {
10771 TelephonyConnectionService service =
10772 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10773 if (service == null) {
10774 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10775 return;
10776 }
10777 service.sendTestDeviceToDeviceMessage(message, value);
10778 } finally {
10779 Binder.restoreCallingIdentity(identity);
10780 }
10781 }
10782
Tyler Gunnbabbda02021-02-10 11:05:02 -080010783 /**
10784 * Sets the specified device to device transport active.
10785 * @param transport The transport to set active.
10786 */
10787 @Override
10788 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10790 "setActiveDeviceToDeviceTransport");
10791 enforceModifyPermission();
10792
10793 final long identity = Binder.clearCallingIdentity();
10794 try {
10795 TelephonyConnectionService service =
10796 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10797 if (service == null) {
10798 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10799 return;
10800 }
10801 service.setActiveDeviceToDeviceTransport(transport);
10802 } finally {
10803 Binder.restoreCallingIdentity(identity);
10804 }
10805 }
Tyler Gunn92479152021-01-20 16:30:10 -080010806
Tyler Gunnd4339262021-05-03 14:46:49 -070010807 @Override
10808 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10810 "setDeviceToDeviceForceEnabled");
10811
10812 final long identity = Binder.clearCallingIdentity();
10813 try {
10814 Arrays.stream(PhoneFactory.getPhones()).forEach(
10815 p -> {
10816 Phone thePhone = p.getImsPhone();
10817 if (thePhone != null && thePhone instanceof ImsPhone) {
10818 ImsPhone imsPhone = (ImsPhone) thePhone;
10819 CallTracker tracker = imsPhone.getCallTracker();
10820 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10821 ImsPhoneCallTracker imsPhoneCallTracker =
10822 (ImsPhoneCallTracker) tracker;
10823 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10824 }
10825 }
10826 }
10827 );
10828 } finally {
10829 Binder.restoreCallingIdentity(identity);
10830 }
10831 }
10832
Tyler Gunn92479152021-01-20 16:30:10 -080010833 /**
Hui Wang761a6682020-10-31 05:12:53 +000010834 * Gets the config of RCS VoLTE single registration enabled for the device.
10835 */
10836 @Override
10837 public boolean getDeviceSingleRegistrationEnabled() {
10838 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10839 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10840 }
10841
10842 /**
10843 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10844 */
10845 @Override
10846 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10848 "setCarrierSingleRegistrationEnabledOverride");
10849 enforceModifyPermission();
10850
10851 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10852 : Boolean.parseBoolean(enabledStr);
10853 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10854 subId, enabled);
10855 }
10856
10857 /**
10858 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10859 */
10860 @Override
10861 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10862 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10863 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10864 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010865
10866 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010867 * Overrides the ims feature validation result
10868 */
10869 @Override
10870 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10872 "setImsFeatureValidationOverride");
10873
10874 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10875 : Boolean.parseBoolean(enabledStr);
10876 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10877 subId, enabled);
10878 }
10879
10880 /**
10881 * Gets the ims feature validation override value
10882 */
10883 @Override
10884 public boolean getImsFeatureValidationOverride(int subId) {
10885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10886 "getImsFeatureValidationOverride");
10887 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10888 }
10889
10890 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010891 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10892 * their mobile plan.
10893 */
10894 @Override
10895 public String getMobileProvisioningUrl() {
10896 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10897 final long identity = Binder.clearCallingIdentity();
10898 try {
10899 return getDefaultPhone().getMobileProvisioningUrl();
10900 } finally {
10901 Binder.restoreCallingIdentity(identity);
10902 }
10903 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010904
James.cf Linbcdf8b32021-01-14 16:44:13 +080010905 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010906 * Get the EAB contact from the EAB database.
10907 */
10908 @Override
10909 public String getContactFromEab(String contact) {
10910 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10911 enforceModifyPermission();
10912 final long identity = Binder.clearCallingIdentity();
10913 try {
10914 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10915 } finally {
10916 Binder.restoreCallingIdentity(identity);
10917 }
10918 }
10919
10920 /**
Calvin Pana1434322021-07-01 19:27:01 +080010921 * Get the EAB capability from the EAB database.
10922 */
10923 @Override
10924 public String getCapabilityFromEab(String contact) {
10925 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10926 enforceModifyPermission();
10927 final long identity = Binder.clearCallingIdentity();
10928 try {
10929 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10930 } finally {
10931 Binder.restoreCallingIdentity(identity);
10932 }
10933 }
10934
10935 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010936 * Remove the EAB contacts from the EAB database.
10937 */
10938 @Override
10939 public int removeContactFromEab(int subId, String contacts) {
10940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10941 enforceModifyPermission();
10942 final long identity = Binder.clearCallingIdentity();
10943 try {
10944 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10945 } finally {
10946 Binder.restoreCallingIdentity(identity);
10947 }
10948 }
10949
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010950 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010951 public boolean getDeviceUceEnabled() {
10952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10953 final long identity = Binder.clearCallingIdentity();
10954 try {
10955 return mApp.getDeviceUceEnabled();
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
10961 @Override
10962 public void setDeviceUceEnabled(boolean isEnabled) {
10963 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10964 final long identity = Binder.clearCallingIdentity();
10965 try {
10966 mApp.setDeviceUceEnabled(isEnabled);
10967 } finally {
10968 Binder.restoreCallingIdentity(identity);
10969 }
10970 }
10971
Brad Ebinger14d467f2021-02-12 06:18:28 +000010972 /**
10973 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10974 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10975 */
10976 // Used for SHELL command only right now.
10977 @Override
10978 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10979 List<String> featureTags) {
10980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10981 "addUceRegistrationOverrideShell");
10982 final long identity = Binder.clearCallingIdentity();
10983 try {
10984 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10985 new ArraySet<>(featureTags));
10986 } catch (ImsException e) {
10987 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
10993 /**
10994 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10995 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10996 */
10997 // Used for SHELL command only right now.
10998 @Override
10999 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11000 List<String> featureTags) {
11001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11002 "removeUceRegistrationOverrideShell");
11003 final long identity = Binder.clearCallingIdentity();
11004 try {
11005 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11006 new ArraySet<>(featureTags));
11007 } catch (ImsException e) {
11008 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11009 } finally {
11010 Binder.restoreCallingIdentity(identity);
11011 }
11012 }
11013
11014 /**
11015 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11016 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11017 */
11018 // Used for SHELL command only right now.
11019 @Override
11020 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11022 "clearUceRegistrationOverrideShell");
11023 final long identity = Binder.clearCallingIdentity();
11024 try {
11025 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11026 } catch (ImsException e) {
11027 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11028 } finally {
11029 Binder.restoreCallingIdentity(identity);
11030 }
11031 }
11032
11033 /**
11034 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11035 */
11036 // Used for SHELL command only right now.
11037 @Override
11038 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11040 "getLatestRcsContactUceCapabilityShell");
11041 final long identity = Binder.clearCallingIdentity();
11042 try {
11043 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11044 } catch (ImsException e) {
11045 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11046 } finally {
11047 Binder.restoreCallingIdentity(identity);
11048 }
11049 }
11050
11051 /**
11052 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11053 * device does not have an active PUBLISH.
11054 */
11055 // Used for SHELL command only right now.
11056 @Override
11057 public String getLastUcePidfXmlShell(int subId) {
11058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11059 final long identity = Binder.clearCallingIdentity();
11060 try {
11061 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11062 } catch (ImsException e) {
11063 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11064 } finally {
11065 Binder.restoreCallingIdentity(identity);
11066 }
11067 }
11068
James.cf Line8713a42021-04-29 16:04:26 +080011069 /**
11070 * Remove UCE requests cannot be sent to the network status.
11071 */
11072 // Used for SHELL command only right now.
11073 @Override
11074 public boolean removeUceRequestDisallowedStatus(int subId) {
11075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11076 final long identity = Binder.clearCallingIdentity();
11077 try {
11078 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11079 } catch (ImsException e) {
11080 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11081 } finally {
11082 Binder.restoreCallingIdentity(identity);
11083 }
11084 }
11085
James.cf Lin18bb9002021-05-25 01:37:38 +080011086 /**
11087 * Remove UCE requests cannot be sent to the network status.
11088 */
11089 // Used for SHELL command only.
11090 @Override
11091 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11093 final long identity = Binder.clearCallingIdentity();
11094 try {
11095 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11096 } catch (ImsException e) {
11097 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011102
James.cf Lin4b784aa2021-01-31 03:25:15 +080011103 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011104 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11105 String callingPackage) {
11106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11107 mApp, subId, "setSignalStrengthUpdateRequest");
11108
11109 final int callingUid = Binder.getCallingUid();
11110 // Verify that tha callingPackage belongs to the calling UID
11111 mApp.getSystemService(AppOpsManager.class)
11112 .checkPackage(callingUid, callingPackage);
11113
Rambo Wang3607f502021-02-01 21:51:40 -080011114 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011115
11116 final long identity = Binder.clearCallingIdentity();
11117 try {
11118 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11119 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11120
11121 if (result instanceof IllegalStateException) {
11122 throw (IllegalStateException) result;
11123 }
11124 } finally {
11125 Binder.restoreCallingIdentity(identity);
11126 }
11127 }
11128
11129 @Override
11130 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11131 String callingPackage) {
11132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11133 mApp, subId, "clearSignalStrengthUpdateRequest");
11134
11135 final int callingUid = Binder.getCallingUid();
11136 // Verify that tha callingPackage belongs to the calling UID
11137 mApp.getSystemService(AppOpsManager.class)
11138 .checkPackage(callingUid, callingPackage);
11139
11140 final long identity = Binder.clearCallingIdentity();
11141 try {
11142 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11143 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11144
11145 if (result instanceof IllegalStateException) {
11146 throw (IllegalStateException) result;
11147 }
11148 } finally {
11149 Binder.restoreCallingIdentity(identity);
11150 }
11151 }
11152
Rambo Wang3607f502021-02-01 21:51:40 -080011153 private static void validateSignalStrengthUpdateRequest(Context context,
11154 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011155 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11156 // phone/system process do not have further restriction on request
11157 return;
11158 }
11159
11160 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011161 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011162 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011163 context.enforceCallingOrSelfPermission(
11164 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11165 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011166 }
11167
11168 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11169 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11170 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11171 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11172 || info.isEnabled()) {
11173 throw new IllegalArgumentException(
11174 "Only system can set hide fields in SignalThresholdInfo");
11175 }
11176
11177 // Thresholds length for each RAN need in range. This has been validated in
11178 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11179 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11180 final int[] thresholds = info.getThresholds();
11181 Objects.requireNonNull(thresholds);
11182 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11183 || thresholds.length
11184 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11185 throw new IllegalArgumentException(
11186 "thresholds length is out of range: " + thresholds.length);
11187 }
11188 }
11189 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011190
11191 /**
11192 * Gets the current phone capability.
11193 *
11194 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11195 * @return the PhoneCapability which describes the data connection capability of modem.
11196 * It's used to evaluate possible phone config change, for example from single
11197 * SIM device to multi-SIM device.
11198 */
11199 @Override
11200 public PhoneCapability getPhoneCapability() {
11201 enforceReadPrivilegedPermission("getPhoneCapability");
11202 final long identity = Binder.clearCallingIdentity();
11203 try {
11204 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11205 } finally {
11206 Binder.restoreCallingIdentity(identity);
11207 }
11208 }
Michele Berionne5e411512020-11-13 02:36:59 +000011209
11210 /**
11211 * Prepare TelephonyManager for an unattended reboot. The reboot is
11212 * required to be done shortly after the API is invoked.
11213 */
11214 @Override
11215 @TelephonyManager.PrepareUnattendedRebootResult
11216 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011217 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011218 enforceRebootPermission();
11219
11220 final long identity = Binder.clearCallingIdentity();
11221 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011222 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011223 } finally {
11224 Binder.restoreCallingIdentity(identity);
11225 }
11226 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011227
11228 /**
11229 * Request to get the current slicing configuration including URSP rules and
11230 * NSSAIs (configured, allowed and rejected).
11231 *
11232 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11233 */
11234 @Override
11235 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011236 TelephonyPermissions
11237 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11238 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011239
11240 final long identity = Binder.clearCallingIdentity();
11241 try {
11242 Phone phone = getDefaultPhone();
11243 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11244 } finally {
11245 Binder.restoreCallingIdentity(identity);
11246 }
11247 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011248
11249 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011250 * Check whether the given premium capability is available for purchase from the carrier.
11251 *
11252 * @param capability The premium capability to check.
11253 * @param subId The subId to check the premium capability for.
11254 *
11255 * @return Whether the given premium capability is available to purchase.
11256 */
11257 @Override
11258 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11259 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11260 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11261 log("Premium capability "
11262 + TelephonyManager.convertPremiumCapabilityToString(capability)
11263 + " is not available for purchase due to missing permissions.");
11264 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11265 + "permission READ_BASIC_PHONE_STATE.");
11266 }
11267
11268 Phone phone = getPhone(subId);
11269 final long identity = Binder.clearCallingIdentity();
11270 try {
Sarah Chin46355ba2022-11-01 23:51:16 -070011271 return SlicePurchaseController.getInstance(phone)
Sarah Chin2ec39f62022-08-31 17:03:26 -070011272 .isPremiumCapabilityAvailableForPurchase(capability);
11273 } finally {
11274 Binder.restoreCallingIdentity(identity);
11275 }
11276 }
11277
11278 /**
11279 * Purchase the given premium capability from the carrier.
11280 *
11281 * @param capability The premium capability to purchase.
11282 * @param callback The result of the purchase request.
11283 * @param subId The subId to purchase the premium capability for.
11284 */
11285 @Override
11286 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11287 log("purchasePremiumCapability: capability="
11288 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11289 + getCurrentPackageName());
11290
11291 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11292 mApp, "purchasePremiumCapability")) {
11293 log("purchasePremiumCapability "
11294 + TelephonyManager.convertPremiumCapabilityToString(capability)
11295 + " failed due to missing permissions.");
11296 throw new SecurityException("purchasePremiumCapability requires permission "
11297 + "READ_BASIC_PHONE_STATE.");
11298 }
11299
11300 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011301 String appName;
11302 try {
11303 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11304 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11305 } catch (PackageManager.NameNotFoundException e) {
11306 appName = "An application";
11307 }
11308 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11309 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011310 }
11311
11312 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011313 * Register an IMS connection state callback
11314 */
11315 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011316 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11317 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011318 if (feature == ImsFeature.FEATURE_MMTEL) {
11319 // ImsMmTelManager
11320 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11321 TelephonyPermissions
11322 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11323 mApp, subId, "registerImsStateCallback");
11324 } else if (feature == ImsFeature.FEATURE_RCS) {
11325 // ImsRcsManager or SipDelegateManager
11326 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11327 Binder.getCallingUid(), "registerImsStateCallback",
11328 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11329 Manifest.permission.READ_PRECISE_PHONE_STATE,
11330 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11331 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11332 }
11333
11334 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11336 "IMS not available on device.");
11337 }
11338
11339 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11340 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11341 }
11342
11343 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11344 if (controller == null) {
11345 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11346 "IMS not available on device.");
11347 }
11348
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011349 if (callingPackage == null) {
11350 callingPackage = getCurrentPackageName();
11351 }
11352
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011353 final long token = Binder.clearCallingIdentity();
11354 try {
11355 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011356 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011357 } catch (ImsException e) {
11358 throw new ServiceSpecificException(e.getCode());
11359 } finally {
11360 Binder.restoreCallingIdentity(token);
11361 }
11362 }
11363
11364 /**
11365 * Unregister an IMS connection state callback
11366 */
11367 @Override
11368 public void unregisterImsStateCallback(IImsStateCallback cb) {
11369 final long token = Binder.clearCallingIdentity();
11370 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11371 if (controller == null) {
11372 return;
11373 }
11374 try {
11375 controller.unregisterImsStateCallback(cb);
11376 } finally {
11377 Binder.restoreCallingIdentity(token);
11378 }
11379 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011380
11381 /**
11382 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11383 *
11384 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11385 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11386 * SecurityException.
11387 * If there is current registered network this value will be same as the registered cell
11388 * identity. If the device goes out of service the previous cell identity is cached and
11389 * will be returned. If the cache age of the Cell identity is more than 24 hours
11390 * it will be cleared and null will be returned.
11391 *
11392 */
11393 @Override
11394 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11395 String callingFeatureId) {
11396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11397 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11398 LocationAccessPolicy.checkLocationPermission(mApp,
11399 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11400 .setCallingPackage(callingPackage)
11401 .setCallingFeatureId(callingFeatureId)
11402 .setCallingPid(Binder.getCallingPid())
11403 .setCallingUid(Binder.getCallingUid())
11404 .setMethod("getLastKnownCellIdentity")
11405 .setLogAsInfo(true)
11406 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11407 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11408 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11409 .build());
11410
11411 boolean hasFinePermission =
11412 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11413 if (!hasFinePermission
11414 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11415 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011416 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011417 }
11418
11419 final long identity = Binder.clearCallingIdentity();
11420 try {
11421 Phone phone = getPhone(subId);
11422 if (phone == null) return null;
11423 ServiceStateTracker sst = phone.getServiceStateTracker();
11424 if (sst == null) return null;
11425 return sst.getLastKnownCellIdentity();
11426 } finally {
11427 Binder.restoreCallingIdentity(identity);
11428 }
11429 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011430
jimsun3b9ccac2021-10-26 15:01:23 +080011431 /**
11432 * Sets the modem service class Name that Telephony will bind to.
11433 *
11434 * @param serviceName The class name of the modem service.
11435 * @return true if the operation is succeed, otherwise false.
11436 */
11437 public boolean setModemService(String serviceName) {
11438 Log.d(LOG_TAG, "setModemService - " + serviceName);
11439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11441 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11442 "setModemService");
11443 return mPhoneConfigurationManager.setModemService(serviceName);
11444 }
11445
11446 /**
11447 * Return the class name of the currently bounded modem service.
11448 *
11449 * @return the class name of the modem service.
11450 */
11451 public String getModemService() {
11452 String result;
11453 Log.d(LOG_TAG, "getModemService");
11454 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11455 TelephonyPermissions
11456 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11457 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11458 "getModemService");
11459 result = mPhoneConfigurationManager.getModemService();
11460 Log.d(LOG_TAG, "result = " + result);
11461 return result;
11462 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011463
11464 @Override
11465 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11466 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11467 mApp.enforceCallingOrSelfPermission(
11468 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11470
11471 final long identity = Binder.clearCallingIdentity();
11472 try {
11473 Phone phone = getPhone(subId);
11474 if (phone == null) return;
11475 phone.setVoiceServiceStateOverride(hasService);
11476 } finally {
11477 Binder.restoreCallingIdentity(identity);
11478 }
11479 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011480
11481 /**
11482 * set removable eSIM as default eUICC.
11483 *
11484 * @hide
11485 */
11486 @Override
11487 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11488 enforceModifyPermission();
11489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11490
11491 final long identity = Binder.clearCallingIdentity();
11492 try {
11493 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11494 } finally {
11495 Binder.restoreCallingIdentity(identity);
11496 }
11497 }
11498
11499 /**
11500 * Returns whether the removable eSIM is default eUICC or not.
11501 *
11502 * @hide
11503 */
11504 @Override
11505 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11506 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11507 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11508
11509 final long identity = Binder.clearCallingIdentity();
11510 try {
11511 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11512 } finally {
11513 Binder.restoreCallingIdentity(identity);
11514 }
11515 }
11516
11517
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011518}