blob: 385efdb26c1195146da005b9ff0dd067c113d800 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.Looper;
54import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070055import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080056import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070057import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070058import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080059import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080060import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070061import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070062import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080063import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070065import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070066import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070067import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070068import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080069import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070070import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090071import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080072import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080073import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070074import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080075import android.telephony.AccessNetworkConstants;
76import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070077import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070078import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080079import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070080import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800113import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800114import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700118import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800120import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800121import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700122import android.telephony.gba.GbaAuthRequest;
123import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700124import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000127import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700128import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000129import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700132import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700136import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700187import com.android.internal.telephony.data.DataUtils;
Jack Yuf745f972022-08-15 19:53:50 +0000188import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700214import com.android.phone.slicestore.SliceStore;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800231import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800232import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800234import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100235import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700237import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800239import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700240import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700364 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
365 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800367 // Parameters of select command.
368 private static final int SELECT_COMMAND = 0xA4;
369 private static final int SELECT_P1 = 0x04;
370 private static final int SELECT_P2 = 0;
371 private static final int SELECT_P3 = 0x10;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /** The singleton instance. */
374 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800375 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800379 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700380 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700382 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800384 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700386 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800387 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Sarah Chin2ec39f62022-08-31 17:03:26 -0700414 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
415 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
416
Derek Tan89e89d42014-07-08 17:00:10 -0700417 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700418 * Experiment flag to enable erase modem config on reset network, default value is false
419 */
420 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
421 "reset_network_erase_modem_config_enabled";
422
Rambo Wang0f050d82021-02-12 11:43:36 -0800423 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800424
sandeepjsb6c87872021-09-27 15:34:44 +0000425 /**
426 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
427 * one ICCID active at the same time.
428 * Apps should use below API signatures if targeting SDK is T and beyond.
429 *
430 * @hide
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800435
Naina Nallurid63128d2019-09-17 14:10:30 -0700436 /**
Chen Xu540470b2021-12-14 17:15:47 -0800437 * Apps targeting on Android T and beyond will get exception whenever icc close channel
438 * operation fails.
439 */
440 @ChangeId
441 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
442 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
443
444 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class IccAPDUArgument {
448 public int channel, cla, command, p1, p2, p3;
449 public String data;
450
451 public IccAPDUArgument(int channel, int cla, int command,
452 int p1, int p2, int p3, String data) {
453 this.channel = channel;
454 this.cla = cla;
455 this.command = command;
456 this.p1 = p1;
457 this.p2 = p2;
458 this.p3 = p3;
459 this.data = data;
460 }
461 }
462
463 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700464 * A request object to use for transmitting data to an ICC.
465 */
466 private static final class ManualNetworkSelectionArgument {
467 public OperatorInfo operatorInfo;
468 public boolean persistSelection;
469
470 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
471 this.operatorInfo = operatorInfo;
472 this.persistSelection = persistSelection;
473 }
474 }
475
476 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
478 * request after sending. The main thread will notify the request when it is complete.
479 */
480 private static final class MainThreadRequest {
481 /** The argument to use for the request */
482 public Object argument;
483 /** The result of the request that is run on the main thread */
484 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800485 // The subscriber id that this request applies to. Defaults to
486 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
487 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Nathan Harold92bed182018-10-12 18:16:49 -0700489 // In cases where subId is unavailable, the caller needs to specify the phone.
490 public Phone phone;
491
vagdeviaf9a5b92018-08-15 16:01:53 -0700492 public WorkSource workSource;
493
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700494 public MainThreadRequest(Object argument) {
495 this.argument = argument;
496 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800497
Nathan Harold92bed182018-10-12 18:16:49 -0700498 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
499 this.argument = argument;
500 if (phone != null) {
501 this.phone = phone;
502 }
503 this.workSource = workSource;
504 }
505
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800507 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800508 if (subId != null) {
509 this.subId = subId;
510 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700511 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513 }
514
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800515 private static final class IncomingThirdPartyCallArgs {
516 public final ComponentName component;
517 public final String callId;
518 public final String callerDisplayName;
519
520 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
521 String callerDisplayName) {
522 this.component = component;
523 this.callId = callId;
524 this.callerDisplayName = callerDisplayName;
525 }
526 }
527
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700528 /**
529 * A handler that processes messages on the main thread in the phone process. Since many
530 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
531 * inbound binder threads to the main thread in the phone process. The Binder thread
532 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
533 * on, which will be notified when the operation completes and will contain the result of the
534 * request.
535 *
536 * <p>If a MainThreadRequest object is provided in the msg.obj field,
537 * note that request.result must be set to something non-null for the calling thread to
538 * unblock.
539 */
540 private final class MainThreadHandler extends Handler {
541 @Override
542 public void handleMessage(Message msg) {
543 MainThreadRequest request;
544 Message onCompleted;
545 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000546 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800548 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549
550 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 case CMD_HANDLE_USSD_REQUEST: {
552 request = (MainThreadRequest) msg.obj;
553 final Phone phone = getPhoneFromRequest(request);
554 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800555 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700557
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 if (!isUssdApiAllowed(request.subId)) {
559 // Carrier does not support use of this API, return failure.
560 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
561 UssdResponse response = new UssdResponse(ussdRequest, null);
562 Bundle returnData = new Bundle();
563 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
564 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700565
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 request.result = true;
567 notifyRequester(request);
568 return;
569 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700570
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 try {
572 request.result = phone != null
573 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
574 } catch (CallStateException cse) {
575 request.result = false;
576 }
577 // Wake up the requesting thread
578 notifyRequester(request);
579 break;
pkanwar32d516d2016-10-14 19:37:38 -0700580 }
581
Yorke Lee716f67e2015-06-17 15:39:16 -0700582 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700584 final Phone phone = getPhoneFromRequest(request);
585 request.result = phone != null ?
586 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
587 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700588 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700590 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700592
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000596 uiccPort = getUiccPortFromRequest(request);
597 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800599 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800603 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000604 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800605 iccArgument.channel, iccArgument.cla, iccArgument.command,
606 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
607 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700608 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 break;
610
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 ar = (AsyncResult) msg.obj;
613 request = (MainThreadRequest) ar.userObj;
614 if (ar.exception == null && ar.result != null) {
615 request.result = ar.result;
616 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800617 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.result == null) {
619 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800620 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800622 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
624 loge("iccTransmitApduLogicalChannel: Unknown exception");
625 }
626 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
631 request = (MainThreadRequest) msg.obj;
632 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000633 uiccPort = getUiccPortFromRequest(request);
634 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800636 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800640 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000641 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800642 iccArgument.cla, iccArgument.command, iccArgument.p1,
643 iccArgument.p2,
644 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 }
646 break;
647
648 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result;
653 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800654 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700655 if (ar.result == null) {
656 loge("iccTransmitApduBasicChannel: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("iccTransmitApduBasicChannel: CommandException: " +
659 ar.exception);
660 } else {
661 loge("iccTransmitApduBasicChannel: Unknown exception");
662 }
663 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700665 break;
666
667 case CMD_EXCHANGE_SIM_IO:
668 request = (MainThreadRequest) msg.obj;
669 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000670 uiccPort = getUiccPortFromRequest(request);
671 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700672 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800673 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700675 } else {
676 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
677 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000678 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
680 iccArgument.data, onCompleted);
681 }
682 break;
683
684 case EVENT_EXCHANGE_SIM_IO_DONE:
685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
687 if (ar.exception == null && ar.result != null) {
688 request.result = ar.result;
689 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800690 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700692 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 break;
694
Derek Tan4d5e5c12014-02-04 11:54:58 -0800695 case CMD_SEND_ENVELOPE:
696 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000697 uiccPort = getUiccPortFromRequest(request);
698 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800700 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700702 } else {
703 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800704 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700705 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800706 break;
707
708 case EVENT_SEND_ENVELOPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800713 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700715 if (ar.result == null) {
716 loge("sendEnvelopeWithStatus: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("sendEnvelopeWithStatus: CommandException: " +
719 ar.exception);
720 } else {
721 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
722 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800723 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700724 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800725 break;
726
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 case CMD_OPEN_CHANNEL:
728 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000729 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800730 IccLogicalChannelRequest openChannelRequest =
731 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000732 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800734 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800735 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700737 } else {
738 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800739 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
740 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case EVENT_OPEN_CHANNEL_DONE:
745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700747 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700749 int[] result = (int[]) ar.result;
750 int channelId = result[0];
751 byte[] selectResponse = null;
752 if (result.length > 1) {
753 selectResponse = new byte[result.length - 1];
754 for (int i = 1; i < result.length; ++i) {
755 selectResponse[i - 1] = (byte) result[i];
756 }
757 }
758 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800759 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800760
761 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700762 if (uiccPort == null) {
763 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
764 } else {
765 IccLogicalChannelRequest channelRequest =
766 (IccLogicalChannelRequest) request.argument;
767 channelRequest.channel = channelId;
768 uiccPort.onLogicalChannelOpened(channelRequest);
769 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 if (ar.result == null) {
772 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700774 if (ar.exception != null) {
775 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
776 }
777
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700778 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700779 if (ar.exception instanceof CommandException) {
780 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800781 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700782 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700783 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700784 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700785 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700786 }
787 }
788 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800789 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700790 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700791 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700792 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700793 break;
794
795 case CMD_CLOSE_CHANNEL:
796 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000797 uiccPort = getUiccPortFromRequest(request);
798 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700799 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800800 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800801 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800802 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700803 } else {
804 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000805 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700806 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 break;
808
809 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800810 ar = (AsyncResult) msg.obj;
811 request = (MainThreadRequest) ar.userObj;
812 if (ar.exception == null) {
813 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800814 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700815 if (uiccPort == null) {
816 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
817 } else {
818 final int channelId = (Integer) request.argument;
819 uiccPort.onLogicalChannelClosed(channelId);
820 }
Chen Xu540470b2021-12-14 17:15:47 -0800821 } else {
822 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800823 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800824 if (ar.exception instanceof CommandException) {
825 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
826 CommandException.Error error =
827 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800828 if (error == CommandException.Error.INVALID_ARGUMENTS) {
829 // should only throw exceptions from the binder threads.
830 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800831 "iccCloseLogicalChannel: invalid argument ");
832 }
833 } else {
834 loge("iccCloseLogicalChannel: Unknown exception");
835 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800836 request.result = (exception != null) ? exception :
837 new IllegalStateException(
838 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800839 }
840 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800841 break;
842
843 case CMD_NV_READ_ITEM:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800846 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
847 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800848 break;
849
850 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700855 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800856 request.result = "";
857 if (ar.result == null) {
858 loge("nvReadItem: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("nvReadItem: CommandException: " +
861 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800863 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 }
865 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700866 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700867 break;
868
Jake Hambye994d462014-02-03 13:10:13 -0800869 case CMD_NV_WRITE_ITEM:
870 request = (MainThreadRequest) msg.obj;
871 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
872 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800873 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700874 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800875 break;
876
877 case EVENT_NV_WRITE_ITEM_DONE:
878 handleNullReturnEvent(msg, "nvWriteItem");
879 break;
880
881 case CMD_NV_WRITE_CDMA_PRL:
882 request = (MainThreadRequest) msg.obj;
883 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800884 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800885 break;
886
887 case EVENT_NV_WRITE_CDMA_PRL_DONE:
888 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
889 break;
890
chen xu6dac5ab2018-10-26 17:39:23 -0700891 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800892 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700893 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800894 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800895 break;
896
chen xu6dac5ab2018-10-26 17:39:23 -0700897 case EVENT_RESET_MODEM_CONFIG_DONE:
898 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800899 break;
900
Sooraj Sasindran37444802020-08-11 10:40:43 -0700901 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
902 request = (MainThreadRequest) msg.obj;
903 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
904 request);
905 Phone phone = getPhoneFromRequest(request);
906 if (phone != null) {
907 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
908 } else {
909 loge("isNRDualConnectivityEnabled: No phone object");
910 request.result = false;
911 notifyRequester(request);
912 }
913 break;
914 }
915
916 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
922 // request.result must be set to something non-null
923 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700924 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700925 request.result = ar.result;
926 } else {
927 request.result = false;
928 }
929 if (ar.result == null) {
930 loge("isNRDualConnectivityEnabled: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("isNRDualConnectivityEnabled: CommandException: "
933 + ar.exception);
934 } else {
935 loge("isNRDualConnectivityEnabled: Unknown exception");
936 }
937 }
938 notifyRequester(request);
939 break;
940
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700941 case CMD_IS_VONR_ENABLED: {
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
944 request);
945 Phone phone = getPhoneFromRequest(request);
946 if (phone != null) {
947 phone.isVoNrEnabled(onCompleted, request.workSource);
948 } else {
949 loge("isVoNrEnabled: No phone object");
950 request.result = false;
951 notifyRequester(request);
952 }
953 break;
954 }
955
956 case EVENT_IS_VONR_ENABLED_DONE:
957 ar = (AsyncResult) msg.obj;
958 request = (MainThreadRequest) ar.userObj;
959 if (ar.exception == null && ar.result != null) {
960 request.result = ar.result;
961 } else {
962 // request.result must be set to something non-null
963 // for the calling thread to unblock
964 if (ar.result != null) {
965 request.result = ar.result;
966 } else {
967 request.result = false;
968 }
969 if (ar.result == null) {
970 loge("isVoNrEnabled: Empty response");
971 } else if (ar.exception instanceof CommandException) {
972 loge("isVoNrEnabled: CommandException: "
973 + ar.exception);
974 } else {
975 loge("isVoNrEnabled: Unknown exception");
976 }
977 }
978 notifyRequester(request);
979 break;
980
Sooraj Sasindran37444802020-08-11 10:40:43 -0700981 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
984 Phone phone = getPhoneFromRequest(request);
985 if (phone != null) {
986 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
987 request.workSource);
988 } else {
989 loge("enableNrDualConnectivity: No phone object");
990 request.result =
991 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
992 notifyRequester(request);
993 }
994 break;
995 }
996
997 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null) {
1001 request.result =
1002 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1003 } else {
1004 request.result =
1005 TelephonyManager
1006 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1007 if (ar.exception instanceof CommandException) {
1008 CommandException.Error error =
1009 ((CommandException) (ar.exception)).getCommandError();
1010 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1011 request.result =
1012 TelephonyManager
1013 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001014 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1015 request.result =
1016 TelephonyManager
1017 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001018 }
1019 loge("enableNrDualConnectivity" + ": CommandException: "
1020 + ar.exception);
1021 } else {
1022 loge("enableNrDualConnectivity" + ": Unknown exception");
1023 }
1024 }
1025 notifyRequester(request);
1026 break;
1027 }
1028
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001029 case CMD_ENABLE_VONR: {
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1032 Phone phone = getPhoneFromRequest(request);
1033 if (phone != null) {
1034 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1035 request.workSource);
1036 } else {
1037 loge("setVoNrEnabled: No phone object");
1038 request.result =
1039 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1040 notifyRequester(request);
1041 }
1042 break;
1043 }
1044
1045 case EVENT_ENABLE_VONR_DONE: {
1046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
1048 if (ar.exception == null) {
1049 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1050 } else {
1051 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1052 if (ar.exception instanceof CommandException) {
1053 CommandException.Error error =
1054 ((CommandException) (ar.exception)).getCommandError();
1055 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1056 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1057 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1058 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1059 } else {
1060 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1061 }
1062 loge("setVoNrEnabled" + ": CommandException: "
1063 + ar.exception);
1064 } else {
1065 loge("setVoNrEnabled" + ": Unknown exception");
1066 }
1067 }
1068 notifyRequester(request);
1069 break;
1070 }
1071
SongFerngWang3ef3e072020-12-21 16:41:52 +08001072 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001073 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001074 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1075 request);
1076 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001077 break;
1078
SongFerngWang3ef3e072020-12-21 16:41:52 +08001079 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 if (ar.exception == null && ar.result != null) {
1083 request.result = ar.result; // Integer
1084 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301085 // request.result must be set to something non-null
1086 // for the calling thread to unblock
1087 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001091 loge("getAllowedNetworkTypesBitmask: CommandException: "
1092 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001094 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001095 }
1096 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001097 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001098 break;
1099
SongFerngWang3ef3e072020-12-21 16:41:52 +08001100 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1103 request);
1104 Pair<Integer, Long> reasonWithNetworkTypes =
1105 (Pair<Integer, Long>) request.argument;
1106 getPhoneFromRequest(request).setAllowedNetworkTypes(
1107 reasonWithNetworkTypes.first,
1108 reasonWithNetworkTypes.second,
1109 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001110 break;
1111
SongFerngWang3ef3e072020-12-21 16:41:52 +08001112 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1113 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 break;
1115
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001116 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1117 request = (MainThreadRequest)msg.obj;
1118 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001119 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001120 break;
1121
1122 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1123 ar = (AsyncResult)msg.obj;
1124 request = (MainThreadRequest)ar.userObj;
1125 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001127 break;
1128
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001129 case CMD_SET_VOICEMAIL_NUMBER:
1130 request = (MainThreadRequest) msg.obj;
1131 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1132 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001133 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1134 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001135 break;
1136
1137 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1138 handleNullReturnEvent(msg, "setVoicemailNumber");
1139 break;
1140
Stuart Scott54788802015-03-30 13:18:01 -07001141 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1144 request);
1145 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1146 break;
1147
1148 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1149 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1150 break;
1151
Shishir Agrawal302c8692015-06-19 13:49:39 -07001152 case CMD_PERFORM_NETWORK_SCAN:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1155 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1156 break;
1157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 request = (MainThreadRequest) msg.obj;
1160 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001161 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1162 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1163 request.argument;
1164 int callForwardingReason = args.first;
1165 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001166 break;
Hall Liu27d24262020-09-18 19:04:59 -07001167 }
1168 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001171 TelephonyManager.CallForwardingInfoCallback callback =
1172 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1173 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001174 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001175 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001176 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1177 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1178 // Service Class is a bit mask per 3gpp 27.007. Search for
1179 // any service for voice call.
1180 if ((callForwardInfo.serviceClass
1181 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001182 callForwardingInfo = new CallForwardingInfo(
1183 callForwardInfo.status
1184 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001185 callForwardInfo.reason,
1186 callForwardInfo.number,
1187 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001188 break;
1189 }
1190 }
1191 // Didn't find a call forward info for voice call.
1192 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001193 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1194 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001195 }
Hall Liu27d24262020-09-18 19:04:59 -07001196 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001197 } else {
1198 if (ar.result == null) {
1199 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1200 }
1201 if (ar.exception != null) {
1202 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1203 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001204 int errorCode = TelephonyManager
1205 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 if (ar.exception instanceof CommandException) {
1207 CommandException.Error error =
1208 ((CommandException) (ar.exception)).getCommandError();
1209 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001210 errorCode = TelephonyManager
1211 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001212 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001213 errorCode = TelephonyManager
1214 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001215 }
1216 }
Hall Liu27d24262020-09-18 19:04:59 -07001217 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001218 }
Shuo Qian4a594052020-01-23 11:59:30 -08001219 break;
Hall Liu27d24262020-09-18 19:04:59 -07001220 }
Shuo Qian4a594052020-01-23 11:59:30 -08001221
Hall Liu27d24262020-09-18 19:04:59 -07001222 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001225 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001227 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1228 request.argument).first;
1229 request.phone.setCallForwardingOption(
1230 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001231 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001232 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001233 callForwardingInfoToSet.getReason(),
1234 callForwardingInfoToSet.getNumber(),
1235 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1236 break;
Hall Liu27d24262020-09-18 19:04:59 -07001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001242 Consumer<Integer> callback =
1243 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1244 request.argument).second;
1245 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001246 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001247 int errorCode = TelephonyManager.CallForwardingInfoCallback
1248 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001249 if (ar.exception instanceof CommandException) {
1250 CommandException.Error error =
1251 ((CommandException) (ar.exception)).getCommandError();
1252 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001253 errorCode = TelephonyManager.CallForwardingInfoCallback
1254 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001255 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001256 errorCode = TelephonyManager.CallForwardingInfoCallback
1257 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001258 }
1259 }
1260 callback.accept(errorCode);
1261 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001262 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001263 }
Shuo Qian4a594052020-01-23 11:59:30 -08001264 break;
Hall Liu27d24262020-09-18 19:04:59 -07001265 }
Shuo Qian4a594052020-01-23 11:59:30 -08001266
Hall Liu27d24262020-09-18 19:04:59 -07001267 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001268 request = (MainThreadRequest) msg.obj;
1269 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1270 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1271 break;
Hall Liu27d24262020-09-18 19:04:59 -07001272 }
Shuo Qian4a594052020-01-23 11:59:30 -08001273
Hall Liu27d24262020-09-18 19:04:59 -07001274 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001277 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001278 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001279 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001280 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001281 // Service Class is a bit mask per 3gpp 27.007.
1282 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001283 if (callForwardResults.length > 1
1284 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001285 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001286 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001287 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1288 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001289 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001290 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001291 }
1292 } else {
1293 if (ar.result == null) {
1294 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1295 }
1296 if (ar.exception != null) {
1297 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1298 }
1299 if (ar.exception instanceof CommandException) {
1300 CommandException.Error error =
1301 ((CommandException) (ar.exception)).getCommandError();
1302 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001304 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001305 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1306 callWaitingStatus =
1307 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001308 }
1309 }
1310 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001311 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001312 break;
Hall Liu27d24262020-09-18 19:04:59 -07001313 }
Shuo Qian4a594052020-01-23 11:59:30 -08001314
Hall Liu27d24262020-09-18 19:04:59 -07001315 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001318 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1319 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001320 break;
Hall Liu27d24262020-09-18 19:04:59 -07001321 }
Shuo Qian4a594052020-01-23 11:59:30 -08001322
Hall Liu27d24262020-09-18 19:04:59 -07001323 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001326 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1327 Consumer<Integer> callback =
1328 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1329 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001331 if (ar.exception instanceof CommandException) {
1332 CommandException.Error error =
1333 ((CommandException) (ar.exception)).getCommandError();
1334 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001336 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1337 callback.accept(
1338 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001339 } else {
1340 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1341 }
1342 } else {
1343 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1344 }
1345 } else {
1346 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1347 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001348 }
Shuo Qian4a594052020-01-23 11:59:30 -08001349 break;
Hall Liu27d24262020-09-18 19:04:59 -07001350 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001351 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
1354 CellNetworkScanResult cellScanResult;
1355 if (ar.exception == null && ar.result != null) {
1356 cellScanResult = new CellNetworkScanResult(
1357 CellNetworkScanResult.STATUS_SUCCESS,
1358 (List<OperatorInfo>) ar.result);
1359 } else {
1360 if (ar.result == null) {
1361 loge("getCellNetworkScanResults: Empty response");
1362 }
1363 if (ar.exception != null) {
1364 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1365 }
1366 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1367 if (ar.exception instanceof CommandException) {
1368 CommandException.Error error =
1369 ((CommandException) (ar.exception)).getCommandError();
1370 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1371 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1372 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1373 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1374 }
1375 }
1376 cellScanResult = new CellNetworkScanResult(errorCode, null);
1377 }
1378 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001379 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001380 break;
1381
1382 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1383 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001384 ManualNetworkSelectionArgument selArg =
1385 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001386 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1387 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001388 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1389 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001390 break;
1391
1392 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 if (ar.exception == null) {
1396 request.result = true;
1397 } else {
1398 request.result = false;
1399 loge("setNetworkSelectionModeManual " + ar.exception);
1400 }
1401 notifyRequester(request);
1402 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 break;
1404
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001405 case CMD_GET_MODEM_ACTIVITY_INFO:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001408 if (defaultPhone != null) {
1409 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001410 } else {
1411 ResultReceiver result = (ResultReceiver) request.argument;
1412 Bundle bundle = new Bundle();
1413 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001414 new ModemActivityInfo(0, 0, 0,
1415 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001416 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001417 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 break;
1419
Hall Liud0f208c2020-10-14 16:54:44 -07001420 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001423 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001424 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001425 if (mLastModemActivityInfo == null) {
1426 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1427 mLastModemActivitySpecificInfo[0] =
1428 new ActivityStatsTechSpecificInfo(
1429 0,
1430 0,
1431 new int[ModemActivityInfo.getNumTxPowerLevels()],
1432 0);
1433 mLastModemActivityInfo =
1434 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1435 }
1436
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001437 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001438 // Update the last modem activity info and the result of the request.
1439 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1440 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001441 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001442 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001443 mLastModemActivityInfo =
1444 new ModemActivityInfo(
1445 mLastModemActivityInfo.getTimestampMillis(),
1446 mLastModemActivityInfo.getSleepTimeMillis(),
1447 mLastModemActivityInfo.getIdleTimeMillis(),
1448 mLastModemActivitySpecificInfo);
1449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 } else {
1451 if (ar.result == null) {
1452 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001453 error = TelephonyManager.ModemActivityInfoException
1454 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001455 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001457 error = TelephonyManager.ModemActivityInfoException
1458 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001459 } else {
1460 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001461 error = TelephonyManager.ModemActivityInfoException
1462 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 }
1464 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001465 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001466 if (mLastModemActivityInfo != null) {
1467 bundle.putParcelable(
1468 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1469 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001470 } else {
1471 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1472 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001473 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001474 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001475 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001476 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477
Meng Wang1a7c35a2016-05-05 20:56:15 -07001478 case CMD_SET_ALLOWED_CARRIERS:
1479 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001480 CarrierRestrictionRules argument =
1481 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001482 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001483 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001484 break;
1485
1486 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
1489 if (ar.exception == null && ar.result != null) {
1490 request.result = ar.result;
1491 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001492 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1493 if (ar.exception instanceof CommandException) {
1494 loge("setAllowedCarriers: CommandException: " + ar.exception);
1495 CommandException.Error error =
1496 ((CommandException) (ar.exception)).getCommandError();
1497 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1498 request.result =
1499 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1500 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001501 } else {
1502 loge("setAllowedCarriers: Unknown exception");
1503 }
1504 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001505 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001506 break;
1507
1508 case CMD_GET_ALLOWED_CARRIERS:
1509 request = (MainThreadRequest) msg.obj;
1510 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001511 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001512 break;
1513
1514 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null && ar.result != null) {
1518 request.result = ar.result;
1519 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001520 request.result = new IllegalStateException(
1521 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001522 if (ar.result == null) {
1523 loge("getAllowedCarriers: Empty response");
1524 } else if (ar.exception instanceof CommandException) {
1525 loge("getAllowedCarriers: CommandException: " +
1526 ar.exception);
1527 } else {
1528 loge("getAllowedCarriers: Unknown exception");
1529 }
1530 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001531 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001532 break;
1533
Nathan Haroldb3014052017-01-25 15:57:32 -08001534 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1535 ar = (AsyncResult) msg.obj;
1536 request = (MainThreadRequest) ar.userObj;
1537 if (ar.exception == null && ar.result != null) {
1538 request.result = ar.result;
1539 } else {
1540 request.result = new IllegalArgumentException(
1541 "Failed to retrieve Forbidden Plmns");
1542 if (ar.result == null) {
1543 loge("getForbiddenPlmns: Empty response");
1544 } else {
1545 loge("getForbiddenPlmns: Unknown exception");
1546 }
1547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001548 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001549 break;
1550
1551 case CMD_GET_FORBIDDEN_PLMNS:
1552 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001553 uiccPort = getUiccPortFromRequest(request);
1554 if (uiccPort == null) {
1555 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001556 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001557 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001558 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001559 break;
1560 }
1561 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001562 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 if (uiccApp == null) {
1564 loge("getForbiddenPlmns() no app with specified type -- "
1565 + appType);
1566 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001567 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001568 break;
1569 } else {
1570 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1571 + " specified type -- " + appType);
1572 }
1573 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1574 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1575 onCompleted);
1576 break;
1577
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 case CMD_SWITCH_SLOTS:
1579 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001580 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001582 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001583 break;
1584
1585 case EVENT_SWITCH_SLOTS_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
1588 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001589 notifyRequester(request);
1590 break;
1591 case CMD_GET_NETWORK_SELECTION_MODE:
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1594 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1595 break;
1596
1597 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 if (ar.exception != null) {
1601 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1602 } else {
1603 int mode = ((int[]) ar.result)[0];
1604 if (mode == 0) {
1605 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1606 } else {
1607 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1608 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001610 notifyRequester(request);
1611 break;
1612 case CMD_GET_CDMA_ROAMING_MODE:
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1615 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1616 break;
1617 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception != null) {
1621 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1622 } else {
1623 request.result = ((int[]) ar.result)[0];
1624 }
1625 notifyRequester(request);
1626 break;
1627 case CMD_SET_CDMA_ROAMING_MODE:
1628 request = (MainThreadRequest) msg.obj;
1629 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1630 int mode = (int) request.argument;
1631 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1632 break;
1633 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1634 ar = (AsyncResult) msg.obj;
1635 request = (MainThreadRequest) ar.userObj;
1636 request.result = ar.exception == null;
1637 notifyRequester(request);
1638 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001639 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1640 request = (MainThreadRequest) msg.obj;
1641 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1642 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1643 break;
1644 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1645 ar = (AsyncResult) msg.obj;
1646 request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception != null) {
1648 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1649 } else {
1650 request.result = ((int[]) ar.result)[0];
1651 }
1652 notifyRequester(request);
1653 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001654 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1655 request = (MainThreadRequest) msg.obj;
1656 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1657 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001658 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1659 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001660 break;
1661 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 request.result = ar.exception == null;
1665 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001666 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 case CMD_GET_ALL_CELL_INFO:
1668 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001669 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001670 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001671 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001672 case EVENT_GET_ALL_CELL_INFO_DONE:
1673 ar = (AsyncResult) msg.obj;
1674 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001675 // If a timeout occurs, the response will be null
1676 request.result = (ar.exception == null && ar.result != null)
1677 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001678 synchronized (request) {
1679 request.notifyAll();
1680 }
1681 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001682 case CMD_REQUEST_CELL_INFO_UPDATE:
1683 request = (MainThreadRequest) msg.obj;
1684 request.phone.requestCellInfoUpdate(request.workSource,
1685 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1686 break;
1687 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1688 ar = (AsyncResult) msg.obj;
1689 request = (MainThreadRequest) ar.userObj;
1690 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1691 try {
1692 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001694 cb.onError(
1695 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1696 ar.exception.getClass().getName(),
1697 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001698 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001699 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001700 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001701 } else {
1702 // use the result as returned
1703 cb.onCellInfo((List<CellInfo>) ar.result);
1704 }
1705 } catch (RemoteException re) {
1706 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1707 }
1708 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001709 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001710 request = (MainThreadRequest) msg.obj;
1711 WorkSource ws = (WorkSource) request.argument;
1712 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001713 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001714 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001715 }
1716 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 if (ar.exception == null) {
1720 request.result = ar.result;
1721 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001724 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001725 }
1726
1727 synchronized (request) {
1728 request.notifyAll();
1729 }
1730 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001731 }
chen xu6dac5ab2018-10-26 17:39:23 -07001732 case CMD_MODEM_REBOOT:
1733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001735 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001736 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001737 case EVENT_CMD_MODEM_REBOOT_DONE:
1738 handleNullReturnEvent(msg, "rebootModem");
1739 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001740 case CMD_REQUEST_ENABLE_MODEM:
1741 request = (MainThreadRequest) msg.obj;
1742 boolean enable = (boolean) request.argument;
1743 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001744 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001745 PhoneConfigurationManager.getInstance()
1746 .enablePhone(request.phone, enable, onCompleted);
1747 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001748 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001752 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001753 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001754 if ((boolean) request.result) {
1755 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1756 updateModemStateMetrics();
1757 } else {
1758 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1759 + ar.exception);
1760 }
1761 notifyRequester(request);
1762 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001763 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001764 case CMD_GET_MODEM_STATUS:
1765 request = (MainThreadRequest) msg.obj;
1766 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1767 PhoneConfigurationManager.getInstance()
1768 .getPhoneStatusFromModem(request.phone, onCompleted);
1769 break;
1770 case EVENT_GET_MODEM_STATUS_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 int id = request.phone.getPhoneId();
1774 if (ar.exception == null && ar.result != null) {
1775 request.result = ar.result;
1776 //update the cache as modem status has changed
1777 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1778 (boolean) request.result);
1779 } else {
1780 // Return true if modem status cannot be retrieved. For most cases,
1781 // modem status is on. And for older version modems, GET_MODEM_STATUS
1782 // and disable modem are not supported. Modem is always on.
1783 // TODO: this should be fixed in R to support a third
1784 // status UNKNOWN b/131631629
1785 request.result = true;
1786 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1787 + ar.exception);
1788 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001789 notifyRequester(request);
1790 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001791 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1792 request = (MainThreadRequest) msg.obj;
1793 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1794 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1795 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1796 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1797 break;
1798 }
1799 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1803 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1804 args.second.accept(ar.exception == null);
1805 notifyRequester(request);
1806 break;
1807 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001808 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1811 Phone phone = getPhoneFromRequest(request);
1812 if (phone != null) {
1813 phone.getSystemSelectionChannels(onCompleted);
1814 } else {
1815 loge("getSystemSelectionChannels: No phone object");
1816 request.result = new ArrayList<RadioAccessSpecifier>();
1817 notifyRequester(request);
1818 }
1819 break;
1820 }
1821 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null && ar.result != null) {
1825 request.result = ar.result;
1826 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001827 request.result = new IllegalStateException(
1828 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001829 if (ar.result == null) {
1830 loge("getSystemSelectionChannels: Empty response");
1831 } else {
1832 loge("getSystemSelectionChannels: Unknown exception");
1833 }
1834 }
1835 notifyRequester(request);
1836 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001837 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 if (ar.exception == null && ar.result != null) {
1841 request.result = ar.result;
1842 } else {
1843 request.result = -1;
1844 loge("Failed to set Forbidden Plmns");
1845 if (ar.result == null) {
1846 loge("setForbidenPlmns: Empty response");
1847 } else if (ar.exception != null) {
1848 loge("setForbiddenPlmns: Exception: " + ar.exception);
1849 request.result = -1;
1850 } else {
1851 loge("setForbiddenPlmns: Unknown exception");
1852 }
1853 }
1854 notifyRequester(request);
1855 break;
1856 case CMD_SET_FORBIDDEN_PLMNS:
1857 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001858 uiccPort = getUiccPortFromRequest(request);
1859 if (uiccPort == null) {
1860 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001861 request.result = -1;
1862 notifyRequester(request);
1863 break;
1864 }
1865 Pair<Integer, List<String>> setFplmnsArgs =
1866 (Pair<Integer, List<String>>) request.argument;
1867 appType = setFplmnsArgs.first;
1868 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001869 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001870 if (uiccApp == null) {
1871 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1872 request.result = -1;
1873 loge("Failed to get UICC App");
1874 notifyRequester(request);
1875 } else {
1876 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1877 ((SIMRecords) uiccApp.getIccRecords())
1878 .setForbiddenPlmns(onCompleted, fplmns);
1879 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001880 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001881 case CMD_ERASE_MODEM_CONFIG:
1882 request = (MainThreadRequest) msg.obj;
1883 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1884 defaultPhone.eraseModemConfig(onCompleted);
1885 break;
1886 case EVENT_ERASE_MODEM_CONFIG_DONE:
1887 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001888 break;
zoey chene02881a2019-12-30 16:11:23 +08001889
Kai Shif70f46f2021-03-03 13:59:46 -08001890 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1891 request = (MainThreadRequest) msg.obj;
1892 request.result = defaultPhone.eraseDataInSharedPreferences();
1893 notifyRequester(request);
1894 break;
1895
zoey chene02881a2019-12-30 16:11:23 +08001896 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1897 request = (MainThreadRequest) msg.obj;
1898 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1899 Pair<String, String> changed = (Pair<String, String>) request.argument;
1900 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1901 changed.first, changed.second, onCompleted);
1902 break;
1903 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1904 ar = (AsyncResult) msg.obj;
1905 request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null) {
1907 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001908 // If the operation is successful, update the PIN storage
1909 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1910 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001911 UiccController.getInstance().getPinStorage()
1912 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001913 } else {
1914 request.result = msg.arg1;
1915 }
1916 notifyRequester(request);
1917 break;
1918
Michele Berionne5e411512020-11-13 02:36:59 +00001919 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1922 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1923 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1924 enabled.first, enabled.second, onCompleted);
1925 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001926 }
zoey chene02881a2019-12-30 16:11:23 +08001927 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1928 ar = (AsyncResult) msg.obj;
1929 request = (MainThreadRequest) ar.userObj;
1930 if (ar.exception == null) {
1931 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001932 // If the operation is successful, update the PIN storage
1933 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1934 int phoneId = getPhoneFromRequest(request).getPhoneId();
1935 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001936 UiccController.getInstance().getPinStorage()
1937 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001938 } else {
1939 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1940 }
zoey chene02881a2019-12-30 16:11:23 +08001941 } else {
1942 request.result = msg.arg1;
1943 }
Michele Berionne5e411512020-11-13 02:36:59 +00001944
1945
zoey chene02881a2019-12-30 16:11:23 +08001946 notifyRequester(request);
1947 break;
1948
Peter Wangdafb9ac2020-01-15 14:13:38 -08001949 case MSG_NOTIFY_USER_ACTIVITY:
1950 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001951 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001952 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1953 getDefaultPhone().getContext().sendBroadcastAsUser(
1954 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1955 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001956
1957 case CMD_SET_DATA_THROTTLING: {
1958 request = (MainThreadRequest) msg.obj;
1959 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1960 DataThrottlingRequest dataThrottlingRequest =
1961 (DataThrottlingRequest) request.argument;
1962 Phone phone = getPhoneFromRequest(request);
1963 if (phone != null) {
1964 phone.setDataThrottling(onCompleted,
1965 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1966 dataThrottlingRequest.getCompletionDurationMillis());
1967 } else {
1968 loge("setDataThrottling: No phone object");
1969 request.result =
1970 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1971 notifyRequester(request);
1972 }
1973
1974 break;
1975 }
1976 case EVENT_SET_DATA_THROTTLING_DONE:
1977 ar = (AsyncResult) msg.obj;
1978 request = (MainThreadRequest) ar.userObj;
1979
1980 if (ar.exception == null) {
1981 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1982 } else if (ar.exception instanceof CommandException) {
1983 loge("setDataThrottling: CommandException: " + ar.exception);
1984 CommandException.Error error =
1985 ((CommandException) (ar.exception)).getCommandError();
1986
1987 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1988 request.result = TelephonyManager
1989 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1990 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1991 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001992 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1993 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001994 } else {
1995 request.result =
1996 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1997 }
1998 } else {
1999 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2000 }
2001 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2002 notifyRequester(request);
2003 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002004
2005 case CMD_SET_SIM_POWER: {
2006 request = (MainThreadRequest) msg.obj;
2007 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2008 request = (MainThreadRequest) msg.obj;
2009 int stateToSet =
2010 ((Pair<Integer, IIntegerConsumer>)
2011 request.argument).first;
2012 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2013 break;
2014 }
2015 case EVENT_SET_SIM_POWER_DONE: {
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 IIntegerConsumer callback =
2019 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2020 if (ar.exception != null) {
2021 loge("setSimPower exception: " + ar.exception);
2022 int errorCode = TelephonyManager.CallForwardingInfoCallback
2023 .RESULT_ERROR_UNKNOWN;
2024 if (ar.exception instanceof CommandException) {
2025 CommandException.Error error =
2026 ((CommandException) (ar.exception)).getCommandError();
2027 if (error == CommandException.Error.SIM_ERR) {
2028 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2029 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2030 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2032 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2033 } else {
2034 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2035 }
2036 }
2037 try {
2038 callback.accept(errorCode);
2039 } catch (RemoteException e) {
2040 // Ignore if the remote process is no longer available to call back.
2041 Log.w(LOG_TAG, "setSimPower: callback not available.");
2042 }
2043 } else {
2044 try {
2045 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2046 } catch (RemoteException e) {
2047 // Ignore if the remote process is no longer available to call back.
2048 Log.w(LOG_TAG, "setSimPower: callback not available.");
2049 }
2050 }
2051 break;
2052 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002053 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2054 request = (MainThreadRequest) msg.obj;
2055
2056 final Phone phone = getPhoneFromRequest(request);
2057 if (phone == null || phone.getServiceStateTracker() == null) {
2058 request.result = new IllegalStateException("Phone or SST is null");
2059 notifyRequester(request);
2060 break;
2061 }
2062
2063 Pair<Integer, SignalStrengthUpdateRequest> pair =
2064 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2065 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2066 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002067 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002068 request.subId, pair.first /*callingUid*/,
2069 pair.second /*request*/, onCompleted);
2070 break;
2071 }
2072 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2073 ar = (AsyncResult) msg.obj;
2074 request = (MainThreadRequest) ar.userObj;
2075 // request.result will be the exception of ar if present, true otherwise.
2076 // Be cautious not to leave result null which will wait() forever
2077 request.result = ar.exception != null ? ar.exception : true;
2078 notifyRequester(request);
2079 break;
2080 }
2081 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2082 request = (MainThreadRequest) msg.obj;
2083
2084 Phone phone = getPhoneFromRequest(request);
2085 if (phone == null || phone.getServiceStateTracker() == null) {
2086 request.result = new IllegalStateException("Phone or SST is null");
2087 notifyRequester(request);
2088 break;
2089 }
2090
2091 Pair<Integer, SignalStrengthUpdateRequest> pair =
2092 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2093 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2094 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002095 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002096 request.subId, pair.first /*callingUid*/,
2097 pair.second /*request*/, onCompleted);
2098 break;
2099 }
2100 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2101 ar = (AsyncResult) msg.obj;
2102 request = (MainThreadRequest) ar.userObj;
2103 request.result = ar.exception != null ? ar.exception : true;
2104 notifyRequester(request);
2105 break;
2106 }
Jordan Liu109698e2020-11-24 14:50:34 -08002107
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002108 case CMD_GET_SLICING_CONFIG: {
2109 request = (MainThreadRequest) msg.obj;
2110 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2111 request.phone.getSlicingConfig(onCompleted);
2112 break;
2113 }
2114 case EVENT_GET_SLICING_CONFIG_DONE: {
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 ResultReceiver result = (ResultReceiver) request.argument;
2118
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002119 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002120 Bundle bundle = new Bundle();
2121 int resultCode = 0;
2122 if (ar.exception != null) {
2123 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2124 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002125 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002126 } else if (ar.result == null) {
2127 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002128 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002129 } else {
2130 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002131 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2132 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 }
2134
2135 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002136 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002137 }
2138 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2139 result.send(resultCode, bundle);
2140 notifyRequester(request);
2141 break;
2142 }
2143
Sarah Chin2ec39f62022-08-31 17:03:26 -07002144 case CMD_PURCHASE_PREMIUM_CAPABILITY:
2145 request = (MainThreadRequest) msg.obj;
2146 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
2147 SliceStore.getInstance(request.phone).purchasePremiumCapability(
2148 ((Pair<Integer, IIntegerConsumer>) request.argument).first,
2149 onCompleted);
2150 break;
2151
2152 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE:
2153 ar = (AsyncResult) msg.obj;
2154 request = (MainThreadRequest) ar.userObj;
2155 Pair<Integer, IIntegerConsumer> pair =
2156 (Pair<Integer, IIntegerConsumer>) request.argument;
2157 try {
2158 int result = (int) ar.result;
2159 pair.second.accept(result);
2160 log("purchasePremiumCapability: capability="
2161 + TelephonyManager.convertPremiumCapabilityToString(pair.first)
2162 + ", result= "
2163 + TelephonyManager.convertPurchaseResultToString(result));
2164 } catch (RemoteException e) {
2165 String logStr = "Purchase premium capability "
2166 + TelephonyManager.convertPremiumCapabilityToString(pair.first)
2167 + " failed: " + e;
2168 if (DBG) log(logStr);
2169 AnomalyReporter.reportAnomaly(
2170 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2171 }
2172 break;
2173
Michele Berionne5e411512020-11-13 02:36:59 +00002174 case CMD_PREPARE_UNATTENDED_REBOOT:
2175 request = (MainThreadRequest) msg.obj;
2176 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002177 UiccController.getInstance().getPinStorage()
2178 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002179 notifyRequester(request);
2180 break;
2181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 default:
2183 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2184 break;
2185 }
2186 }
Jake Hambye994d462014-02-03 13:10:13 -08002187
Pengquan Menga1bb6272018-09-06 09:59:22 -07002188 private void notifyRequester(MainThreadRequest request) {
2189 synchronized (request) {
2190 request.notifyAll();
2191 }
2192 }
2193
Jake Hambye994d462014-02-03 13:10:13 -08002194 private void handleNullReturnEvent(Message msg, String command) {
2195 AsyncResult ar = (AsyncResult) msg.obj;
2196 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2197 if (ar.exception == null) {
2198 request.result = true;
2199 } else {
2200 request.result = false;
2201 if (ar.exception instanceof CommandException) {
2202 loge(command + ": CommandException: " + ar.exception);
2203 } else {
2204 loge(command + ": Unknown exception");
2205 }
2206 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002207 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 }
2210
2211 /**
2212 * Posts the specified command to be executed on the main thread,
2213 * waits for the request to complete, and returns the result.
2214 * @see #sendRequestAsync
2215 */
2216 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002217 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2218 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002219 }
2220
2221 /**
2222 * Posts the specified command to be executed on the main thread,
2223 * waits for the request to complete, and returns the result.
2224 * @see #sendRequestAsync
2225 */
2226 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2227 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002228 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002229 }
2230
2231 /**
2232 * Posts the specified command to be executed on the main thread,
2233 * waits for the request to complete, and returns the result.
2234 * @see #sendRequestAsync
2235 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002236 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002237 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2238 }
2239
2240 /**
2241 * Posts the specified command to be executed on the main thread,
2242 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2243 * if not timeout or null otherwise.
2244 * @see #sendRequestAsync
2245 */
2246 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2247 long timeoutInMs) {
2248 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002249 }
2250
2251 /**
2252 * Posts the specified command to be executed on the main thread,
2253 * waits for the request to complete, and returns the result.
2254 * @see #sendRequestAsync
2255 */
Nathan Harold92bed182018-10-12 18:16:49 -07002256 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002257 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002258 }
2259
2260 /**
2261 * Posts the specified command to be executed on the main thread,
2262 * waits for the request to complete, and returns the result.
2263 * @see #sendRequestAsync
2264 */
2265 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002266 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2267 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002268 }
2269
2270 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002271 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2272 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2273 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002274 * @see #sendRequestAsync
2275 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002276 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2277 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2279 throw new RuntimeException("This method will deadlock if called from the main thread.");
2280 }
2281
Nathan Harold92bed182018-10-12 18:16:49 -07002282 MainThreadRequest request = null;
2283 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2284 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2285 } else if (phone != null) {
2286 request = new MainThreadRequest(argument, phone, workSource);
2287 } else {
2288 request = new MainThreadRequest(argument, subId, workSource);
2289 }
2290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 Message msg = mMainThreadHandler.obtainMessage(command, request);
2292 msg.sendToTarget();
2293
Rambo Wang0f050d82021-02-12 11:43:36 -08002294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002296 if (timeoutInMs >= 0) {
2297 // Wait for at least timeoutInMs before returning null request result
2298 long now = SystemClock.elapsedRealtime();
2299 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002300 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002301 try {
2302 request.wait(deadline - now);
2303 } catch (InterruptedException e) {
2304 // Do nothing, go back and check if request is completed or timeout
2305 } finally {
2306 now = SystemClock.elapsedRealtime();
2307 }
2308 }
2309 } else {
2310 // Wait for the request to complete
2311 while (request.result == null) {
2312 try {
2313 request.wait();
2314 } catch (InterruptedException e) {
2315 // Do nothing, go back and wait until the request is complete
2316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 }
2318 }
2319 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002320 if (request.result == null) {
2321 Log.wtf(LOG_TAG,
2322 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002324 return request.result;
2325 }
2326
2327 /**
2328 * Asynchronous ("fire and forget") version of sendRequest():
2329 * Posts the specified command to be executed on the main thread, and
2330 * returns immediately.
2331 * @see #sendRequest
2332 */
2333 private void sendRequestAsync(int command) {
2334 mMainThreadHandler.sendEmptyMessage(command);
2335 }
2336
2337 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002338 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002339 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002340 */
2341 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002342 sendRequestAsync(command, argument, null, null);
2343 }
2344
2345 /**
2346 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2347 * @see {@link #sendRequest(int,Object)}
2348 */
2349 private void sendRequestAsync(
2350 int command, Object argument, Phone phone, WorkSource workSource) {
2351 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002352 Message msg = mMainThreadHandler.obtainMessage(command, request);
2353 msg.sendToTarget();
2354 }
2355
2356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 * Initialize the singleton PhoneInterfaceManager instance.
2358 * This is only done once, at startup, from PhoneApp.onCreate().
2359 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002360 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 synchronized (PhoneInterfaceManager.class) {
2362 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002363 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 } else {
2365 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2366 }
2367 return sInstance;
2368 }
2369 }
2370
2371 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002372 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002375 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002376 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002378 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002380 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002381 mTelephonySharedPreferences =
2382 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002383 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002384 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002385 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002386 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002387 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 publish();
2389 }
2390
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002391 private Phone getDefaultPhone() {
2392 Phone thePhone = getPhone(getDefaultSubscription());
2393 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 private void publish() {
2397 if (DBG) log("publish: " + this);
2398
Peter Wangc035ce42020-01-08 21:00:22 -08002399 TelephonyFrameworkInitializer
2400 .getTelephonyServiceManager()
2401 .getTelephonyServiceRegisterer()
2402 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Stuart Scott584921c2015-01-15 17:10:34 -08002405 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002406 if (request.phone != null) {
2407 return request.phone;
2408 } else {
2409 return getPhoneFromSubId(request.subId);
2410 }
2411 }
2412
2413 private Phone getPhoneFromSubId(int subId) {
2414 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2415 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002416 }
2417
Rambo Wange53e07d2022-05-10 13:01:13 -07002418 @Nullable
2419 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002420 Phone phone = getPhoneFromRequest(request);
2421 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002422 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002423 }
2424
Wink Saville36469e72014-06-11 15:17:00 -07002425 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002426 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002427 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429
Kai Shif70f46f2021-03-03 13:59:46 -08002430 private void sendEraseModemConfig(@NonNull Phone phone) {
2431 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2432 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2433 }
2434
2435 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2436 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2437 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002438 }
2439
Peter Wang44b186e2020-01-13 23:33:09 -08002440 private boolean isImsAvailableOnDevice() {
2441 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2442 if (pm == null) {
2443 // For some reason package manger is not available.. This will fail internally anyway,
2444 // so do not throw error and allow.
2445 return true;
2446 }
2447 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2448 }
2449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002451 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002452 }
2453
Wink Savilleb564aae2014-10-23 10:18:09 -07002454 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 if (DBG) log("dial: " + number);
2456 // No permission check needed here: This is just a wrapper around the
2457 // ACTION_DIAL intent, which is available to any app since it puts up
2458 // the UI before it does anything.
2459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 String url = createTelUrl(number);
2463 if (url == null) {
2464 return;
2465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002467 // PENDING: should we just silently fail if phone is offhook or ringing?
2468 PhoneConstants.State state = mCM.getState(subId);
2469 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2470 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2471 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2472 mApp.startActivity(intent);
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 }
2477 }
2478
2479 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002480 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002481 }
2482
Wink Savilleb564aae2014-10-23 10:18:09 -07002483 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 if (DBG) log("call: " + number);
2485
2486 // This is just a wrapper around the ACTION_CALL intent, but we still
2487 // need to do a permission check since we're calling startActivity()
2488 // from the context of the phone app.
2489 enforceCallPermission();
2490
Jordan Liu1617b712019-07-10 15:06:26 -07002491 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 != AppOpsManager.MODE_ALLOWED) {
2493 return;
2494 }
2495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 final long identity = Binder.clearCallingIdentity();
2497 try {
2498 String url = createTelUrl(number);
2499 if (url == null) {
2500 return;
2501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 boolean isValid = false;
2504 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2505 if (slist != null) {
2506 for (SubscriptionInfo subInfoRecord : slist) {
2507 if (subInfoRecord.getSubscriptionId() == subId) {
2508 isValid = true;
2509 break;
2510 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002511 }
Wink Saville08874612014-08-31 19:19:58 -07002512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 if (!isValid) {
2514 return;
2515 }
Wink Saville08874612014-08-31 19:19:58 -07002516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002517 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2518 intent.putExtra(SUBSCRIPTION_KEY, subId);
2519 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2520 mApp.startActivity(intent);
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
2523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
2525
Wink Savilleb564aae2014-10-23 10:18:09 -07002526 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002527 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002528 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2529 }
2530
Wink Savilleb564aae2014-10-23 10:18:09 -07002531 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002532 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002533 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2534 }
2535
Wink Savilleb564aae2014-10-23 10:18:09 -07002536 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002541 Phone phone = getPhone(subId);
2542 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543 checkSimPin.start();
2544 return checkSimPin.unlockSim(null, pin);
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
Wink Savilleb564aae2014-10-23 10:18:09 -07002550 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002555 Phone phone = getPhone(subId);
2556 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 checkSimPuk.start();
2558 return checkSimPuk.unlockSim(puk, pin);
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 }
2563
2564 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002565 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 * a synchronous one.
2567 */
2568 private static class UnlockSim extends Thread {
2569
2570 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002571 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572
2573 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002574 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2575 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576
2577 // For replies from SimCard interface
2578 private Handler mHandler;
2579
2580 // For async handler to identify request type
2581 private static final int SUPPLY_PIN_COMPLETE = 100;
2582
Michele Berionne5e411512020-11-13 02:36:59 +00002583 UnlockSim(int phoneId, IccCard simCard) {
2584 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 mSimCard = simCard;
2586 }
2587
2588 @Override
2589 public void run() {
2590 Looper.prepare();
2591 synchronized (UnlockSim.this) {
2592 mHandler = new Handler() {
2593 @Override
2594 public void handleMessage(Message msg) {
2595 AsyncResult ar = (AsyncResult) msg.obj;
2596 switch (msg.what) {
2597 case SUPPLY_PIN_COMPLETE:
2598 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2599 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002600 mRetryCount = msg.arg1;
2601 if (ar.exception != null) {
2602 if (ar.exception instanceof CommandException &&
2603 ((CommandException)(ar.exception)).getCommandError()
2604 == CommandException.Error.PASSWORD_INCORRECT) {
2605 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002606 } //When UiccCardApp dispose,handle message and return exception
2607 else if (ar.exception instanceof CommandException &&
2608 ((CommandException) (ar.exception)).getCommandError()
2609 == CommandException.Error.ABORTED) {
2610 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002611 } else {
2612 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2613 }
2614 } else {
2615 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 mDone = true;
2618 UnlockSim.this.notifyAll();
2619 }
2620 break;
2621 }
2622 }
2623 };
2624 UnlockSim.this.notifyAll();
2625 }
2626 Looper.loop();
2627 }
2628
2629 /*
2630 * Use PIN or PUK to unlock SIM card
2631 *
2632 * If PUK is null, unlock SIM card with PIN
2633 *
2634 * If PUK is not null, unlock SIM card with PUK and set PIN code
2635 */
Wink Saville9de0f752013-10-22 19:04:03 -07002636 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637
2638 while (mHandler == null) {
2639 try {
2640 wait();
2641 } catch (InterruptedException e) {
2642 Thread.currentThread().interrupt();
2643 }
2644 }
2645 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2646
2647 if (puk == null) {
2648 mSimCard.supplyPin(pin, callback);
2649 } else {
2650 mSimCard.supplyPuk(puk, pin, callback);
2651 }
2652
2653 while (!mDone) {
2654 try {
2655 Log.d(LOG_TAG, "wait for done");
2656 wait();
2657 } catch (InterruptedException e) {
2658 // Restore the interrupted status
2659 Thread.currentThread().interrupt();
2660 }
2661 }
2662 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002663 int[] resultArray = new int[2];
2664 resultArray[0] = mResult;
2665 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002666
2667 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002668 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002669 }
2670
Wink Saville9de0f752013-10-22 19:04:03 -07002671 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673 }
2674
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002675 /**
2676 * This method has been removed due to privacy and stability concerns.
2677 */
2678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002680 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2681 return;
Wink Saville36469e72014-06-11 15:17:00 -07002682 }
2683
Nathan Harold1f889d82020-06-04 17:05:26 -07002684 @Override
2685 public void updateServiceLocationWithPackageName(String callingPackage) {
2686 mApp.getSystemService(AppOpsManager.class)
2687 .checkPackage(Binder.getCallingUid(), callingPackage);
2688
Nathan Haroldf096d982020-11-18 17:18:06 -08002689 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002690 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2691 // Callers targeting S have no business invoking this method.
2692 return;
2693 }
2694
2695 LocationAccessPolicy.LocationPermissionResult locationResult =
2696 LocationAccessPolicy.checkLocationPermission(mApp,
2697 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2698 .setCallingPackage(callingPackage)
2699 .setCallingFeatureId(null)
2700 .setCallingPid(Binder.getCallingPid())
2701 .setCallingUid(Binder.getCallingUid())
2702 .setMethod("updateServiceLocation")
2703 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2704 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2705 .build());
2706 // Apps that lack location permission have no business calling this method;
2707 // however, because no permission was declared in the public API, denials must
2708 // all be "soft".
2709 switch (locationResult) {
2710 case DENIED_HARD: /* fall through */
2711 case DENIED_SOFT:
2712 return;
2713 }
2714
2715 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002718 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002720 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 }
2726
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002727 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002728 @Override
2729 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002730 return isRadioOnWithFeature(callingPackage, null);
2731 }
2732
2733
2734 @Override
2735 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2736 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2737 callingFeatureId);
2738 }
2739
2740 @Deprecated
2741 @Override
2742 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2743 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002744 }
2745
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002746 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002747 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2748 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002750 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002751 return false;
2752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 return isRadioOnForSubscriber(subId);
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002760 }
2761
2762 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 final Phone phone = getPhone(subId);
2766 if (phone != null) {
2767 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2768 } else {
2769 return false;
2770 }
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
2776 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002777 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
Wink Saville36469e72014-06-11 15:17:00 -07002779
Wink Savilleb564aae2014-10-23 10:18:09 -07002780 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782
2783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2788 }
2789 } finally {
2790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002791 }
Wink Saville36469e72014-06-11 15:17:00 -07002792 }
2793
2794 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002795 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002796 }
2797
Wink Savilleb564aae2014-10-23 10:18:09 -07002798 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 final Phone phone = getPhone(subId);
2804 if (phone == null) {
2805 return false;
2806 }
2807 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2808 toggleRadioOnOffForSubscriber(subId);
2809 }
2810 return true;
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
Wink Saville36469e72014-06-11 15:17:00 -07002815
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002816 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002817 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002818 /*
2819 * If any of the Radios are available, it will need to be
2820 * shutdown. So return true if any Radio is available.
2821 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2825 Phone phone = PhoneFactory.getPhone(i);
2826 if (phone != null && phone.isRadioAvailable()) return true;
2827 }
2828 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2829 return false;
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002833 }
2834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002836 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 enforceModifyPermission();
2838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2842 logv("Shutting down Phone " + i);
2843 shutdownRadioUsingPhoneId(i);
2844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002847 }
2848 }
2849
2850 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002851 Phone phone = PhoneFactory.getPhone(phoneId);
2852 if (phone != null && phone.isRadioAvailable()) {
2853 phone.shutdownRadio();
2854 }
2855 }
2856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002858 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002859
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
2862 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2863 if (defaultPhone != null) {
2864 defaultPhone.setRadioPower(turnOn);
2865 return true;
2866 } else {
2867 loge("There's no default phone.");
2868 return false;
2869 }
2870 } finally {
2871 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002872 }
Wink Saville36469e72014-06-11 15:17:00 -07002873 }
2874
Wink Savilleb564aae2014-10-23 10:18:09 -07002875 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877
2878 final long identity = Binder.clearCallingIdentity();
2879 try {
2880 final Phone phone = getPhone(subId);
2881 if (phone != null) {
2882 phone.setRadioPower(turnOn);
2883 return true;
2884 } else {
2885 return false;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002892 /**
2893 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2894 * no reason to power it off. When any of the voters want to power it off, it will be turned
2895 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2896 * powering it off, and these radio off votes will be cleared.
2897 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2898 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2899 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2900 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2901 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2902 * check its vote.
2903 *
2904 * @param subId The subscription ID.
2905 * @param reason The reason for powering off radio.
2906 * @return true on success and false on failure.
2907 */
2908 public boolean requestRadioPowerOffForReason(int subId,
2909 @TelephonyManager.RadioPowerReason int reason) {
2910 enforceModifyPermission();
2911
2912 final long identity = Binder.clearCallingIdentity();
2913 try {
2914 final Phone phone = getPhone(subId);
2915 if (phone != null) {
2916 phone.setRadioPowerForReason(false, reason);
2917 return true;
2918 } else {
2919 return false;
2920 }
2921 } finally {
2922 Binder.restoreCallingIdentity(identity);
2923 }
2924 }
2925
2926 /**
2927 * Remove the vote on powering off the radio for a reason, as requested by
2928 * {@link requestRadioPowerOffForReason}.
2929 *
2930 * @param subId The subscription ID.
2931 * @param reason The reason for powering off radio.
2932 * @return true on success and false on failure.
2933 */
2934 public boolean clearRadioPowerOffForReason(int subId,
2935 @TelephonyManager.RadioPowerReason int reason) {
2936 enforceModifyPermission();
2937
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 final Phone phone = getPhone(subId);
2941 if (phone != null) {
2942 phone.setRadioPowerForReason(true, reason);
2943 return true;
2944 } else {
2945 return false;
2946 }
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
2950 }
2951
2952 /**
2953 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2954 *
2955 * @param subId The subscription ID.
2956 * @param callingPackage The package making the call.
2957 * @param callingFeatureId The feature in the package.
2958 * @return List of reasons for powering off radio.
2959 */
2960 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2961 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2962
2963 final long identity = Binder.clearCallingIdentity();
2964 List result = new ArrayList();
2965 try {
2966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2967 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2968 return result;
2969 }
2970
2971 final Phone phone = getPhone(subId);
2972 if (phone != null) {
2973 result.addAll(phone.getRadioPowerOffReasons());
2974 }
2975 } finally {
2976 Binder.restoreCallingIdentity(identity);
2977 }
2978 return result;
2979 }
2980
Wink Saville36469e72014-06-11 15:17:00 -07002981 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002983 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 int subId = mSubscriptionController.getDefaultDataSubId();
2989 final Phone phone = getPhone(subId);
2990 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00002991 if (phone.isUsingNewDataStack()) {
2992 phone.getDataSettingsManager().setDataEnabled(
2993 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
2994 } else {
2995 phone.getDataEnabledSettings().setDataEnabled(
2996 TelephonyManager.DATA_ENABLED_REASON_USER, true);
2997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998 return true;
2999 } else {
3000 return false;
3001 }
3002 } finally {
3003 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
Wink Saville36469e72014-06-11 15:17:00 -07003007 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003009 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003010 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003011
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 int subId = mSubscriptionController.getDefaultDataSubId();
3015 final Phone phone = getPhone(subId);
3016 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00003017 if (phone.isUsingNewDataStack()) {
3018 phone.getDataSettingsManager().setDataEnabled(
3019 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
3020 } else {
3021 phone.getDataEnabledSettings().setDataEnabled(
3022 TelephonyManager.DATA_ENABLED_REASON_USER, false);
3023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 return true;
3025 } else {
3026 return false;
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
Sanket Padawe356d7632015-06-22 14:03:32 -07003033 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003034 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 final Phone phone = getPhone(subId);
3038 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003039 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 } else {
3041 return false;
3042 }
3043 } finally {
3044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003046 }
3047
3048 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003049 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003050 }
3051
pkanwarae03a6b2016-11-06 20:37:09 -08003052 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 enforceCallPermission();
3054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3058 return;
3059 }
3060 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3061 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
pkanwar32d516d2016-10-14 19:37:38 -07003065 };
3066
Wink Savilleb564aae2014-10-23 10:18:09 -07003067 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3073 return false;
3074 }
3075 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003079 }
3080
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003081 /**
3082 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3083 * tag on getCallState Binder call.
3084 */
3085 @Deprecated
3086 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003088 if (CompatChanges.isChangeEnabled(
3089 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3090 Binder.getCallingUid())) {
3091 // Do not allow this API to be called on API version 31+, it should only be
3092 // called on old apps using this Binder call directly.
3093 throw new SecurityException("This method can only be used for applications "
3094 + "targeting API version 30 or less.");
3095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 final long identity = Binder.clearCallingIdentity();
3097 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003098 Phone phone = getPhone(getDefaultSubscription());
3099 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3100 PhoneConstantConversions.convertCallState(phone.getState());
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3108 if (CompatChanges.isChangeEnabled(
3109 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3110 Binder.getCallingUid())) {
3111 // Check READ_PHONE_STATE for API version 31+
3112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3113 featureId, "getCallStateForSubscription")) {
3114 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3115 + "targeting API level 31+.");
3116 }
3117 }
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003121 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3122 PhoneConstantConversions.convertCallState(phone.getState());
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003126 }
3127
Sanket Padawe356d7632015-06-22 14:03:32 -07003128 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003129 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003130 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3131 }
3132
3133 @Override
3134 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003135 final long identity = Binder.clearCallingIdentity();
3136 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003137 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138 if (phone != null) {
Jack Yuf745f972022-08-15 19:53:50 +00003139 if (phone.isUsingNewDataStack()) {
3140 return phone.getDataNetworkController().getInternetDataNetworkState();
3141 }
3142 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003143 } else {
3144 return PhoneConstantConversions.convertDataState(
3145 PhoneConstants.DataState.DISCONNECTED);
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003149 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003150 }
3151
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003153 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003154 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3155 }
3156
3157 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003158 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003161 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003163 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 } else {
3165 return TelephonyManager.DATA_ACTIVITY_NONE;
3166 }
3167 } finally {
3168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 }
3171
3172 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003173 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003175 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003176
3177 LocationAccessPolicy.LocationPermissionResult locationResult =
3178 LocationAccessPolicy.checkLocationPermission(mApp,
3179 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3180 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003181 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003182 .setCallingPid(Binder.getCallingPid())
3183 .setCallingUid(Binder.getCallingUid())
3184 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003185 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003186 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3187 .build());
3188 switch (locationResult) {
3189 case DENIED_HARD:
3190 throw new SecurityException("Not allowed to access cell location");
3191 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003192 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3193 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 }
3195
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003196 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003200 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003201 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
Svetoslav64fad262015-04-14 14:35:21 -07003205 }
3206
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003208 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003209 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3210 // registered cell info, so return a NULL country instead.
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003213 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3214 // Get default phone in this case.
3215 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3216 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003217 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003219 if (phone == null) return "";
3220 ServiceStateTracker sst = phone.getServiceStateTracker();
3221 if (sst == null) return "";
3222 LocaleTracker lt = sst.getLocaleTracker();
3223 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003224 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003225 } finally {
3226 Binder.restoreCallingIdentity(identity);
3227 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003228 }
3229
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003230 /**
3231 * This method was removed due to potential issues caused by performing partial
3232 * updates of service state, and lack of a credible use case.
3233 *
3234 * This has the ability to break the telephony implementation by disabling notification of
3235 * changes in device connectivity. DO NOT USE THIS!
3236 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003237 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 public void enableLocationUpdates() {
3239 mApp.enforceCallingOrSelfPermission(
3240 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 }
3242
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003243 /**
3244 * This method was removed due to potential issues caused by performing partial
3245 * updates of service state, and lack of a credible use case.
3246 *
3247 * This has the ability to break the telephony implementation by disabling notification of
3248 * changes in device connectivity. DO NOT USE THIS!
3249 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 @Override
3251 public void disableLocationUpdates() {
3252 mApp.enforceCallingOrSelfPermission(
3253 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 @Override
3257 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003258 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3259 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003260 try {
3261 mApp.getSystemService(AppOpsManager.class)
3262 .checkPackage(Binder.getCallingUid(), callingPackage);
3263 } catch (SecurityException e) {
3264 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3265 throw e;
3266 }
3267
Nathan Haroldf096d982020-11-18 17:18:06 -08003268 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003269 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3270 throw new SecurityException(
3271 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3272 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003273
Jordan Liu1617b712019-07-10 15:06:26 -07003274 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3276 return null;
3277 }
Svetoslav64fad262015-04-14 14:35:21 -07003278
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003279 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003281 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003282 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283
Nathan Haroldf180aac2018-06-01 18:43:55 -07003284 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3285 for (CellInfo ci : info) {
3286 if (ci instanceof CellInfoGsm) {
3287 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3288 } else if (ci instanceof CellInfoWcdma) {
3289 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003292 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
3294
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003295 private List<CellInfo> getCachedCellInfo() {
3296 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3297 for (Phone phone : PhoneFactory.getPhones()) {
3298 List<CellInfo> info = phone.getAllCellInfo();
3299 if (info != null) cellInfos.addAll(info);
3300 }
3301 return cellInfos;
3302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003303
3304 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003305 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003306 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003307 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003308
3309 LocationAccessPolicy.LocationPermissionResult locationResult =
3310 LocationAccessPolicy.checkLocationPermission(mApp,
3311 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3312 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003313 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003314 .setCallingPid(Binder.getCallingPid())
3315 .setCallingUid(Binder.getCallingUid())
3316 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003317 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003318 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3319 .build());
3320 switch (locationResult) {
3321 case DENIED_HARD:
3322 throw new SecurityException("Not allowed to access cell info");
3323 case DENIED_SOFT:
3324 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003325 }
3326
Nathan Haroldf096d982020-11-18 17:18:06 -08003327 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003328 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3329 return getCachedCellInfo();
3330 }
3331
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003332 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3337 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003338 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003339 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 if (info != null) cellInfos.addAll(info);
3341 }
3342 return cellInfos;
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 }
3346 }
3347
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003348 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003349 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3350 String callingFeatureId) {
3351 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3352 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003353 }
3354
3355 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003356 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3357 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003358 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003359 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 }
3361
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003362 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3363 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003365 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003366
3367 LocationAccessPolicy.LocationPermissionResult locationResult =
3368 LocationAccessPolicy.checkLocationPermission(mApp,
3369 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3370 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003371 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003372 .setCallingPid(Binder.getCallingPid())
3373 .setCallingUid(Binder.getCallingUid())
3374 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003375 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3376 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003377 .build());
3378 switch (locationResult) {
3379 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003380 if (TelephonyPermissions
3381 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003382 // Safetynet logging for b/154934934
3383 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3384 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003385 throw new SecurityException("Not allowed to access cell info");
3386 case DENIED_SOFT:
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 }
Nathan Harold5320c422019-05-09 10:26:08 -07003392 try {
3393 cb.onCellInfo(new ArrayList<CellInfo>());
3394 } catch (RemoteException re) {
3395 // Drop without consequences
3396 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003397 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003398 }
3399
Nathan Harolda939a962019-05-09 10:13:47 -07003400
3401 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003402 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3403
3404 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3405 }
3406
3407 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003408 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003409 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003414 Phone phone = getPhone(subId);
3415 if (phone == null) {
3416 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3417 } else {
3418 phone.setCellInfoListRate(rateInMillis, workSource);
3419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420 } finally {
3421 Binder.restoreCallingIdentity(identity);
3422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 }
3424
Shishir Agrawala9f32182016-04-12 12:00:16 -07003425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003426 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003427 Phone phone = PhoneFactory.getPhone(slotIndex);
3428 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003429 return null;
3430 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003431 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003432 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003433 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003434 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003435 return null;
3436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 return phone.getImei();
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
3443 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003444 }
3445
3446 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003447 public String getTypeAllocationCodeForSlot(int slotIndex) {
3448 Phone phone = PhoneFactory.getPhone(slotIndex);
3449 String tac = null;
3450 if (phone != null) {
3451 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003452 try {
3453 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3454 } catch (IndexOutOfBoundsException e) {
3455 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3456 return null;
3457 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003458 }
3459 return tac;
3460 }
3461
3462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003463 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003464 try {
3465 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3466 } catch (SecurityException se) {
3467 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3468 throw new SecurityException("Package " + callingPackage + " does not belong to "
3469 + Binder.getCallingUid());
3470 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003471 Phone phone = PhoneFactory.getPhone(slotIndex);
3472 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003473 return null;
3474 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003475
Jeff Davidson913390f2018-02-23 17:11:49 -08003476 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003477 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 return null;
3480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481
3482 final long identity = Binder.clearCallingIdentity();
3483 try {
3484 return phone.getMeid();
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
Jack Yu2af8d712017-03-15 17:14:14 -07003488 }
3489
3490 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003491 public String getManufacturerCodeForSlot(int slotIndex) {
3492 Phone phone = PhoneFactory.getPhone(slotIndex);
3493 String manufacturerCode = null;
3494 if (phone != null) {
3495 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003496 try {
3497 manufacturerCode =
3498 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3499 } catch (IndexOutOfBoundsException e) {
3500 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3501 return null;
3502 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003503 }
3504 return manufacturerCode;
3505 }
3506
3507 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003508 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3509 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003510 Phone phone = PhoneFactory.getPhone(slotIndex);
3511 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 return null;
3513 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003514 int subId = phone.getSubId();
3515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 mApp, subId, callingPackage, callingFeatureId,
3517 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003518 return null;
3519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 return phone.getDeviceSvn();
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003527 }
3528
fionaxu43304da2017-11-27 22:51:16 -08003529 @Override
3530 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = getPhone(subId);
3534 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
fionaxu43304da2017-11-27 22:51:16 -08003538 }
3539
3540 @Override
3541 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 final Phone phone = getPhone(subId);
3545 return phone == null ? null : phone.getCarrierName();
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
3548 }
fionaxu43304da2017-11-27 22:51:16 -08003549 }
3550
calvinpanffe225e2018-11-01 19:43:06 +08003551 @Override
chen xu0026ca62019-03-06 15:28:50 -08003552 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 final Phone phone = getPhone(subId);
3556 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003557 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
3563 @Override
chen xu0026ca62019-03-06 15:28:50 -08003564 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003568 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
3572 }
3573
chen xu651eec72018-11-11 19:03:44 -08003574 @Override
chen xu864e11c2018-12-06 22:10:03 -08003575 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3576 if (!isSubscriptionMccMnc) {
3577 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3578 }
chen xu651eec72018-11-11 19:03:44 -08003579 final Phone phone = PhoneFactory.getPhone(slotIndex);
3580 if (phone == null) {
3581 return TelephonyManager.UNKNOWN_CARRIER_ID;
3582 }
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003591 //
3592 // Internal helper methods.
3593 //
3594
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003595 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003596 * Make sure the caller is the calling package itself
3597 *
3598 * @throws SecurityException if the caller is not the calling package
3599 */
3600 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3601 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003602 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3603 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003604 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003605 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003606 } catch (PackageManager.NameNotFoundException e) {
3607 // packageUid is -1
3608 }
3609 if (packageUid != callingUid) {
3610 throw new SecurityException(message + ": Package " + callingPackage
3611 + " does not belong to " + callingUid);
3612 }
3613 }
3614
3615 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003616 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3617 *
3618 * @throws SecurityException if the caller does not have the required permission
3619 */
3620 private void enforceModifyPermission() {
3621 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3622 }
3623
Shuo Qian3b6ee772019-11-13 17:43:31 -08003624 private void enforceActiveEmergencySessionPermission() {
3625 mApp.enforceCallingOrSelfPermission(
3626 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3627 }
3628
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003629 /**
3630 * Make sure the caller has the CALL_PHONE permission.
3631 *
3632 * @throws SecurityException if the caller does not have the required permission
3633 */
3634 private void enforceCallPermission() {
3635 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3636 }
3637
paulhu5a773602019-08-23 19:17:33 +08003638 private void enforceSettingsPermission() {
3639 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003640 }
3641
Michele Berionne5e411512020-11-13 02:36:59 +00003642 private void enforceRebootPermission() {
3643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3644 }
3645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 private String createTelUrl(String number) {
3647 if (TextUtils.isEmpty(number)) {
3648 return null;
3649 }
3650
Jake Hambye994d462014-02-03 13:10:13 -08003651 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003652 }
3653
Ihab Awadf9e92732013-12-05 18:02:52 -08003654 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3656 }
3657
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003658 private static void logv(String msg) {
3659 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3660 }
3661
Ihab Awadf9e92732013-12-05 18:02:52 -08003662 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003663 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3664 }
3665
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003666 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003667 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003668 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003669 }
3670
Sanket Padawe356d7632015-06-22 14:03:32 -07003671 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003672 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 final Phone phone = PhoneFactory.getPhone(slotIndex);
3676 if (phone == null) {
3677 return PhoneConstants.PHONE_TYPE_NONE;
3678 } else {
3679 return phone.getPhoneType();
3680 }
3681 } finally {
3682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003684 }
3685
3686 /**
3687 * Returns the CDMA ERI icon index to display
3688 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003690 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3691 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3692 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003693 }
3694
Sanket Padawe356d7632015-06-22 14:03:32 -07003695 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003696 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3697 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 mApp, subId, callingPackage, callingFeatureId,
3700 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003701 return -1;
3702 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 final Phone phone = getPhone(subId);
3707 if (phone != null) {
3708 return phone.getCdmaEriIconIndex();
3709 } else {
3710 return -1;
3711 }
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
3716
3717 /**
3718 * Returns the CDMA ERI icon mode,
3719 * 0 - ON
3720 * 1 - FLASHING
3721 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003723 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3724 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3725 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003726 }
3727
Sanket Padawe356d7632015-06-22 14:03:32 -07003728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003729 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3730 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003732 mApp, subId, callingPackage, callingFeatureId,
3733 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003734 return -1;
3735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 final Phone phone = getPhone(subId);
3740 if (phone != null) {
3741 return phone.getCdmaEriIconMode();
3742 } else {
3743 return -1;
3744 }
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003748 }
3749
3750 /**
3751 * Returns the CDMA ERI text,
3752 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003754 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3755 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3756 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003757 }
3758
Sanket Padawe356d7632015-06-22 14:03:32 -07003759 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003760 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 mApp, subId, callingPackage, callingFeatureId,
3764 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003765 return null;
3766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 final Phone phone = getPhone(subId);
3771 if (phone != null) {
3772 return phone.getCdmaEriText();
3773 } else {
3774 return null;
3775 }
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003779 }
3780
3781 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003782 * Returns the CDMA MDN.
3783 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003784 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003785 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3787 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788
3789 final long identity = Binder.clearCallingIdentity();
3790 try {
3791 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003792 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793 return phone.getLine1Number();
3794 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 return null;
3797 }
3798 } finally {
3799 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003800 }
3801 }
3802
3803 /**
3804 * Returns the CDMA MIN.
3805 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003806 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003807 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3809 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810
3811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 final Phone phone = getPhone(subId);
3814 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3815 return phone.getCdmaMin();
3816 } else {
3817 return null;
3818 }
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003821 }
3822 }
3823
Hall Liud892bec2018-11-30 14:51:45 -08003824 @Override
3825 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3826 INumberVerificationCallback callback, String callingPackage) {
3827 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3828 != PERMISSION_GRANTED) {
3829 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3830 }
3831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3832
3833 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3834 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003835 throw new SecurityException("Calling package must be configured in the device config: "
3836 + "calling package: " + callingPackage
3837 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003838 }
3839
3840 if (range == null) {
3841 throw new NullPointerException("Range must be non-null");
3842 }
3843
3844 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003845 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003846
3847 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3848 }
3849
Junda Liuca05d5d2014-08-14 22:36:34 -07003850 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003851 * Returns true if CDMA provisioning needs to run.
3852 */
3853 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003856 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003860 }
3861
3862 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003863 * Sets the voice mail number of a given subId.
3864 */
3865 @Override
3866 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3868 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869
3870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3873 new Pair<String, String>(alphaTag, number), new Integer(subId));
3874 return success;
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003878 }
3879
Ta-wei Yen87c49842016-05-13 21:19:52 -07003880 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003881 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3882 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003883 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3884 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003885 if (!TextUtils.equals(callingPackage, systemDialer)) {
3886 throw new SecurityException("caller must be system dialer");
3887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3892 if (phoneAccountHandle == null) {
3893 return null;
3894 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003895 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003896 } finally {
3897 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003898 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003899 }
3900
3901 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003902 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3903 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003904 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003905 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003906 mApp, subId, callingPackage, callingFeatureId,
3907 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003908 return null;
3909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003911 final long identity = Binder.clearCallingIdentity();
3912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003914 } finally {
3915 Binder.restoreCallingIdentity(identity);
3916 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003917 }
3918
3919 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003920 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3921 VisualVoicemailSmsFilterSettings settings) {
3922 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923
3924 final long identity = Binder.clearCallingIdentity();
3925 try {
3926 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003927 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003928 } finally {
3929 Binder.restoreCallingIdentity(identity);
3930 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003931 }
3932
3933 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003934 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3935 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003936
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003940 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003944 }
3945
3946 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003947 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3948 String callingPackage, int subId) {
3949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950
3951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003958 }
3959
3960 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003961 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963
3964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003967 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 } finally {
3969 Binder.restoreCallingIdentity(identity);
3970 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003971 }
3972
3973 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003974 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3975 String callingAttributionTag, int subId, String number, int port, String text,
3976 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003978 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003979 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003980 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003981 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3982 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003983 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003984
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003985 /**
fionaxu0152e512016-11-14 13:36:14 -08003986 * Sets the voice activation state of a given subId.
3987 */
3988 @Override
3989 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3991 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992
3993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 final Phone phone = getPhone(subId);
3996 if (phone != null) {
3997 phone.setVoiceActivationState(activationState);
3998 } else {
3999 loge("setVoiceActivationState fails with invalid subId: " + subId);
4000 }
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004003 }
4004 }
4005
4006 /**
4007 * Sets the data activation state of a given subId.
4008 */
4009 @Override
4010 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4012 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 final Phone phone = getPhone(subId);
4017 if (phone != null) {
4018 phone.setDataActivationState(activationState);
4019 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004020 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 }
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004024 }
4025 }
4026
4027 /**
4028 * Returns the voice activation state of a given subId.
4029 */
4030 @Override
4031 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
fionaxu0152e512016-11-14 13:36:14 -08004034 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 if (phone != null) {
4038 return phone.getVoiceActivationState();
4039 } else {
4040 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4041 }
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004044 }
4045 }
4046
4047 /**
4048 * Returns the data activation state of a given subId.
4049 */
4050 @Override
4051 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053
fionaxu0152e512016-11-14 13:36:14 -08004054 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 if (phone != null) {
4058 return phone.getDataActivationState();
4059 } else {
4060 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4061 }
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004064 }
4065 }
4066
4067 /**
Wink Saville36469e72014-06-11 15:17:00 -07004068 * Returns the unread count of voicemails for a subId
4069 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004071 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4072 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 mApp, subId, callingPackage, callingFeatureId,
4075 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004076 return 0;
4077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 final Phone phone = getPhone(subId);
4081 if (phone != null) {
4082 return phone.getVoiceMessageCount();
4083 } else {
4084 return 0;
4085 }
4086 } finally {
4087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089 }
4090
4091 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004092 * returns true, if the device is in a state where both voice and data
4093 * are supported simultaneously. This can change based on location or network condition.
4094 */
4095 @Override
4096 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004097 final long identity = Binder.clearCallingIdentity();
4098 try {
4099 final Phone phone = getPhone(subId);
4100 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004104 }
4105
4106 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004107 * Send the dialer code if called from the current default dialer or the caller has
4108 * carrier privilege.
4109 * @param inputCode The dialer code to send
4110 */
4111 @Override
4112 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004115 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4116 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004117 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004118 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004119 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121
4122 final long identity = Binder.clearCallingIdentity();
4123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004124 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
fionaxu235cc5e2017-03-06 22:25:57 -08004128 }
4129
Pengquan Menga1bb6272018-09-06 09:59:22 -07004130 @Override
4131 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004132 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004133 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004134 mApp, subId, "getNetworkSelectionMode");
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 if (!isActiveSubscription(subId)) {
4138 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4139 }
4140 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4141 } finally {
4142 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004143 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004144 }
4145
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004147 public boolean isInEmergencySmsMode() {
4148 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 for (Phone phone : PhoneFactory.getPhones()) {
4152 if (phone.isInEmergencySmsMode()) {
4153 return true;
4154 }
4155 }
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159 return false;
4160 }
4161
shilu366312e2019-12-17 09:28:10 -08004162 /**
4163 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4164 * @param subId The subscription to use to check the configuration.
4165 * @param c The callback that will be used to send the result.
4166 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004167 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004168 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4169 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004170 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004171 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004172
4173 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4174 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4175 "IMS not available on device.");
4176 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 final long token = Binder.clearCallingIdentity();
4178 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004179 int slotId = getSlotIndexOrException(subId);
4180 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004181
4182 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4183 if (controller != null) {
4184 ImsManager imsManager = controller.getImsManager(subId);
4185 if (imsManager != null) {
4186 imsManager.addRegistrationCallbackForSubscription(c, subId);
4187 } else {
4188 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4189 }
4190 } else {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4192 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 } catch (ImsException e) {
4194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 } finally {
4196 Binder.restoreCallingIdentity(token);
4197 }
4198 }
4199
shilu366312e2019-12-17 09:28:10 -08004200 /**
4201 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4202 * @param subId The subscription to use to check the configuration.
4203 * @param c The callback that will be used to send the result.
4204 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004206 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004208 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004209 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4210 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4211 }
Meng Wangafbc5852019-09-19 17:37:13 -07004212 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004213
Meng Wangafbc5852019-09-19 17:37:13 -07004214 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004215 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4216 if (controller != null) {
4217 ImsManager imsManager = controller.getImsManager(subId);
4218 if (imsManager != null) {
4219 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4220 } else {
4221 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4222 + "is inactive, ignoring unregister.");
4223 // If the ImsManager is not valid, just return, since the callback
4224 // will already have been removed internally.
4225 }
4226 }
Meng Wangafbc5852019-09-19 17:37:13 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 }
4231
Brad Ebingera34a6c22019-10-22 17:36:18 -07004232 /**
4233 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4234 */
4235 @Override
4236 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4237 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4238 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4239 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4240 "IMS not available on device.");
4241 }
4242 final long token = Binder.clearCallingIdentity();
4243 try {
4244 Phone phone = getPhone(subId);
4245 if (phone == null) {
4246 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4247 + subId + "'");
4248 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4249 }
4250 phone.getImsRegistrationState(regState -> {
4251 try {
4252 consumer.accept((regState == null)
4253 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4254 } catch (RemoteException e) {
4255 // Ignore if the remote process is no longer available to call back.
4256 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4257 }
4258 });
4259 } finally {
4260 Binder.restoreCallingIdentity(token);
4261 }
4262 }
4263
4264 /**
4265 * Get the transport type for the IMS service registration state.
4266 */
4267 @Override
4268 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004269 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004270 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004271 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4272 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4273 "IMS not available on device.");
4274 }
4275 final long token = Binder.clearCallingIdentity();
4276 try {
4277 Phone phone = getPhone(subId);
4278 if (phone == null) {
4279 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4280 + subId + "'");
4281 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4282 }
4283 phone.getImsRegistrationTech(regTech -> {
4284 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4285 int regTechConverted = (regTech == null)
4286 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4287 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4288 regTechConverted);
4289 try {
4290 consumer.accept(regTechConverted);
4291 } catch (RemoteException e) {
4292 // Ignore if the remote process is no longer available to call back.
4293 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4294 }
4295 });
4296 } finally {
4297 Binder.restoreCallingIdentity(token);
4298 }
4299 }
4300
shilu366312e2019-12-17 09:28:10 -08004301 /**
4302 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4303 * @param subId The subscription to use to check the configuration.
4304 * @param c The callback that will be used to send the result.
4305 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004307 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4308 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004309 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004310 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004311 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4312 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4313 "IMS not available on device.");
4314 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 final long token = Binder.clearCallingIdentity();
4316 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004317 int slotId = getSlotIndexOrException(subId);
4318 verifyImsMmTelConfiguredOrThrow(slotId);
4319 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(token);
4324 }
4325 }
4326
shilu366312e2019-12-17 09:28:10 -08004327 /**
4328 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4329 * @param subId The subscription to use to check the configuration.
4330 * @param c The callback that will be used to send the result.
4331 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004332 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004333 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004334 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004335 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004336 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4337 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4338 }
Meng Wangafbc5852019-09-19 17:37:13 -07004339
4340 final long token = Binder.clearCallingIdentity();
4341 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004342 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004343 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004344 } catch (ImsException e) {
4345 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4346 + "is inactive, ignoring unregister.");
4347 // If the subscription is no longer active, just return, since the callback
4348 // will already have been removed internally.
4349 } finally {
4350 Binder.restoreCallingIdentity(token);
4351 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 }
4353
4354 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004355 public boolean isCapable(int subId, int capability, int regTech) {
4356 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 final long token = Binder.clearCallingIdentity();
4358 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004359 int slotId = getSlotIndexOrException(subId);
4360 verifyImsMmTelConfiguredOrThrow(slotId);
4361 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4362 } catch (com.android.ims.ImsException e) {
4363 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4364 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004365 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004366 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4367 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 } finally {
4369 Binder.restoreCallingIdentity(token);
4370 }
4371 }
4372
4373 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004374 public boolean isAvailable(int subId, int capability, int regTech) {
4375 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 final long token = Binder.clearCallingIdentity();
4377 try {
4378 Phone phone = getPhone(subId);
4379 if (phone == null) return false;
4380 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004381 } catch (com.android.ims.ImsException e) {
4382 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4383 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004384 } finally {
4385 Binder.restoreCallingIdentity(token);
4386 }
4387 }
4388
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004389 /**
4390 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4391 * subscription.
4392 * @param subId The subscription to use to check the configuration.
4393 * @param callback The callback that will be used to send the result.
4394 * @param capability The MmTelFeature capability that will be used to send the result.
4395 * @param transportType The transport type of the MmTelFeature capability.
4396 */
4397 @Override
4398 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4399 int transportType) {
4400 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004401 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4402 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4403 "IMS not available on device.");
4404 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004405 final long token = Binder.clearCallingIdentity();
4406 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004407 int slotId = getSlotIndex(subId);
4408 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4409 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4410 + subId + "'");
4411 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4412 }
4413 verifyImsMmTelConfiguredOrThrow(slotId);
4414 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4415 transportType, aBoolean -> {
4416 try {
4417 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4418 } catch (RemoteException e) {
4419 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4420 + "running. Ignore");
4421 }
4422 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 } catch (ImsException e) {
4424 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004425 } finally {
4426 Binder.restoreCallingIdentity(token);
4427 }
4428 }
4429
shilu366312e2019-12-17 09:28:10 -08004430 /**
4431 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4432 * @param subId The subscription to use to check the configuration.
4433 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 @Override
4435 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004436 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004437 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004438
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 final long token = Binder.clearCallingIdentity();
4440 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004442 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004444 } catch (ImsException e) {
4445 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 } finally {
4447 Binder.restoreCallingIdentity(token);
4448 }
4449 }
4450
4451 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004452 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 final long identity = Binder.clearCallingIdentity();
4456 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004458 // This setting doesn't require an active ImsService connection, so do not verify. The
4459 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
shilu366312e2019-12-17 09:28:10 -08004468 /**
4469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4470 * @param subId The subscription to use to check the configuration.
4471 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004473 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004474 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004475 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 final long identity = Binder.clearCallingIdentity();
4477 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004478 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004479 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004480 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004481 } catch (ImsException e) {
4482 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
4486 }
4487
4488 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004489 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004491 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004495 // This setting doesn't require an active ImsService connection, so do not verify. The
4496 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004498 } catch (ImsException e) {
4499 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
4503 }
4504
shilu366312e2019-12-17 09:28:10 -08004505 /**
4506 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4507 * @param subId The subscription to use to check the configuration.
4508 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 @Override
4510 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004511 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004512 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 final long identity = Binder.clearCallingIdentity();
4514 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004515 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004516 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004517 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004518 } catch (ImsException e) {
4519 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
4525 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004526 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004528 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004531 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004532 // This setting doesn't require an active ImsService connection, so do not verify. The
4533 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004535 } catch (ImsException e) {
4536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
4540 }
4541
shilu366312e2019-12-17 09:28:10 -08004542 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004543 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4545 * @param subId The subscription to use to check the configuration.
4546 */
4547 @Override
4548 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004549 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004550 mApp, subId, "isCrossSimCallingEnabledByUser");
4551 final long identity = Binder.clearCallingIdentity();
4552 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004553 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004554 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004555 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004556 } catch (ImsException e) {
4557 throw new ServiceSpecificException(e.getCode());
4558 } finally {
4559 Binder.restoreCallingIdentity(identity);
4560 }
4561 }
4562
4563 /**
4564 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4565 * Requires MODIFY_PHONE_STATE permission.
4566 * @param subId The subscription to use to check the configuration.
4567 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4568 * false otherwise
4569 */
4570 @Override
4571 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4573 "setCrossSimCallingEnabled");
4574 final long identity = Binder.clearCallingIdentity();
4575 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004576 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004577 // This setting doesn't require an active ImsService connection, so do not verify. The
4578 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004580 } catch (ImsException e) {
4581 throw new ServiceSpecificException(e.getCode());
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
4587 /**
shilu366312e2019-12-17 09:28:10 -08004588 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4589 * @param subId The subscription to use to check the configuration.
4590 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004591 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004592
Brad Ebinger35c841c2018-10-01 10:40:55 -07004593 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004594 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004595 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 final long identity = Binder.clearCallingIdentity();
4597 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004598 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004599 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004600 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004601 } catch (ImsException e) {
4602 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606 }
4607
4608 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004609 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004611 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004612 final long identity = Binder.clearCallingIdentity();
4613 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004614 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004615 // This setting doesn't require an active ImsService connection, so do not verify. The
4616 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004618 } catch (ImsException e) {
4619 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004620 } finally {
4621 Binder.restoreCallingIdentity(identity);
4622 }
4623 }
4624
4625 @Override
4626 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4628 "setVoWiFiNonPersistent");
4629 final long identity = Binder.clearCallingIdentity();
4630 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004631 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004632 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004633 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004634 } catch (ImsException e) {
4635 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
shilu366312e2019-12-17 09:28:10 -08004641 /**
4642 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4643 * @param subId The subscription to use to check the configuration.
4644 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004645 @Override
4646 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004647 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004648 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004649 final long identity = Binder.clearCallingIdentity();
4650 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004651 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004652 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004653 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004654 } catch (ImsException e) {
4655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
4659 }
4660
4661 @Override
4662 public void setVoWiFiModeSetting(int subId, int mode) {
4663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4664 "setVoWiFiModeSetting");
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004667 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004668 // This setting doesn't require an active ImsService connection, so do not verify. The
4669 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 } catch (ImsException e) {
4672 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677
4678 @Override
4679 public int getVoWiFiRoamingModeSetting(int subId) {
4680 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4681 final long identity = Binder.clearCallingIdentity();
4682 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004683 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004684 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004685 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004686 } catch (ImsException e) {
4687 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
4691 }
4692
4693 @Override
4694 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4696 "setVoWiFiRoamingModeSetting");
4697 final long identity = Binder.clearCallingIdentity();
4698 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004699 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004700 // This setting doesn't require an active ImsService connection, so do not verify. The
4701 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004703 } catch (ImsException e) {
4704 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
4710 @Override
4711 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4713 "setRttCapabilityEnabled");
4714 final long identity = Binder.clearCallingIdentity();
4715 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004716 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004717 // This setting doesn't require an active ImsService connection, so do not verify. The
4718 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004720 } catch (ImsException e) {
4721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
4725 }
4726
shilu366312e2019-12-17 09:28:10 -08004727 /**
4728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4729 * @param subId The subscription to use to check the configuration.
4730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004731 @Override
4732 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004733 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004734 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004735 final long identity = Binder.clearCallingIdentity();
4736 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004737 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004738 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004739 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004740 } catch (ImsException e) {
4741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 } finally {
4743 Binder.restoreCallingIdentity(identity);
4744 }
4745 }
4746
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004747 @Override
4748 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4749 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004750
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004751 final long identity = Binder.clearCallingIdentity();
4752 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004753 if (!isImsAvailableOnDevice()) {
4754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4755 "IMS not available on device.");
4756 }
4757 int slotId = getSlotIndexOrException(subId);
4758 verifyImsMmTelConfiguredOrThrow(slotId);
4759 ImsManager.getInstance(mApp, slotId)
4760 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004761 } catch (ImsException e) {
4762 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
4769 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4770 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004771
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004772 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4775 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004778 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004780 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4781 + "is inactive, ignoring unregister.");
4782 // If the subscription is no longer active, just return, since the callback will already
4783 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
4787 }
4788
joonhunshincffb7fc2021-11-28 07:32:01 +00004789 @Override
4790 public void registerFeatureProvisioningChangedCallback(int subId,
4791 IFeatureProvisioningCallback callback) {
4792 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4793 mApp, subId, "registerFeatureProvisioningChangedCallback");
4794
4795 final long identity = Binder.clearCallingIdentity();
4796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4797 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4798 }
4799
joonhunshin91bc1952022-04-29 08:47:15 +00004800 try {
4801 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4802 if (controller == null) {
4803 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4804 "Device does not support IMS");
4805 }
4806 controller.addFeatureProvisioningChangedCallback(subId, callback);
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
4809 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004810 }
4811
4812 @Override
4813 public void unregisterFeatureProvisioningChangedCallback(int subId,
4814 IFeatureProvisioningCallback callback) {
4815 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4816 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4817
4818 final long identity = Binder.clearCallingIdentity();
4819 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4820 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4821 }
4822
joonhunshin91bc1952022-04-29 08:47:15 +00004823 try {
4824 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4825 if (controller == null) {
4826 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4827 return;
4828 }
4829 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4830 } finally {
4831 Binder.restoreCallingIdentity(identity);
4832 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004833 }
allenwtsu99c623b2020-01-03 18:24:23 +08004834
4835 private void checkModifyPhoneStatePermission(int subId, String message) {
4836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4837 message);
4838 }
4839
allenwtsu99c623b2020-01-03 18:24:23 +08004840 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004841 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004842 boolean isProvisioned) {
4843 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4844
4845 final long identity = Binder.clearCallingIdentity();
4846 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004847 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4848 if (controller == null) {
4849 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4850 return;
4851 }
4852 controller.setRcsProvisioningStatusForCapability(
4853 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
allenwtsu99c623b2020-01-03 18:24:23 +08004857 }
4858
4859
4860 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004861 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4862 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4863 mApp, subId, "getRcsProvisioningStatusForCapability");
4864
allenwtsu99c623b2020-01-03 18:24:23 +08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004867 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4868 if (controller == null) {
4869 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4870
4871 // device does not support IMS, this method will return true always.
4872 return true;
4873 }
4874 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
4878 }
4879
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004880 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4882 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004883 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004884
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004885 final long identity = Binder.clearCallingIdentity();
4886 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004887 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4888 if (controller == null) {
4889 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4890 return;
4891 }
4892 controller.setImsProvisioningStatusForCapability(
4893 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
4897 }
4898
4899 @Override
4900 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004901 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4902 mApp, subId, "getProvisioningStatusForCapability");
4903
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004906 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4907 if (controller == null) {
4908 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909
joonhunshin91bc1952022-04-29 08:47:15 +00004910 // device does not support IMS, this method will return true always.
4911 return true;
4912 }
4913 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004914 } finally {
4915 Binder.restoreCallingIdentity(identity);
4916 }
4917 }
4918
4919 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004920 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4922 mApp, subId, "isProvisioningRequiredForCapability");
4923
4924 final long identity = Binder.clearCallingIdentity();
4925 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004926 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4927 if (controller == null) {
4928 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4929
4930 // device does not support IMS, this method will return false
4931 return false;
4932 }
4933 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004936 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004937 }
4938
4939 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004940 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4941 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4942 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943
joonhunshincffb7fc2021-11-28 07:32:01 +00004944 final long identity = Binder.clearCallingIdentity();
4945 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004946 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4947 if (controller == null) {
4948 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4949
4950 // device does not support IMS, this method will return false
4951 return false;
4952 }
4953 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 }
4958
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4962 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4963 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004964 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4965 mApp, subId, "getImsProvisioningInt");
4966
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004970 int slotId = getSlotIndex(subId);
4971 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4972 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4973 + subId + "' for key:" + key);
4974 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4975 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004976
joonhunshin91bc1952022-04-29 08:47:15 +00004977 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4978 if (controller == null) {
4979 loge("getImsProvisioningInt: Device does not support IMS");
4980
4981 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4982 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4983 }
4984 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004985 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4986 return retVal;
4987 }
4988
calvinpanb5a34062021-02-08 19:59:36 +08004989 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004990 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004991 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4992 + subId + "' for key:" + key);
4993 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
4997 }
4998
4999 @Override
5000 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005001 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5002 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5003 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005004 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5005 mApp, subId, "getImsProvisioningString");
5006
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005010 int slotId = getSlotIndex(subId);
5011 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5012 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5013 + subId + "' for key:" + key);
5014 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5015 }
calvinpanb5a34062021-02-08 19:59:36 +08005016 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005017 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005018 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5019 + subId + "' for key:" + key);
5020 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005021 } finally {
5022 Binder.restoreCallingIdentity(identity);
5023 }
5024 }
5025
5026 @Override
5027 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005028 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5029 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5030 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5032 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005033
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005037 int slotId = getSlotIndex(subId);
5038 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5039 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5040 + subId + "' for key:" + key);
5041 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5042 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005043
joonhunshin91bc1952022-04-29 08:47:15 +00005044 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5045 if (controller == null) {
5046 loge("setImsProvisioningInt: Device does not support IMS");
5047
5048 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5049 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5050 }
5051 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005052 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5053 return retVal;
5054 }
5055
calvinpanb5a34062021-02-08 19:59:36 +08005056 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5057 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005058 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005059 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005060 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
5064 }
5065
5066 @Override
5067 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5069 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5070 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5072 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005076 int slotId = getSlotIndex(subId);
5077 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5078 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5079 + subId + "' for key:" + key);
5080 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5081 }
calvinpanb5a34062021-02-08 19:59:36 +08005082 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5083 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005084 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005085 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005086 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005087 } finally {
5088 Binder.restoreCallingIdentity(identity);
5089 }
5090 }
5091
Brad Ebinger919631e2021-06-02 17:46:35 -07005092 /**
5093 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5094 * for the given slot ID or no ImsResolver instance has been created.
5095 * @param slotId The slot ID that the IMS service is created for.
5096 * @throws ImsException If there is no ImsService configured for this slot.
5097 */
5098 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5099 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5100 ImsFeature.FEATURE_MMTEL)) {
5101 throw new ImsException("This subscription does not support MMTEL over IMS",
5102 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5103 }
5104 }
5105
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005106 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005107 int slotId = SubscriptionManager.getSlotIndex(subId);
5108 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005109 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5110 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005111 }
5112 return slotId;
5113 }
5114
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005115 private int getSlotIndex(int subId) {
5116 int slotId = SubscriptionManager.getSlotIndex(subId);
5117 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5118 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5119 }
5120 return slotId;
5121 }
5122
Wink Saville36469e72014-06-11 15:17:00 -07005123 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005124 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005125 */
5126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005127 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5128 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005129 try {
5130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5131 } catch (SecurityException se) {
5132 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5133 throw new SecurityException("Package " + callingPackage + " does not belong to "
5134 + Binder.getCallingUid());
5135 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005136 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005137 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005138 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005139 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005140 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005141 mApp, subId, callingPackage, callingFeatureId,
5142 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5144 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 final Phone phone = getPhone(subId);
5149 if (phone != null) {
5150 return phone.getServiceState().getDataNetworkType();
5151 } else {
5152 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5153 }
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005157 }
5158
5159 /**
5160 * Returns the data network type
5161 */
5162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005163 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005164 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5165 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005166 }
5167
5168 /**
5169 * Returns the data network type for a subId
5170 */
5171 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005172 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5173 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005174 String functionName = "getDataNetworkTypeForSubscriber";
5175 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5176 mApp, functionName)) {
5177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5178 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5179 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5180 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005181 }
5182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 final long identity = Binder.clearCallingIdentity();
5184 try {
5185 final Phone phone = getPhone(subId);
5186 if (phone != null) {
5187 return phone.getServiceState().getDataNetworkType();
5188 } else {
5189 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5190 }
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005194 }
5195
5196 /**
Wink Saville36469e72014-06-11 15:17:00 -07005197 * Returns the Voice network type for a subId
5198 */
5199 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005200 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5201 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005202 String functionName = "getVoiceNetworkTypeForSubscriber";
5203 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5204 mApp, functionName)) {
5205 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5206 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5208 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005209 }
5210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 final Phone phone = getPhone(subId);
5214 if (phone != null) {
5215 return phone.getServiceState().getVoiceNetworkType();
5216 } else {
5217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5218 }
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005222 }
5223
5224 /**
5225 * @return true if a ICC card is present
5226 */
5227 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005228 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005229 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5230 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005231 }
5232
5233 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005234 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005235 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 final Phone phone = PhoneFactory.getPhone(slotIndex);
5241 if (phone != null) {
5242 return phone.getIccCard().hasIccCard();
5243 } else {
5244 return false;
5245 }
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005249 }
5250
5251 /**
5252 * Return if the current radio is LTE on CDMA. This
5253 * is a tri-state return value as for a period of time
5254 * the mode may be unknown.
5255 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005256 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005257 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005258 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005259 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005261 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5262 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5263 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005264 }
5265
Sanket Padawe356d7632015-06-22 14:03:32 -07005266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005267 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5268 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005269 try {
5270 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5271 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005272 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5273 }
5274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 final Phone phone = getPhone(subId);
5278 if (phone == null) {
5279 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5280 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005281 return TelephonyProperties.lte_on_cdma_device()
5282 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 }
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005286 }
Wink Saville36469e72014-06-11 15:17:00 -07005287 }
5288
Wink Saville36469e72014-06-11 15:17:00 -07005289 /**
5290 * {@hide}
5291 * Returns Default subId, 0 in the case of single standby.
5292 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005293 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005294 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005295 }
5296
Shishir Agrawala9f32182016-04-12 12:00:16 -07005297 private int getSlotForDefaultSubscription() {
5298 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5299 }
5300
Wink Savilleb564aae2014-10-23 10:18:09 -07005301 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005302 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005303 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005304
Pengquan Menge92a50d2018-09-21 15:54:48 -07005305 private boolean isActiveSubscription(int subId) {
5306 return mSubscriptionController.isActiveSubId(subId);
5307 }
5308
Ihab Awadf2177b72013-11-25 13:33:23 -08005309 /**
5310 * @see android.telephony.TelephonyManager.WifiCallingChoices
5311 */
5312 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 final long identity = Binder.clearCallingIdentity();
5314 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005315 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5317 getWhenToMakeWifiCallsDefaultPreference());
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
5320 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005321 }
5322
5323 /**
5324 * @see android.telephony.TelephonyManager.WifiCallingChoices
5325 */
5326 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005330 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005335 }
5336
Sailesh Nepald1e68152013-12-12 19:08:02 -08005337 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005338 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005339 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005340 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005341
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005342 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5343 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5344 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005345 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005346 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5347 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005348 }
5349 return PhoneFactory.getPhone(phoneId);
5350 }
5351
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005353 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005354 @NonNull IccLogicalChannelRequest request) {
5355 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5356 /*message=*/ "iccOpenLogicalChannel");
5357
5358 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5359 // Verify that the callingPackage in the request belongs to the calling UID
5360 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5361
5362 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005363 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364
Rambo Wanga1782702021-11-10 20:15:19 -08005365 private Phone getPhoneFromValidIccLogicalChannelRequest(
5366 @NonNull IccLogicalChannelRequest request, String message) {
5367 Phone phone;
5368 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, request.subId, message);
5371 phone = getPhoneFromSubId(request.subId);
5372 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5373 enforceModifyPermission();
5374 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5375 } else {
5376 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005377 }
Rambo Wanga1782702021-11-10 20:15:19 -08005378 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005379 }
5380
5381 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005382 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 final long identity = Binder.clearCallingIdentity();
5384 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005385 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005387 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5388 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005389 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5390 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 loge("The calling package is not allowed to access ISD-R.");
5392 throw new SecurityException(
5393 "The calling package is not allowed to access ISD-R.");
5394 }
Derek Tan740e1672017-06-27 14:56:27 -07005395 }
Derek Tan740e1672017-06-27 14:56:27 -07005396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005398 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5399 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 return response;
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005404 }
5405
5406 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005407 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5408 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5409 /*message=*/"iccCloseLogicalChannel");
5410
5411 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5412
5413 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005414 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005415
Rambo Wanga1782702021-11-10 20:15:19 -08005416 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5417 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005418 // before this feature is enabled, this API should only return false if
5419 // the operation fails instead of throwing runtime exception for
5420 // backward-compatibility.
5421 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5422 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005425 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005426 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 }
Chen Xue9d737e2022-01-01 23:41:31 -08005428 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005429 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005430 Boolean success = false;
5431 if (result instanceof RuntimeException) {
5432 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005433 if (shouldThrowExceptionOnFailure) {
5434 throw (RuntimeException) result;
5435 } else {
5436 return false;
5437 }
Chen Xue9d737e2022-01-01 23:41:31 -08005438 } else if (result instanceof Boolean) {
5439 success = (Boolean) result;
5440 } else {
5441 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5442 }
Rambo Wanga1782702021-11-10 20:15:19 -08005443 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 return success;
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005447 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005448 }
5449
5450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005451 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005452 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5454 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005455 if (DBG) {
5456 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5457 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5458 + p3 + " data=" + data);
5459 }
5460 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5461 command, p1, p2, p3, data);
5462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005463
Jordan Liu4c733742019-02-28 12:03:40 -08005464 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005465 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5466 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005467 enforceModifyPermission();
5468 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005469 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5470 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5471 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005472 }
5473 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005474 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5475 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005476 }
5477
5478 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5479 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005482 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 return "";
5484 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005487 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5488 null /* workSource */);
5489 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 // Append the returned status code to the end of the response payload.
5492 String s = Integer.toHexString(
5493 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5494 if (response.payload != null) {
5495 s = IccUtils.bytesToHexString(response.payload) + s;
5496 }
5497 return s;
5498 } finally {
5499 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005500 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005501 }
Jake Hambye994d462014-02-03 13:10:13 -08005502
Evan Charltonc66da362014-05-16 14:06:40 -07005503 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005504 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5505 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005509 if (DBG) {
5510 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5511 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5512 }
5513 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5514 cla, command, p1, p2, p3, data);
5515 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005516
Jordan Liu4c733742019-02-28 12:03:40 -08005517 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005518 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5519 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005520 enforceModifyPermission();
5521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5522 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005523 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5524 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5525 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005526 }
5527
5528 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005529 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5530 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005531 }
5532
5533 // open APDU basic channel assuming the caller has sufficient permissions
5534 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5535 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5539 && TextUtils.equals(ISDR_AID, data)) {
5540 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005541 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5542 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 if (bestComponent == null
5544 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5545 loge("The calling package is not allowed to select ISD-R.");
5546 throw new SecurityException(
5547 "The calling package is not allowed to select ISD-R.");
5548 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005549 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005552 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5553 null /* workSource */);
5554 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 // Append the returned status code to the end of the response payload.
5557 String s = Integer.toHexString(
5558 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5559 if (response.payload != null) {
5560 s = IccUtils.bytesToHexString(response.payload) + s;
5561 }
5562 return s;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005565 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005566 }
5567
5568 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005569 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005570 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5572 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 if (DBG) {
5577 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5578 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5579 }
5580
5581 IccIoResult response =
5582 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5583 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5584 subId);
5585
5586 if (DBG) {
5587 log("Exchange SIM_IO [R]" + response);
5588 }
5589
5590 byte[] result = null;
5591 int length = 2;
5592 if (response.payload != null) {
5593 length = 2 + response.payload.length;
5594 result = new byte[length];
5595 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5596 } else {
5597 result = new byte[length];
5598 }
5599
5600 result[length - 1] = (byte) response.sw2;
5601 result[length - 2] = (byte) response.sw1;
5602 return result;
5603 } finally {
5604 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005606 }
5607
Nathan Haroldb3014052017-01-25 15:57:32 -08005608 /**
5609 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5610 * on a particular subscription
5611 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005612 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5613 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005615 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005616 return null;
5617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618
5619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 if (appType != TelephonyManager.APPTYPE_USIM
5622 && appType != TelephonyManager.APPTYPE_SIM) {
5623 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5624 return null;
5625 }
5626 Object response = sendRequest(
5627 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5628 if (response instanceof String[]) {
5629 return (String[]) response;
5630 }
yincheng zhao2737e882019-09-06 17:06:54 -07005631 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005633 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 } finally {
5635 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005636 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005637 }
5638
yincheng zhao2737e882019-09-06 17:06:54 -07005639 /**
5640 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5641 * subscription.
5642 *
5643 * @param subId the id of the subscription.
5644 * @param appType the uicc app type, must be USIM or SIM.
5645 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5646 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005647 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005648 * @return number of fplmns that is successfully written to the SIM.
5649 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005650 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5651 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5653 mApp, subId, "setForbiddenPlmns");
5654
yincheng zhao2737e882019-09-06 17:06:54 -07005655 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5656 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5657 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5658 }
5659 if (fplmns == null) {
5660 throw new IllegalArgumentException("Fplmn List provided is null");
5661 }
5662 for (String fplmn : fplmns) {
5663 if (!CellIdentity.isValidPlmn(fplmn)) {
5664 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5665 }
5666 }
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 Object response = sendRequest(
5670 CMD_SET_FORBIDDEN_PLMNS,
5671 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5672 subId);
5673 return (int) response;
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005679 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005680 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5682 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005683
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5687 if (response.payload == null) {
5688 return "";
5689 }
Evan Charltonc66da362014-05-16 14:06:40 -07005690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 // Append the returned status code to the end of the response payload.
5692 String s = Integer.toHexString(
5693 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5694 s = IccUtils.bytesToHexString(response.payload) + s;
5695 return s;
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Evan Charltonc66da362014-05-16 14:06:40 -07005699 }
5700
Jake Hambye994d462014-02-03 13:10:13 -08005701 /**
5702 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5703 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5704 *
5705 * @param itemID the ID of the item to read
5706 * @return the NV item as a String, or null on error.
5707 */
5708 @Override
5709 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5712 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
5715 try {
5716 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005717 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5719 return value;
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
Jake Hambye994d462014-02-03 13:10:13 -08005723 }
5724
5725 /**
5726 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5727 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5728 *
5729 * @param itemID the ID of the item to read
5730 * @param itemValue the value to write, as a String
5731 * @return true on success; false on any failure
5732 */
5733 @Override
5734 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005735 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5737 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5742 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005743 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005744 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5745 return success;
5746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
Jake Hambye994d462014-02-03 13:10:13 -08005749 }
5750
5751 /**
5752 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5753 * Used for device configuration by some CDMA operators.
5754 *
5755 * @param preferredRoamingList byte array containing the new PRL
5756 * @return true on success; false on any failure
5757 */
5758 @Override
5759 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5761 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5766 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5767 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5768 return success;
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
Jake Hambye994d462014-02-03 13:10:13 -08005772 }
5773
5774 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005775 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005776 * Used for device configuration by some CDMA operators.
5777 *
chen xu6dac5ab2018-10-26 17:39:23 -07005778 * @param slotIndex - device slot.
5779 *
Jake Hambye994d462014-02-03 13:10:13 -08005780 * @return true on success; false on any failure
5781 */
5782 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005783 public boolean resetModemConfig(int slotIndex) {
5784 Phone phone = PhoneFactory.getPhone(slotIndex);
5785 if (phone != null) {
5786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5787 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788
chen xu6dac5ab2018-10-26 17:39:23 -07005789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5792 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5793 return success;
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 }
chen xu6dac5ab2018-10-26 17:39:23 -07005798 return false;
5799 }
5800
5801 /**
5802 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5803 *
5804 * @param slotIndex - device slot.
5805 *
5806 * @return true on success; false on any failure
5807 */
5808 @Override
5809 public boolean rebootModem(int slotIndex) {
5810 Phone phone = PhoneFactory.getPhone(slotIndex);
5811 if (phone != null) {
5812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5813 mApp, phone.getSubId(), "rebootModem");
5814
5815 final long identity = Binder.clearCallingIdentity();
5816 try {
5817 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5818 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5819 return success;
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
5824 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005825 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005826
Brad Ebinger51f743a2017-01-23 13:50:20 -08005827 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005828 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5829 * {@link #disableIms(int)}.
5830 * @param slotIndex device slot.
5831 */
5832 public void resetIms(int slotIndex) {
5833 enforceModifyPermission();
5834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 if (mImsResolver == null) {
5838 // may happen if the does not support IMS.
5839 return;
5840 }
5841 mImsResolver.disableIms(slotIndex);
5842 mImsResolver.enableIms(slotIndex);
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
5846 }
5847
5848 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005849 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5850 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005851 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005852 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
5855 final long identity = Binder.clearCallingIdentity();
5856 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005858 // may happen if the device does not support IMS.
5859 return;
5860 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005865 }
5866
5867 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005868 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5869 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005870 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005871 public void disableIms(int slotId) {
5872 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005877 // may happen if the device does not support IMS.
5878 return;
5879 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005884 }
5885
5886 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005887 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5888 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005889 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005890 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005891 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005897 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5898 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005899 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005900 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005904 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005905 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005906 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5907 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005908 @Override
5909 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005910 enforceModifyPermission();
5911
5912 final long identity = Binder.clearCallingIdentity();
5913 try {
5914 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005915 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
5919 }
5920
5921 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005922 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005923 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005924 */
5925 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005931 // may happen if the device does not support IMS.
5932 return null;
5933 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 } finally {
5936 Binder.restoreCallingIdentity(identity);
5937 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005938 }
5939
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005940 /**
5941 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005942 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005943 */
5944 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005949 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005950 // may happen if the device does not support IMS.
5951 return null;
5952 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005953 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005957 }
5958
Brad Ebinger884c07b2018-02-15 16:17:40 -08005959 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005960 * Sets the ImsService Package Name that Telephony will bind to.
5961 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005962 * @param slotIndex the slot ID that the ImsService should bind for.
5963 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005964 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005965 * @param featureTypes An integer array of feature types associated with a packageName.
5966 * @param packageName The name of the package that the current configuration will be replaced
5967 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005968 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005969 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005970 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5971 int[] featureTypes, String packageName) {
5972 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5975 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005976 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 final long identity = Binder.clearCallingIdentity();
5979 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005980 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005981 // may happen if the device does not support IMS.
5982 return false;
5983 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005984 Map<Integer, String> featureConfig = new HashMap<>();
5985 for (int featureType : featureTypes) {
5986 featureConfig.put(featureType, packageName);
5987 }
5988 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5989 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 } finally {
5991 Binder.restoreCallingIdentity(identity);
5992 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005993 }
5994
5995 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005996 * Clears any carrier ImsService overrides for the slot index specified that were previously
5997 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5998 *
5999 * This should only be used for testing.
6000 *
6001 * @param slotIndex the slot ID that the ImsService should bind for.
6002 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6003 */
6004 @Override
6005 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6006 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6007 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6008 "clearCarrierImsServiceOverride");
6009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6010 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6011 "clearCarrierImsServiceOverride");
6012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
6015 if (mImsResolver == null) {
6016 // may happen if the device does not support IMS.
6017 return false;
6018 }
6019 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
6022 }
6023 }
6024
6025 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006026 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006027 *
6028 * @param slotId The slot that the ImsService is associated with.
6029 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6030 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006031 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006032 * @return the package name of the ImsService configuration.
6033 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006034 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6035 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006036 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006038 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6040 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 final long identity = Binder.clearCallingIdentity();
6043 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006044 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006045 // may happen if the device does not support IMS.
6046 return "";
6047 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006048 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006049 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6050 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006054 }
6055
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006056 /**
6057 * Get the MmTelFeature state associated with the requested subscription id.
6058 * @param subId The subscription that the MmTelFeature is associated with.
6059 * @param callback A callback with an integer containing the
6060 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6061 */
6062 @Override
6063 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6064 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006065 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6066 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6067 "IMS not available on device.");
6068 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006069 final long token = Binder.clearCallingIdentity();
6070 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006071 int slotId = getSlotIndex(subId);
6072 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6073 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6074 + subId + "'");
6075 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6076 }
6077 verifyImsMmTelConfiguredOrThrow(slotId);
6078 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6079 try {
6080 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6081 } catch (RemoteException e) {
6082 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6083 + "Ignore");
6084 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006085 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006086 } catch (ImsException e) {
6087 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006088 } finally {
6089 Binder.restoreCallingIdentity(token);
6090 }
6091 }
6092
Daniel Brightbb5840b2021-01-12 15:48:18 -08006093 /**
6094 * Sets the ims registration state on all valid {@link Phone}s.
6095 */
6096 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098
6099 final long identity = Binder.clearCallingIdentity();
6100 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006101 // NOTE: Before S, this method only set the default phone.
6102 for (final Phone phone : PhoneFactory.getPhones()) {
6103 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6104 phone.setImsRegistrationState(registered);
6105 }
6106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
Wink Saville36469e72014-06-11 15:17:00 -07006110 }
6111
6112 /**
Stuart Scott54788802015-03-30 13:18:01 -07006113 * Set the network selection mode to automatic.
6114 *
6115 */
6116 @Override
6117 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6119 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120
6121 final long identity = Binder.clearCallingIdentity();
6122 try {
shilufc958392020-01-20 11:36:01 -08006123 if (!isActiveSubscription(subId)) {
6124 return;
6125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006127 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6128 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
Stuart Scott54788802015-03-30 13:18:01 -07006132 }
6133
Jack Yud10cdd42020-09-28 20:28:01 -07006134 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006135 * Ask the radio to connect to the input network and change selection mode to manual.
6136 *
6137 * @param subId the id of the subscription.
6138 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6139 * the operator to attach to.
6140 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6141 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6142 * normal network selection next time.
6143 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006144 */
6145 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006146 public boolean setNetworkSelectionModeManual(
6147 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6149 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006150
6151 if (!isActiveSubscription(subId)) {
6152 return false;
6153 }
6154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 final long identity = Binder.clearCallingIdentity();
6156 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006157 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006159 if (DBG) {
6160 log("setNetworkSelectionModeManual: subId: " + subId
6161 + " operator: " + operatorInfo);
6162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006167 }
shilu84f6e8b2019-12-19 13:58:01 -08006168 /**
6169 * Get the manual network selection
6170 *
6171 * @param subId the id of the subscription.
6172 *
6173 * @return the previously saved user selected PLMN
6174 */
6175 @Override
6176 public String getManualNetworkSelectionPlmn(int subId) {
6177 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006178 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006179 mApp, subId, "getManualNetworkSelectionPlmn");
6180
6181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006184 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006185 }
6186
6187 final Phone phone = getPhone(subId);
6188 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006189 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006190 }
6191 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6192 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6193 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
6197 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006198
6199 /**
6200 * Scans for available networks.
6201 */
6202 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006203 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6204 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6206 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006207 LocationAccessPolicy.LocationPermissionResult locationResult =
6208 LocationAccessPolicy.checkLocationPermission(mApp,
6209 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6210 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006211 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006212 .setCallingPid(Binder.getCallingPid())
6213 .setCallingUid(Binder.getCallingUid())
6214 .setMethod("getCellNetworkScanResults")
6215 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006216 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6217 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .build());
6219 switch (locationResult) {
6220 case DENIED_HARD:
6221 throw new SecurityException("Not allowed to access scan results -- location");
6222 case DENIED_SOFT:
6223 return null;
6224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225
Pengquan Menga1bb6272018-09-06 09:59:22 -07006226 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 try {
6228 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006229 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006234 }
6235
6236 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006237 * Get the call forwarding info, given the call forwarding reason.
6238 */
6239 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006240 public void getCallForwarding(int subId, int callForwardingReason,
6241 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006242 enforceReadPrivilegedPermission("getCallForwarding");
6243 long identity = Binder.clearCallingIdentity();
6244 try {
6245 if (DBG) {
6246 log("getCallForwarding: subId " + subId
6247 + " callForwardingReason" + callForwardingReason);
6248 }
Hall Liu27d24262020-09-18 19:04:59 -07006249
6250 Phone phone = getPhone(subId);
6251 if (phone == null) {
6252 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006253 callback.onError(
6254 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006255 } catch (RemoteException e) {
6256 // ignore
6257 }
6258 return;
6259 }
6260
6261 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6262 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6263 @Override
6264 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6265 try {
6266 callback.onCallForwardingInfoAvailable(info);
6267 } catch (RemoteException e) {
6268 // ignore
6269 }
6270 }
6271
6272 @Override
6273 public void onError(int error) {
6274 try {
6275 callback.onError(error);
6276 } catch (RemoteException e) {
6277 // ignore
6278 }
6279 }
6280 });
6281 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
6285 }
6286
6287 /**
6288 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6289 * reason, the number to forward, and the timeout before the forwarding is attempted.
6290 */
6291 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006292 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6293 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006294 enforceModifyPermission();
6295 long identity = Binder.clearCallingIdentity();
6296 try {
6297 if (DBG) {
6298 log("setCallForwarding: subId " + subId
6299 + " callForwardingInfo" + callForwardingInfo);
6300 }
Hall Liu27d24262020-09-18 19:04:59 -07006301
6302 Phone phone = getPhone(subId);
6303 if (phone == null) {
6304 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006305 callback.accept(
6306 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006307 } catch (RemoteException e) {
6308 // ignore
6309 }
6310 return;
6311 }
6312
6313 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6314 FunctionalUtils.ignoreRemoteException(callback::accept));
6315
6316 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 }
6321
6322 /**
Hall Liu27d24262020-09-18 19:04:59 -07006323 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006324 */
6325 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006326 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006327 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006328 long identity = Binder.clearCallingIdentity();
6329 try {
Hall Liu27d24262020-09-18 19:04:59 -07006330 Phone phone = getPhone(subId);
6331 if (phone == null) {
6332 try {
6333 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6334 } catch (RemoteException e) {
6335 // ignore
6336 }
6337 return;
6338 }
SongFerngWang0e767992021-03-31 22:08:45 +08006339 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6340 PersistableBundle c = configManager.getConfigForSubId(subId);
6341 boolean requireUssd = c.getBoolean(
6342 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006343
Shuo Qian4a594052020-01-23 11:59:30 -08006344 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006345 if (requireUssd) {
6346 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6347 getSubscriptionCarrierId(subId));
6348 String newUssdCommand = "";
6349 try {
6350 newUssdCommand = carrierXmlParser.getFeature(
6351 CarrierXmlParser.FEATURE_CALL_WAITING)
6352 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6353 } catch (NullPointerException e) {
6354 loge("Failed to generate USSD number" + e);
6355 }
6356 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6357 mMainThreadHandler, callback, carrierXmlParser,
6358 CarrierXmlParser.SsEntry.SSAction.QUERY);
6359 final String ussdCommand = newUssdCommand;
6360 Executors.newSingleThreadExecutor().execute(() -> {
6361 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6362 });
6363 } else {
6364 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6365 callback::accept);
6366 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6367 }
Shuo Qian4a594052020-01-23 11:59:30 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
6371 }
6372
6373 /**
Hall Liu27d24262020-09-18 19:04:59 -07006374 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006375 */
6376 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006377 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006378 enforceModifyPermission();
6379 long identity = Binder.clearCallingIdentity();
6380 try {
Hall Liu27d24262020-09-18 19:04:59 -07006381 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6382
6383 Phone phone = getPhone(subId);
6384 if (phone == null) {
6385 try {
6386 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6387 } catch (RemoteException e) {
6388 // ignore
6389 }
6390 return;
6391 }
6392
SongFerngWang0e767992021-03-31 22:08:45 +08006393 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6394 PersistableBundle c = configManager.getConfigForSubId(subId);
6395 boolean requireUssd = c.getBoolean(
6396 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006397
SongFerngWang0e767992021-03-31 22:08:45 +08006398 if (DBG) log("getCallWaitingStatus: subId " + subId);
6399 if (requireUssd) {
6400 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6401 getSubscriptionCarrierId(subId));
6402 CarrierXmlParser.SsEntry.SSAction ssAction =
6403 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6404 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6405 String newUssdCommand = "";
6406 try {
6407 newUssdCommand = carrierXmlParser.getFeature(
6408 CarrierXmlParser.FEATURE_CALL_WAITING)
6409 .makeCommand(ssAction, null);
6410 } catch (NullPointerException e) {
6411 loge("Failed to generate USSD number" + e);
6412 }
6413 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6414 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6415 final String ussdCommand = newUssdCommand;
6416 Executors.newSingleThreadExecutor().execute(() -> {
6417 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6418 });
6419 } else {
6420 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6421 FunctionalUtils.ignoreRemoteException(callback::accept));
6422
6423 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6424 }
Shuo Qian4a594052020-01-23 11:59:30 -08006425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
yinxub1bed742017-04-17 11:45:04 -07006431 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006432 *
yinxub1bed742017-04-17 11:45:04 -07006433 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006434 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6435 * location related information which will be sent if the caller already possess
6436 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006437 * @param request contains the radio access networks with bands/channels to scan
6438 * @param messenger callback messenger for scan results or errors
6439 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006440 * @return the id of the requested scan which can be used to stop the scan.
6441 */
6442 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006443 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6444 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006445 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6447 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006448 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006449 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6450 if (!renounceFineLocationAccess) {
6451 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6452 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6453 .setCallingPackage(callingPackage)
6454 .setCallingFeatureId(callingFeatureId)
6455 .setCallingPid(Binder.getCallingPid())
6456 .setCallingUid(Binder.getCallingUid())
6457 .setMethod("requestNetworkScan")
6458 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6459 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6460 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6461 .build());
6462 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006463 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006464 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6465 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006466 if (e != null) {
6467 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6468 throw e;
6469 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006470 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006471 return TelephonyScanManager.INVALID_SCAN_ID;
6472 }
6473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 }
Hall Liu912dfd32019-04-25 14:02:26 -07006475 int callingUid = Binder.getCallingUid();
6476 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006480 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006481 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
yinxu504e1392017-04-12 16:03:22 -07006485 }
6486
Hall Liub2ac8ef2019-02-28 15:56:23 -08006487 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006488 NetworkScanRequest request, int subId, String callingPackage) {
6489 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006490 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6491 boolean hasNetworkScanPermission =
6492 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6493 == PERMISSION_GRANTED;
6494
6495 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6496 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6497 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006498 }
6499
6500 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6501 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006502 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6503 return new SecurityException("Specific channels must not be"
6504 + " scanned without location access.");
6505 }
6506 }
6507 }
6508
Hall Liub2ac8ef2019-02-28 15:56:23 -08006509 return null;
6510 }
6511
yinxu504e1392017-04-12 16:03:22 -07006512 /**
6513 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006514 *
6515 * @param subId id of the subscription
6516 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006517 */
6518 @Override
6519 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6521 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522
Hall Liu912dfd32019-04-25 14:02:26 -07006523 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524 final long identity = Binder.clearCallingIdentity();
6525 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006526 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527 } finally {
6528 Binder.restoreCallingIdentity(identity);
6529 }
yinxu504e1392017-04-12 16:03:22 -07006530 }
6531
6532 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006533 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006534 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006535 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006536 */
6537 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006538 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006539 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
6544 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 if (DBG) log("getAllowedNetworkTypesBitmask");
6546 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6547 int networkTypesBitmask = (result != null ? result[0] : -1);
6548 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6549 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 } finally {
6551 Binder.restoreCallingIdentity(identity);
6552 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006553 }
6554
6555 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006556 * Get the allowed network types for certain reason.
6557 *
6558 * @param subId the id of the subscription.
6559 * @param reason the reason the allowed network type change is taking place
6560 * @return the allowed network types.
6561 */
6562 @Override
6563 public long getAllowedNetworkTypesForReason(int subId,
6564 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006565 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006566 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006567 final long identity = Binder.clearCallingIdentity();
6568 try {
6569 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
6572 }
6573 }
6574
6575 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006576 * Enable/Disable E-UTRA-NR Dual Connectivity
6577 * @param subId subscription id of the sim card
6578 * @param nrDualConnectivityState expected NR dual connectivity state
6579 * This can be passed following states
6580 * <ol>
6581 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6582 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6583 * <li>Disable NR dual connectivity and force secondary cell to be released
6584 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6585 * </ol>
6586 * @return operation result.
6587 */
6588 @Override
6589 public int setNrDualConnectivityState(int subId,
6590 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6592 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006593 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006594 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6595 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6596 }
6597
Sooraj Sasindran37444802020-08-11 10:40:43 -07006598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6602 nrDualConnectivityState, subId,
6603 workSource);
6604 if (DBG) log("enableNRDualConnectivity result: " + result);
6605 return result;
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 }
6610
6611 /**
6612 * Is E-UTRA-NR Dual Connectivity enabled
6613 * @return true if dual connectivity is enabled else false
6614 */
6615 @Override
6616 public boolean isNrDualConnectivityEnabled(int subId) {
6617 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006618 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006619 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006620 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006621 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6622 return false;
6623 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006624 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6628 null, subId, workSource);
6629 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6630 return isEnabled;
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
6633 }
6634 }
6635
6636 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006637 * Set the allowed network types of the device and
6638 * provide the reason triggering the allowed network change.
6639 *
6640 * @param subId the id of the subscription.
6641 * @param reason the reason the allowed network type change is taking place
6642 * @param allowedNetworkTypes the allowed network types.
6643 * @return true on success; false on any failure.
6644 */
6645 @Override
6646 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006647 @TelephonyManager.AllowedNetworkTypesReason int reason,
6648 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6650 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006651 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006652 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6653 return false;
6654 }
6655 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6656 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006657 return false;
6658 }
6659
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006660 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6661 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6662
6663
6664 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6665 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6666 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006667 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006668
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006669 final long identity = Binder.clearCallingIdentity();
6670 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006671 Boolean success = (Boolean) sendRequest(
6672 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6673 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6674
6675 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6676 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
6680 }
6681
6682 /**
Miaoa84611c2019-03-15 09:21:10 +08006683 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006684 *
Miaoa84611c2019-03-15 09:21:10 +08006685 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006686 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006687 * @hide
6688 */
6689 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006690 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006693 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 try {
Miaoa84611c2019-03-15 09:21:10 +08006695 if (phone != null) {
6696 return phone.hasMatchedTetherApnSetting();
6697 } else {
6698 return false;
6699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 } finally {
6701 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006702 }
Junda Liu475951f2014-11-07 16:45:03 -08006703 }
6704
6705 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006706 * Get the user enabled state of Mobile Data.
6707 *
6708 * TODO: remove and use isUserDataEnabled.
6709 * This can't be removed now because some vendor codes
6710 * calls through ITelephony directly while they should
6711 * use TelephonyManager.
6712 *
6713 * @return true on enabled
6714 */
6715 @Override
6716 public boolean getDataEnabled(int subId) {
6717 return isUserDataEnabled(subId);
6718 }
6719
6720 /**
6721 * Get whether mobile data is enabled per user setting.
6722 *
6723 * There are other factors deciding whether mobile data is actually enabled, but they are
6724 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006725 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006726 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6727 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006728 *
6729 * @return {@code true} if data is enabled else {@code false}
6730 */
6731 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006732 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006733 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006734 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006735 try {
6736 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6737 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006738 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006739 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6740 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006741 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006742 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006743 mApp, subId, functionName);
6744
Robert Greenwalt646120a2014-05-23 11:54:03 -07006745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746
6747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 int phoneId = mSubscriptionController.getPhoneId(subId);
6750 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6751 Phone phone = PhoneFactory.getPhone(phoneId);
6752 if (phone != null) {
6753 boolean retVal = phone.isUserDataEnabled();
6754 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6755 return retVal;
6756 } else {
6757 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6758 return false;
6759 }
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006762 }
6763 }
6764
6765 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006766 * Checks if the device is capable of mobile data by considering whether whether the
6767 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6768 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006769 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006770 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006771 */
6772 @Override
6773 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006774 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006775 try {
6776 try {
6777 mApp.enforceCallingOrSelfPermission(
6778 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006779 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006780 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006781 try {
6782 mApp.enforceCallingOrSelfPermission(
6783 android.Manifest.permission.READ_PHONE_STATE,
6784 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006785 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 mApp.enforceCallingOrSelfPermission(
6787 permission.READ_BASIC_PHONE_STATE, functionName);
6788 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006789 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006790 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793
6794 final long identity = Binder.clearCallingIdentity();
6795 try {
6796 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 Phone phone = PhoneFactory.getPhone(phoneId);
6798 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006799 boolean retVal;
Jack Yuf745f972022-08-15 19:53:50 +00006800 if (phone.isUsingNewDataStack()) {
6801 retVal = phone.getDataSettingsManager().isDataEnabled();
6802 } else {
6803 retVal = phone.getDataEnabledSettings().isDataEnabled();
6804 }
Jack Yu4ad64e52021-12-03 14:23:53 -08006805 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 return retVal;
6807 } else {
6808 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6809 return false;
6810 }
6811 } finally {
6812 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006813 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006814 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006815
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006816 /**
6817 * Check if data is enabled for a specific reason
6818 * @param subId Subscription index
6819 * @param reason the reason the data enable change is taking place
6820 * @return {@code true} if the overall data is enabled; {@code false} if not.
6821 */
6822 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006823 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006825 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006826 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006827 try {
6828 mApp.enforceCallingOrSelfPermission(
6829 android.Manifest.permission.ACCESS_NETWORK_STATE,
6830 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006831 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006832 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6833 functionName);
6834 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006835 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006836 try {
6837 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006838 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006839 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006841 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006842 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006843 }
6844
6845
6846 final long identity = Binder.clearCallingIdentity();
6847 try {
6848 int phoneId = mSubscriptionController.getPhoneId(subId);
6849 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006850 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006851 + " reason=" + reason);
6852 }
6853 Phone phone = PhoneFactory.getPhone(phoneId);
6854 if (phone != null) {
6855 boolean retVal;
Jack Yuf745f972022-08-15 19:53:50 +00006856 if (phone.isUsingNewDataStack()) {
6857 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
6858 } else {
6859 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6860 retVal = phone.isUserDataEnabled();
6861 } else {
6862 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
6863 }
6864 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006866 return retVal;
6867 } else {
6868 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006869 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006870 + subId + " retVal=false");
6871 }
6872 return false;
6873 }
6874 } finally {
6875 Binder.restoreCallingIdentity(identity);
6876 }
6877 }
6878
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006879 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006880 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006881 // No permission needed; this only lets the caller inspect their own status.
6882 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006883 }
Junda Liu29340342014-07-10 15:23:27 -07006884
6885 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006886 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006887 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006888 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6889 }
6890
6891 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6892 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006894 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6896 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006897 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6898 if (cpt == null) {
6899 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6901 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006902 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006903 }
6904
6905 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006906 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006907 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006908 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006910 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006911 Phone phone = getPhone(subId);
6912 if (phone == null) {
6913 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6915 }
6916 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6917 if (cpt == null) {
6918 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6920 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006922 }
6923
6924 @Override
6925 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006926 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006927 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6928 }
6929
6930 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006931 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006933 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006934 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006935 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6936 Phone phone = PhoneFactory.getPhone(phoneId);
6937 if (phone == null) {
6938 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006939 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006940 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6941 if (cpt == null) {
6942 continue;
6943 }
6944 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006945 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6946 break;
6947 }
6948 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006949 return result;
Junda Liu29340342014-07-10 15:23:27 -07006950 }
Derek Tan89e89d42014-07-08 17:00:10 -07006951
6952 @Override
Junda Liue64de782015-04-16 17:19:16 -07006953 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006954 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006955 Phone phone = PhoneFactory.getPhone(phoneId);
6956 if (phone == null) {
6957 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006958 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006959 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6960 if (cpt == null) {
6961 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006962 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006963 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006964 }
6965
Amith Yamasani6e118872016-02-19 12:53:51 -08006966 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006967 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006968 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006969 Phone phone = PhoneFactory.getPhone(phoneId);
6970 if (phone == null) {
6971 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006972 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6974 if (cpt == null) {
6975 return Collections.emptyList();
6976 }
6977 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006978 }
6979
chen xuf7e9fe82019-05-09 19:31:02 -07006980 @Override
6981 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006982 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006983 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006984 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006985 try {
6986 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6987 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006991 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006992 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006993 }
6994
Rambo Wang6812ffb2022-03-15 16:54:17 -07006995 @Override
6996 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6997 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6998
6999 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
7000 if (phone == null) {
7001 return null;
7002 }
7003 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7004 if (cpt == null) {
7005 return null;
7006 }
7007 return cpt.getCarrierServicePackageName();
7008 }
7009
Wink Savilleb564aae2014-10-23 10:18:09 -07007010 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007011 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007012 UiccPort port = phone == null ? null : phone.getUiccPort();
7013 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007014 return null;
7015 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007016 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007017 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007018 return null;
7019 }
7020 return iccId;
7021 }
7022
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007023 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007024 public void setCallComposerStatus(int subId, int status) {
7025 enforceModifyPermission();
7026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 Phone phone = getPhone(subId);
7030 if (phone != null) {
7031 Phone defaultPhone = phone.getImsPhone();
7032 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7033 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7034 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7036 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007037 }
7038 }
Shuo Qian284ae752020-12-22 19:10:14 -08007039 } catch (ImsException e) {
7040 throw new ServiceSpecificException(e.getCode());
7041 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
7047 public int getCallComposerStatus(int subId) {
7048 enforceReadPrivilegedPermission("getCallComposerStatus");
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 Phone phone = getPhone(subId);
7053 if (phone != null) {
7054 Phone defaultPhone = phone.getImsPhone();
7055 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7056 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7057 return imsPhone.getCallComposerStatus();
7058 }
7059 }
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
7063 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7064 }
7065
7066 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007067 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7068 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007069 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007070 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 final String iccId = getIccId(subId);
7075 final Phone phone = getPhone(subId);
7076 if (phone == null) {
7077 return false;
7078 }
7079 final String subscriberId = phone.getSubscriberId();
7080
7081 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007082 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 + subscriberId + " to " + number);
7084 }
7085
7086 if (TextUtils.isEmpty(iccId)) {
7087 return false;
7088 }
7089
7090 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7091
7092 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7093 if (alphaTag == null) {
7094 editor.remove(alphaTagPrefKey);
7095 } else {
7096 editor.putString(alphaTagPrefKey, alphaTag);
7097 }
7098
7099 // Record both the line number and IMSI for this ICCID, since we need to
7100 // track all merged IMSIs based on line number
7101 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7102 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7103 if (number == null) {
7104 editor.remove(numberPrefKey);
7105 editor.remove(subscriberPrefKey);
7106 } else {
7107 editor.putString(numberPrefKey, number);
7108 editor.putString(subscriberPrefKey, subscriberId);
7109 }
7110
7111 editor.commit();
7112 return true;
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007115 }
Derek Tan7226c842014-07-02 17:42:23 -07007116 }
7117
7118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 public String getLine1NumberForDisplay(int subId, String callingPackage,
7120 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007121 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007123 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007124 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007125 return null;
7126 }
Derek Tan97ebb422014-09-05 16:55:38 -07007127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 String iccId = getIccId(subId);
7131 if (iccId != null) {
7132 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7133 if (DBG_MERGE) {
7134 log("getLine1NumberForDisplay returning "
7135 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7136 }
7137 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7140 return null;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
Derek Tan7226c842014-07-02 17:42:23 -07007144 }
7145
7146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007147 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7148 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007150 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007151 return null;
7152 }
Derek Tan97ebb422014-09-05 16:55:38 -07007153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 String iccId = getIccId(subId);
7157 if (iccId != null) {
7158 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7159 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7160 }
7161 return null;
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
Derek Tan7226c842014-07-02 17:42:23 -07007165 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007166
7167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007168 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7169 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007170 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7171 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007173 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007174 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007175 return null;
7176 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007177
Jordan Liub49b04b2019-05-06 14:45:15 -07007178 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7179 // the process, where TelephonyManager was instantiated.
7180 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007181 final long identity = Binder.clearCallingIdentity();
7182 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007183 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 final TelephonyManager tele = TelephonyManager.from(context);
7185 final SubscriptionManager sub = SubscriptionManager.from(context);
7186
7187 // Figure out what subscribers are currently active
7188 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189
Jordan Liub49b04b2019-05-06 14:45:15 -07007190 // Only consider subs which match the current subId
7191 // This logic can be simplified. See b/131189269 for progress.
7192 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007193 activeSubscriberIds.add(tele.getSubscriberId(subId));
7194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195
7196 // First pass, find a number override for an active subscriber
7197 String mergeNumber = null;
7198 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7199 for (String key : prefs.keySet()) {
7200 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7201 final String subscriberId = (String) prefs.get(key);
7202 if (activeSubscriberIds.contains(subscriberId)) {
7203 final String iccId = key.substring(
7204 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7205 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7206 mergeNumber = (String) prefs.get(numberKey);
7207 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007208 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 + " for active subscriber " + subscriberId);
7210 }
7211 if (!TextUtils.isEmpty(mergeNumber)) {
7212 break;
7213 }
7214 }
7215 }
7216 }
7217
7218 // Shortcut when no active merged subscribers
7219 if (TextUtils.isEmpty(mergeNumber)) {
7220 return null;
7221 }
7222
7223 // Second pass, find all subscribers under that line override
7224 final ArraySet<String> result = new ArraySet<>();
7225 for (String key : prefs.keySet()) {
7226 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7227 final String number = (String) prefs.get(key);
7228 if (mergeNumber.equals(number)) {
7229 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7230 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7231 final String subscriberId = (String) prefs.get(subscriberKey);
7232 if (!TextUtils.isEmpty(subscriberId)) {
7233 result.add(subscriberId);
7234 }
7235 }
7236 }
7237 }
7238
7239 final String[] resultArray = result.toArray(new String[result.size()]);
7240 Arrays.sort(resultArray);
7241 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007242 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7244 }
7245 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007249 }
7250
7251 @Override
zoey chen38003472019-12-13 17:16:31 +08007252 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7253 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 final TelephonyManager telephonyManager = mApp.getSystemService(
7258 TelephonyManager.class);
7259 String subscriberId = telephonyManager.getSubscriberId(subId);
7260 if (subscriberId == null) {
7261 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007262 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007263 + subId);
7264 }
7265 return null;
7266 }
7267
7268 final SubscriptionInfo info = SubscriptionController.getInstance()
7269 .getSubscriptionInfo(subId);
7270 final ParcelUuid groupUuid = info.getGroupUuid();
7271 // If it doesn't belong to any group, return just subscriberId of itself.
7272 if (groupUuid == null) {
7273 return new String[]{subscriberId};
7274 }
7275
7276 // Get all subscriberIds from the group.
7277 final List<String> mergedSubscriberIds = new ArrayList<>();
7278 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007279 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007280 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007281 for (SubscriptionInfo subInfo : groupInfos) {
7282 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7283 if (subscriberId != null) {
7284 mergedSubscriberIds.add(subscriberId);
7285 }
7286 }
7287
7288 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291
7292 }
7293 }
7294
7295 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007296 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007297 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007298 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299
7300 final long identity = Binder.clearCallingIdentity();
7301 try {
7302 final Phone phone = getPhone(subId);
7303 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007307 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007308
7309 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007310 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007311 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7312 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007313 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7314 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 final Phone phone = getPhone(subId);
7319 if (phone == null) {
7320 return false;
7321 }
7322 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7323 cdmaNonRoamingList);
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007326 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007327 }
7328
7329 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007330 @Deprecated
7331 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7332 enforceModifyPermission();
7333
7334 int returnValue = 0;
7335 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007336 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007337 if(result.exception == null) {
7338 if (result.result != null) {
7339 byte[] responseData = (byte[])(result.result);
7340 if(responseData.length > oemResp.length) {
7341 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7342 responseData.length + "bytes. Buffer Size is " +
7343 oemResp.length + "bytes.");
7344 }
7345 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7346 returnValue = responseData.length;
7347 }
7348 } else {
7349 CommandException ex = (CommandException) result.exception;
7350 returnValue = ex.getCommandError().ordinal();
7351 if(returnValue > 0) returnValue *= -1;
7352 }
7353 } catch (RuntimeException e) {
7354 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7355 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7356 if(returnValue > 0) returnValue *= -1;
7357 }
7358
7359 return returnValue;
7360 }
7361
7362 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007363 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007365 try {
7366 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007367 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007368 mApp, phone.getSubId(), "getRadioAccessFamily");
7369 } catch (SecurityException e) {
7370 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7371 throw e;
7372 }
chen xub97461a2018-10-26 14:17:57 -07007373 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007374 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007375 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 final long identity = Binder.clearCallingIdentity();
7378 try {
chen xub97461a2018-10-26 14:17:57 -07007379 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007380 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007381 mApp, phone.getSubId(), "getRadioAccessFamily");
7382 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
chen xub97461a2018-10-26 14:17:57 -07007386 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007387 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007388
7389 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007390 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007391 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007392 try {
7393 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7394 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007395 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007396 }
7397 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007398 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007399 }
7400 RoleManager rm = mApp.getSystemService(RoleManager.class);
7401 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7402 if (!dialerRoleHolders.contains(callingPackage)) {
7403 throw new SecurityException("App must be the dialer role holder to"
7404 + " upload a call composer pic");
7405 }
7406
7407 Executors.newSingleThreadExecutor().execute(() -> {
7408 ByteArrayOutputStream output = new ByteArrayOutputStream(
7409 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7410 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7411 boolean readUntilEnd = false;
7412 int totalBytesRead = 0;
7413 byte[] buffer = new byte[16 * 1024];
7414 while (true) {
7415 int numRead;
7416 try {
7417 numRead = input.read(buffer);
7418 } catch (IOException e) {
7419 try {
7420 fd.checkError();
7421 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7422 null);
7423 } catch (IOException e1) {
7424 // This means that the other side closed explicitly with an error. If this
7425 // happens, log and ignore.
7426 loge("Remote end of call composer picture pipe closed: " + e1);
7427 }
7428 break;
7429 }
7430 if (numRead == -1) {
7431 readUntilEnd = true;
7432 break;
7433 }
7434 totalBytesRead += numRead;
7435 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7436 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7437 try {
7438 input.close();
7439 } catch (IOException e) {
7440 // ignore
7441 }
7442 break;
7443 }
7444 output.write(buffer, 0, numRead);
7445 }
7446 // Generally, the remote end will close the file descriptors. The only case where we
7447 // close is above, where the picture size is too big.
7448
7449 try {
7450 fd.checkError();
7451 } catch (IOException e) {
7452 loge("Remote end for call composer closed with an error: " + e);
7453 return;
7454 }
7455
Hall Liuaa4211e2021-01-20 15:43:39 -08007456 if (!readUntilEnd) {
7457 loge("Did not finish reading entire image; aborting");
7458 return;
7459 }
Hall Liu82694d52020-12-11 18:22:04 -08007460
Hall Liuaa4211e2021-01-20 15:43:39 -08007461 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7462 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7463 new CallComposerPictureTransfer.Factory() {},
7464 imageData,
7465 (result) -> {
7466 if (result.first != null) {
7467 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7468 Bundle outputResult = new Bundle();
7469 outputResult.putParcelable(
7470 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7471 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7472 outputResult);
7473 } else {
7474 callback.send(result.second, null);
7475 }
7476 }
7477 );
Hall Liu82694d52020-12-11 18:22:04 -08007478 });
7479 }
7480
7481 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007482 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 ImsManager.getInstance(defaultPhone.getContext(),
7489 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007493 }
7494
7495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007496 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007497 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7499 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007500 return false;
7501 }
Svet Ganovb320e182015-04-16 12:30:10 -07007502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 // Check the user preference and the system-level IMS setting. Even if the user has
7506 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7507 // In the long run, we may instead need to check if there exists a connection service
7508 // which can support video calling.
7509 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007510 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 return imsManager.isVtEnabledByPlatform()
7512 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7513 && imsManager.isVtEnabledByUser();
7514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007517 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007518
Andrew Leea1239f22015-03-02 17:44:07 -08007519 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007520 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7521 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 mApp, subId, callingPackage, callingFeatureId,
7524 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 return false;
7526 }
7527
7528 final long identity = Binder.clearCallingIdentity();
7529 try {
7530 CarrierConfigManager configManager =
7531 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007532 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
7536 }
Andrew Leea1239f22015-03-02 17:44:07 -08007537 }
7538
7539 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007540 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007542 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 return false;
7544 }
7545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 CarrierConfigManager configManager =
7549 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007550 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Andrew Leea1239f22015-03-02 17:44:07 -08007555 }
7556
Andrew Lee9431b832015-03-09 18:46:45 -07007557 @Override
7558 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007559 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007560 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007561 }
7562
7563 @Override
7564 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 final long identity = Binder.clearCallingIdentity();
7566 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
Andrew Lee9431b832015-03-09 18:46:45 -07007571 }
7572
Hall Liuf6668912018-10-31 17:05:23 -07007573 /**
7574 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7575 * support for the feature and device firmware support.
7576 *
7577 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7578 */
7579 @Override
7580 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007582 final Phone phone = getPhone(subscriptionId);
7583 if (phone == null) {
7584 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7585 return false;
7586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7590 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007591 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 return isCarrierSupported && isDeviceSupported;
7593 } finally {
7594 Binder.restoreCallingIdentity(identity);
7595 }
Hall Liu98187582018-01-22 19:15:32 -08007596 }
7597
Hall Liuf6668912018-10-31 17:05:23 -07007598 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007599 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7600 * RTT setting, will return true if the device and carrier both support RTT.
7601 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007602 */
7603 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 final long identity = Binder.clearCallingIdentity();
7605 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007606 boolean isRttSupported = isRttSupported(subscriptionId);
7607 boolean isUserRttSettingOn = Settings.Secure.getInt(
7608 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7609 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7610 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7611 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
7614 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007615 }
7616
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007617 @Deprecated
7618 @Override
7619 public String getDeviceId(String callingPackage) {
7620 return getDeviceIdWithFeature(callingPackage, null);
7621 }
7622
Sanket Padawe7310cc72015-01-14 09:53:20 -08007623 /**
7624 * Returns the unique device ID of phone, for example, the IMEI for
7625 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7626 *
7627 * <p>Requires Permission:
7628 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7629 */
7630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007631 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007632 try {
7633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7634 } catch (SecurityException se) {
7635 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7636 throw new SecurityException("Package " + callingPackage + " does not belong to "
7637 + Binder.getCallingUid());
7638 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007639 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007640 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007641 return null;
7642 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007643 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007644 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007645 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007646 return null;
7647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648
7649 final long identity = Binder.clearCallingIdentity();
7650 try {
7651 return phone.getDeviceId();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007655 }
7656
Ping Sunc67b7c22016-03-02 19:16:45 +08007657 /**
7658 * {@hide}
7659 * Returns the IMS Registration Status on a particular subid
7660 *
7661 * @param subId
7662 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007664 Phone phone = getPhone(subId);
7665 if (phone != null) {
7666 return phone.isImsRegistered();
7667 } else {
7668 return false;
7669 }
7670 }
7671
Santos Cordon7a1885b2015-02-03 11:15:19 -08007672 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007673 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007677 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7678 }
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
7684 }
7685 }
7686
7687 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007688 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007689 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007690 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007691 mApp,
7692 subscriptionId,
7693 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subscriptionId);
7697 if (phone == null) {
7698 return null;
7699 }
7700 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7701 } finally {
7702 Binder.restoreCallingIdentity(identity);
7703 }
7704 }
7705
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007706 /**
7707 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007708 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007709 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 Phone phone = getPhone(subId);
7713 if (phone != null) {
7714 return phone.isWifiCallingEnabled();
7715 } else {
7716 return false;
7717 }
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007720 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007721 }
7722
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007724 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007725 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007726 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = getPhone(subId);
7730 if (phone != null) {
7731 return phone.isVideoEnabled();
7732 } else {
7733 return false;
7734 }
7735 } finally {
7736 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007737 }
7738 }
7739
7740 /**
7741 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7742 * defined in {@link ImsRegistrationImplBase}.
7743 */
7744 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
7747 Phone phone = getPhone(subId);
7748 if (phone != null) {
7749 return phone.getImsRegistrationTech();
7750 } else {
7751 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007755 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007756 }
7757
Stuart Scott8eef64f2015-04-08 15:13:54 -07007758 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007759 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007760 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007761 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7762 return;
7763 }
Kai Shif70f46f2021-03-03 13:59:46 -08007764 Phone defaultPhone = getDefaultPhone();
7765 if (defaultPhone != null) {
7766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7767 mApp, getDefaultPhone().getSubId(), "factoryReset");
7768 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007769 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007770
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007772 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7773 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007774 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007775 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007776 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007777 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007778 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007779 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007780 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007781 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007782 // There has been issues when Sms raw table somehow stores orphan
7783 // fragments. They lead to garbled message when new fragments come
7784 // in and combined with those stale ones. In case this happens again,
7785 // user can reset all network settings which will clean up this table.
7786 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007787 // Clean up IMS settings as well here.
7788 int slotId = getSlotIndex(subId);
7789 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7790 ImsManager.getInstance(mApp, slotId).factoryReset();
7791 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007792
Kai Shif70f46f2021-03-03 13:59:46 -08007793 if (defaultPhone == null) {
7794 return;
7795 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007796 // Erase modem config if erase modem on network setting is enabled.
7797 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7798 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7799 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007800 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007801 }
Kai Shif70f46f2021-03-03 13:59:46 -08007802
7803 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007804 } finally {
7805 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007806 }
7807 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007808
SongFerngWangfd89b102021-05-27 22:44:54 +08007809 @VisibleForTesting
7810 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7811 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7812 return;
7813 }
7814 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7815 RILConstants.PREFERRED_NETWORK_MODE);
7816 SubscriptionManager.setSubscriptionProperty(subId,
7817 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7818 "user=" + defaultNetworkType);
7819 phone.loadAllowedNetworksFromSubscriptionDatabase();
7820 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7821 defaultNetworkType, null);
7822 }
7823
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007824 private void cleanUpSmsRawTable(Context context) {
7825 ContentResolver resolver = context.getContentResolver();
7826 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7827 resolver.delete(uri, null, null);
7828 }
7829
Narayan Kamath1c496c22015-04-16 14:40:19 +01007830 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007831 public String getSimLocaleForSubscriber(int subId) {
7832 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7833 final Phone phone = getPhone(subId);
7834 if (phone == null) {
7835 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007836 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 final long identity = Binder.clearCallingIdentity();
7839 try {
chen xu5d3637b2019-01-21 23:31:38 -08007840 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007841 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007842 if (info == null) {
7843 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7844 return null;
7845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846 // Try and fetch the locale from the carrier properties or from the SIM language
7847 // preferences (EF-PL and EF-LI)...
7848 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007850 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7851 if (localeFromDefaultSim != null) {
7852 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7853 if (DBG) log("Using locale from subId: " + subId + " locale: "
7854 + localeFromDefaultSim);
7855 return localeFromDefaultSim.toLanguageTag();
7856 } else {
7857 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 }
7859 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007861 // The SIM language preferences only store a language (e.g. fr = French), not an
7862 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7863 // the SIM and carrier preferences does not include a country we add the country
7864 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007865 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007867 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 return mccLocale.toLanguageTag();
7869 }
7870
7871 if (DBG) log("No locale found - returning null");
7872 return null;
7873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007876 }
7877
7878 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007879 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007880 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007881 }
7882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883 /**
7884 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7885 */
7886 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007887 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007888 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007889 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007890
Gary Jian3aa9a762022-01-24 16:41:19 +08007891 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7892 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007893
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007894 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007895 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7896 * representing the state of the modem.
7897 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007898 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7899 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007900 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007901 */
7902 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007903 public void requestModemActivityInfo(ResultReceiver result) {
7904 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906
7907 final long identity = Binder.clearCallingIdentity();
7908 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007909 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 } finally {
7911 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007912 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007913 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007914
Siddharth Rayb8114062018-06-17 15:02:38 -07007915 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7916 // less than total activity duration.
7917 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7918 if (info == null) {
7919 return false;
7920 }
7921 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007922 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7923 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7924
Siddharth Rayb8114062018-06-17 15:02:38 -07007925 return (info.isValid()
7926 && (info.getSleepTimeMillis() <= activityDurationMs)
7927 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007928 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007929 && (totalTxTimeMs <= activityDurationMs));
7930 }
7931
Gary Jian3aa9a762022-01-24 16:41:19 +08007932 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7933 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7934 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7935 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7936
7937 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7938 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7939 }
7940
7941 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7942 mLastModemActivityInfo.setReceiveTimeMillis(
7943 rat,
7944 freq,
7945 info.getReceiveTimeMillis(rat, freq)
7946 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7947 }
7948
7949 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7950 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7951 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7952 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7953
7954 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7955 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7956 }
7957 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7958 mLastModemActivityInfo.setReceiveTimeMillis(
7959 rat,
7960 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7961 }
7962
7963 /**
7964 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7965 * @param info recent ModemActivityInfo
7966 */
7967 private void mergeModemActivityInfo(ModemActivityInfo info) {
7968 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7969 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7970 boolean matched;
7971 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7972 matched = false;
7973 int rat = info.getSpecificInfoRat(i);
7974 int freq = info.getSpecificInfoFrequencyRange(i);
7975 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7976 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7977 //if it already exists
7978 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7979 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7980 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7981 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7982 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7983 updateLastModemActivityInfo(info, rat, freq);
7984 matched = true;
7985 }
7986 } else {
7987 updateLastModemActivityInfo(info, rat);
7988 matched = true;
7989 }
7990 }
7991 }
7992
7993 if (!matched) {
7994 mDeltaSpecificInfo =
7995 new ActivityStatsTechSpecificInfo(
7996 rat,
7997 freq,
7998 info.getTransmitTimeMillis(rat, freq),
7999 (int) info.getReceiveTimeMillis(rat, freq));
8000 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8001 }
8002 }
8003 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8004 mLastModemActivitySpecificInfo =
8005 new ActivityStatsTechSpecificInfo[merged.size()];
8006 merged.toArray(mLastModemActivitySpecificInfo);
8007
8008 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8009 mLastModemActivityInfo.setSleepTimeMillis(
8010 info.getSleepTimeMillis()
8011 + mLastModemActivityInfo.getSleepTimeMillis());
8012 mLastModemActivityInfo.setIdleTimeMillis(
8013 info.getIdleTimeMillis()
8014 + mLastModemActivityInfo.getIdleTimeMillis());
8015 }
8016
Jack Yu85bd38a2015-11-09 11:34:32 -08008017 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008018 * Returns the service state information on specified subscription.
8019 */
8020 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008021 public ServiceState getServiceStateForSubscriber(int subId,
8022 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8023 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008025 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008026 return null;
8027 }
8028
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008029 boolean hasFinePermission = false;
8030 boolean hasCoarsePermission = false;
8031 if (!renounceFineLocationAccess) {
8032 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8033 LocationAccessPolicy.checkLocationPermission(mApp,
8034 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8035 .setCallingPackage(callingPackage)
8036 .setCallingFeatureId(callingFeatureId)
8037 .setCallingPid(Binder.getCallingPid())
8038 .setCallingUid(Binder.getCallingUid())
8039 .setMethod("getServiceStateForSubscriber")
8040 .setLogAsInfo(true)
8041 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8042 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8043 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8044 .build());
8045 hasFinePermission =
8046 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8047 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008048
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008049 if (!renounceCoarseLocationAccess) {
8050 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8051 LocationAccessPolicy.checkLocationPermission(mApp,
8052 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8053 .setCallingPackage(callingPackage)
8054 .setCallingFeatureId(callingFeatureId)
8055 .setCallingPid(Binder.getCallingPid())
8056 .setCallingUid(Binder.getCallingUid())
8057 .setMethod("getServiceStateForSubscriber")
8058 .setLogAsInfo(true)
8059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8060 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8061 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8062 .build());
8063 hasCoarsePermission =
8064 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8065 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008066
Jack Yu479f40e2020-10-27 21:29:25 -07008067 final Phone phone = getPhone(subId);
8068 if (phone == null) {
8069 return null;
8070 }
8071
Jordan Liu0f2bc442020-11-18 16:47:37 -08008072 final long identity = Binder.clearCallingIdentity();
8073
Jack Yu479f40e2020-10-27 21:29:25 -07008074 boolean isCallingPackageDataService = phone.getDataServicePackages()
8075 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008077 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8078 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8079 Rlog.d(LOG_TAG,
8080 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8081 return null;
8082 }
8083
Hall Liuf19c44f2018-11-27 14:38:17 -08008084 ServiceState ss = phone.getServiceState();
8085
8086 // Scrub out the location info in ServiceState depending on what level of access
8087 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008088 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008089 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8090 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 } finally {
8092 Binder.restoreCallingIdentity(identity);
8093 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008094 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008095
8096 /**
8097 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8098 *
8099 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8100 * voicemail ringtone.
8101 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8102 * PhoneAccount.
8103 */
8104 @Override
8105 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008106 final long identity = Binder.clearCallingIdentity();
8107 try {
8108 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8109 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008110 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008117 }
8118
8119 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008120 * Sets the per-account voicemail ringtone.
8121 *
8122 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8123 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8124 *
8125 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8126 * voicemail ringtone.
8127 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8128 * PhoneAccount.
8129 */
8130 @Override
8131 public void setVoicemailRingtoneUri(String callingPackage,
8132 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008133 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008134 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008135 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8136 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8138 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8139 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141
8142 final long identity = Binder.clearCallingIdentity();
8143 try {
8144 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8145 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008146 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147 }
8148 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8149 } finally {
8150 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008151 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008152 }
8153
8154 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008155 * Returns whether vibration is set for voicemail notification in Phone settings.
8156 *
8157 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8158 * voicemail vibration setting.
8159 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8160 */
8161 @Override
8162 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8166 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008167 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008174 }
8175
Youhan Wange64578a2016-05-02 15:32:42 -07008176 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008177 * Sets the per-account voicemail vibration.
8178 *
8179 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8180 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8181 *
8182 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8183 * voicemail vibration setting.
8184 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8185 * specific PhoneAccount.
8186 */
8187 @Override
8188 public void setVoicemailVibrationEnabled(String callingPackage,
8189 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008190 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008191 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008192 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8193 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8195 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8196 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008197 }
8198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008199 final long identity = Binder.clearCallingIdentity();
8200 try {
8201 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8202 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 }
8205 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8206 } finally {
8207 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008208 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008209 }
8210
8211 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008212 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8213 *
8214 * @throws SecurityException if the caller does not have the required permission
8215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008216 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008217 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008218 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008219 }
8220
8221 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008222 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8223 * permission.
8224 *
8225 * @throws SecurityException if the caller does not have the required permission
8226 */
8227 private void enforceSendSmsPermission() {
8228 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8229 }
8230
8231 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008232 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008233 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008234 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008235 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008236 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008240 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 if (componentName == null) {
8242 throw new SecurityException(
8243 "Caller not current active visual voicemail package[null]");
8244 }
8245 String vvmPackage = componentName.getPackageName();
8246 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008247 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 }
8249 } finally {
8250 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008251 }
8252 }
8253
8254 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008255 * Return the application ID for the app type.
8256 *
8257 * @param subId the subscription ID that this request applies to.
8258 * @param appType the uicc app type.
8259 * @return Application ID for specificied app type, or null if no uicc.
8260 */
8261 @Override
8262 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008263 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008264 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008267 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 if (phone == null) {
8269 return null;
8270 }
8271 String aid = null;
8272 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008273 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 .getApplicationByType(appType).getAid();
8275 } catch (Exception e) {
8276 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8277 }
8278 return aid;
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008281 }
Youhan Wange64578a2016-05-02 15:32:42 -07008282 }
8283
Youhan Wang4001d252016-05-11 10:29:41 -07008284 /**
8285 * Return the Electronic Serial Number.
8286 *
8287 * @param subId the subscription ID that this request applies to.
8288 * @return ESN or null if error.
8289 */
8290 @Override
8291 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008292 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008293 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294
8295 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008296 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 if (phone == null) {
8298 return null;
8299 }
8300 String esn = null;
8301 try {
8302 esn = phone.getEsn();
8303 } catch (Exception e) {
8304 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8305 }
8306 return esn;
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008309 }
Youhan Wang4001d252016-05-11 10:29:41 -07008310 }
8311
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008312 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008313 * Return the Preferred Roaming List Version.
8314 *
8315 * @param subId the subscription ID that this request applies to.
8316 * @return PRLVersion or null if error.
8317 */
8318 @Override
8319 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008320 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008321 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322
8323 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008324 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 if (phone == null) {
8326 return null;
8327 }
8328 String cdmaPrlVersion = null;
8329 try {
8330 cdmaPrlVersion = phone.getCdmaPrlVersion();
8331 } catch (Exception e) {
8332 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8333 }
8334 return cdmaPrlVersion;
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008337 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008338 }
8339
8340 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008341 * Get snapshot of Telephony histograms
8342 * @return List of Telephony histograms
8343 * @hide
8344 */
8345 @Override
8346 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8348 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008349
8350 final long identity = Binder.clearCallingIdentity();
8351 try {
8352 return RIL.getTelephonyRILTimingHistograms();
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008356 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008357
8358 /**
8359 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008360 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8361 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008362 * Require system privileges. In the future we may add this to carrier APIs.
8363 *
Michele Berionne482f8202018-11-27 18:57:59 -08008364 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008365 */
8366 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008367 @TelephonyManager.SetCarrierRestrictionResult
8368 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008369 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008371
Michele Berionne482f8202018-11-27 18:57:59 -08008372 if (carrierRestrictionRules == null) {
8373 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008374 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 final long identity = Binder.clearCallingIdentity();
8377 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008378 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008379 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008383 }
8384
8385 /**
8386 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008387 * Get the allowed carrier list and the excluded carrier list, including the priority between
8388 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008389 * Require system privileges. In the future we may add this to carrier APIs.
8390 *
Michele Berionne482f8202018-11-27 18:57:59 -08008391 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008392 */
8393 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008394 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008395 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008396 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008397
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008400 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8401 if (response instanceof CarrierRestrictionRules) {
8402 return (CarrierRestrictionRules) response;
8403 }
8404 // Response is an Exception of some kind,
8405 // which is signalled to the user as a NULL retval
8406 return null;
8407 } catch (Exception e) {
8408 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8409 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410 } finally {
8411 Binder.restoreCallingIdentity(identity);
8412 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008413 }
8414
fionaxu59545b42016-05-25 15:53:37 -07008415 /**
fionaxu59545b42016-05-25 15:53:37 -07008416 * Action set from carrier signalling broadcast receivers to enable/disable radio
8417 * @param subId the subscription ID that this action applies to.
8418 * @param enabled control enable or disable radio.
8419 * {@hide}
8420 */
8421 @Override
8422 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8423 enforceModifyPermission();
8424 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008425
8426 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008427 if (phone == null) {
8428 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8429 return;
8430 }
8431 try {
8432 phone.carrierActionSetRadioEnabled(enabled);
8433 } catch (Exception e) {
8434 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008435 } finally {
8436 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008437 }
8438 }
8439
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008440 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008441 * Enable or disable Voice over NR (VoNR)
8442 * @param subId the subscription ID that this action applies to.
8443 * @param enabled enable or disable VoNR.
8444 * @return operation result.
8445 */
8446 @Override
8447 public int setVoNrEnabled(int subId, boolean enabled) {
8448 enforceModifyPermission();
8449 final Phone phone = getPhone(subId);
8450
8451 final long identity = Binder.clearCallingIdentity();
8452 if (phone == null) {
8453 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8454 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8455 }
8456
8457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8458 try {
8459 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8460 workSource);
8461 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008462
8463 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8464 if (DBG) {
8465 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8466 }
8467 SubscriptionManager.setSubscriptionProperty(
8468 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8469 (enabled ? "1" : "0"));
8470 }
8471
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008472 return result;
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
8477
8478 /**
8479 * Is voice over NR enabled
8480 * @return true if VoNR is enabled else false
8481 */
8482 @Override
8483 public boolean isVoNrEnabled(int subId) {
8484 enforceReadPrivilegedPermission("isVoNrEnabled");
8485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8489 null, subId, workSource);
8490 if (DBG) log("isVoNrEnabled: " + isEnabled);
8491 return isEnabled;
8492 } finally {
8493 Binder.restoreCallingIdentity(identity);
8494 }
8495 }
8496
8497 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008498 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8499 * network status based on which carrier apps could apply actions accordingly,
8500 * enable/disable default url handler for example.
8501 *
8502 * @param subId the subscription ID that this action applies to.
8503 * @param report control start/stop reporting the default network status.
8504 * {@hide}
8505 */
8506 @Override
8507 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8508 enforceModifyPermission();
8509 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008510
8511 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008512 if (phone == null) {
8513 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8514 return;
8515 }
8516 try {
8517 phone.carrierActionReportDefaultNetworkStatus(report);
8518 } catch (Exception e) {
8519 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 } finally {
8521 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008522 }
8523 }
8524
8525 /**
fionaxud9622282017-07-17 17:51:30 -07008526 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8527 * @param subId the subscription ID that this action applies to.
8528 * {@hide}
8529 */
8530 @Override
8531 public void carrierActionResetAll(int subId) {
8532 enforceModifyPermission();
8533 final Phone phone = getPhone(subId);
8534 if (phone == null) {
8535 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8536 return;
8537 }
8538 try {
8539 phone.carrierActionResetAll();
8540 } catch (Exception e) {
8541 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8542 }
8543 }
8544
8545 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008546 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8547 * bug report is being generated.
8548 */
8549 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008550 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008551 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8552 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008553 writer.println("Permission Denial: can't dump Phone from pid="
8554 + Binder.getCallingPid()
8555 + ", uid=" + Binder.getCallingUid()
8556 + "without permission "
8557 + android.Manifest.permission.DUMP);
8558 return;
8559 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008560 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008561 }
Jack Yueb89b242016-06-22 13:27:47 -07008562
Brad Ebingerdac2f002018-04-03 15:17:52 -07008563 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008564 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8565 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8566 @NonNull String[] args) {
8567 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8568 this, in.getFileDescriptor(), out.getFileDescriptor(),
8569 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008570 }
8571
Jack Yueb89b242016-06-22 13:27:47 -07008572 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008573 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008574 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008575 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008576 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008577 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008578 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008579 */
8580 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008581 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008582 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008583 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8584 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8585 try {
8586 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008587 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008588 } catch (SecurityException se) {
8589 enforceModifyPermission();
8590 }
8591 } else {
8592 enforceModifyPermission();
8593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
8597 Phone phone = getPhone(subId);
8598 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008599 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8600 phone.carrierActionSetMeteredApnsEnabled(enabled);
8601 } else {
Jack Yuf745f972022-08-15 19:53:50 +00008602 if (phone.isUsingNewDataStack()) {
8603 phone.getDataSettingsManager().setDataEnabled(
8604 reason, enabled, callingPackage);
8605 } else {
8606 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8607 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008608 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008609 }
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008612 }
8613 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008614
8615 /**
8616 * Get Client request stats
8617 * @return List of Client Request Stats
8618 * @hide
8619 */
8620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8622 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008624 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008625 return null;
8626 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008627 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 if (phone != null) {
8632 return phone.getClientRequestStats();
8633 }
8634
8635 return null;
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008639 }
8640
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008641 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008642 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008643 if (uid == Process.ROOT_UID && packageName == null) {
8644 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8645 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8646 // exception. ROOT_UID seems not to have a valid package name returned by
8647 // PackageManager, so just fake it here to avoid issues when running telephony shell
8648 // commands that plumb through the RIL as root, like so:
8649 // $ adb root
8650 // $ adb shell cmd phone ...
8651 packageName = "root";
8652 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008653 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008654 }
Jack Yueb4124c2017-02-16 15:32:43 -08008655
8656 /**
Grace Chen70990072017-03-24 17:21:30 -07008657 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008658 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008659 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008660 * @param state State of SIM (power down, power up, pass through)
8661 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8662 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8663 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008664 *
8665 **/
8666 @Override
Grace Chen70990072017-03-24 17:21:30 -07008667 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008668 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008669 Phone phone = PhoneFactory.getPhone(slotIndex);
8670
vagdeviaf9a5b92018-08-15 16:01:53 -07008671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008676 phone.setSimPowerState(state, null, workSource);
8677 }
8678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
8681 }
8682
8683 /**
8684 * Set SIM card power state.
8685 *
8686 * @param slotIndex SIM slot id.
8687 * @param state State of SIM (power down, power up, pass through)
8688 * @param callback callback to trigger after success or failure
8689 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8690 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8691 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8692 *
8693 **/
8694 @Override
8695 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8696 IIntegerConsumer callback) {
8697 enforceModifyPermission();
8698 Phone phone = PhoneFactory.getPhone(slotIndex);
8699
8700 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8701
8702 final long identity = Binder.clearCallingIdentity();
8703 try {
8704 if (phone != null) {
8705 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8706 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008707 }
8708 } finally {
8709 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008710 }
8711 }
Shuo Qiandd210312017-04-12 22:11:33 +00008712
Tyler Gunn65d45c22017-06-05 11:22:26 -07008713 private boolean isUssdApiAllowed(int subId) {
8714 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008715 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008716 if (configManager == null) {
8717 return false;
8718 }
8719 PersistableBundle pb = configManager.getConfigForSubId(subId);
8720 if (pb == null) {
8721 return false;
8722 }
8723 return pb.getBoolean(
8724 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8725 }
8726
Shuo Qiandd210312017-04-12 22:11:33 +00008727 /**
8728 * Check if phone is in emergency callback mode
8729 * @return true if phone is in emergency callback mode
8730 * @param subId sub id
8731 */
goneil9c5f4872017-12-05 14:07:56 -08008732 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008733 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008734 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
8739 if (phone != null) {
8740 return phone.isInEcm();
8741 } else {
8742 return false;
8743 }
8744 } finally {
8745 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008746 }
8747 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008748
8749 /**
8750 * Get the current signal strength information for the given subscription.
8751 * Because this information is not updated when the device is in a low power state
8752 * it should not be relied-upon to be current.
8753 * @param subId Subscription index
8754 * @return the most recent cached signal strength info from the modem
8755 */
8756 @Override
8757 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 Phone p = getPhone(subId);
8761 if (p == null) {
8762 return null;
8763 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 return p.getSignalStrength();
8766 } finally {
8767 Binder.restoreCallingIdentity(identity);
8768 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008769 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008770
Pengquan Meng77b7f132018-08-22 14:49:57 -07008771 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008772 * Get the current modem radio state for the given slot.
8773 * @param slotIndex slot index.
8774 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008775 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008776 * @return the current radio power state from the modem
8777 */
8778 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008779 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008780 Phone phone = PhoneFactory.getPhone(slotIndex);
8781 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8783 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008784 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8785 }
8786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 return phone.getRadioPowerState();
8790 } finally {
8791 Binder.restoreCallingIdentity(identity);
8792 }
8793 }
8794 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8795 }
8796
8797 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008798 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8799 *
8800 * <p>Requires one of the following permissions:
8801 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008802 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008803 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8804 * privileges.
8805 *
8806 * @param subId subscription id
8807 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8808 * {@code false}.
8809 */
8810 @Override
8811 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008812 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008813 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008814 try {
8815 mApp.enforceCallingOrSelfPermission(
8816 android.Manifest.permission.ACCESS_NETWORK_STATE,
8817 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008818 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008819 mApp.enforceCallingOrSelfPermission(
8820 permission.READ_BASIC_PHONE_STATE, functionName);
8821 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008822 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008823 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008824 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008825 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008826
Pengquan Menga1bb6272018-09-06 09:59:22 -07008827 boolean isEnabled = false;
8828 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008829 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008830 Phone phone = getPhone(subId);
8831 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008832 } finally {
8833 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008834 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008835 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008836 }
8837
8838
8839 /**
8840 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8841 *
8842 * <p> Requires permission:
8843 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8844 * privileges.
8845 *
8846 * @param subId subscription id
8847 * @param isEnabled {@code true} means enable, {@code false} means disable.
8848 */
8849 @Override
8850 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8852 mApp, subId, "setDataRoamingEnabled");
8853
Pengquan Menga1bb6272018-09-06 09:59:22 -07008854 final long identity = Binder.clearCallingIdentity();
8855 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008856 Phone phone = getPhone(subId);
8857 if (phone != null) {
8858 phone.setDataRoamingEnabled(isEnabled);
8859 }
8860 } finally {
8861 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008862 }
8863 }
8864
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008865 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008866 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008867 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008868 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008869 mApp, subId, "isManualNetworkSelectionAllowed");
8870
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008871 boolean isAllowed = true;
8872 final long identity = Binder.clearCallingIdentity();
8873 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008874 Phone phone = getPhone(subId);
8875 if (phone != null) {
8876 isAllowed = phone.isCspPlmnEnabled();
8877 }
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
8881 return isAllowed;
8882 }
8883
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008884 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8885 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008886 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008887 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008888 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008889 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8890 if (phone == null) {
8891 return false;
8892 }
8893 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8894 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8895 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008896 }
8897
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008898 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008899 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008900 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008901 mApp.getSystemService(AppOpsManager.class)
8902 .checkPackage(Binder.getCallingUid(), callingPackage);
8903
Jordan Liu1e142fc2019-04-22 15:10:43 -07008904 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008905 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008906 try {
8907 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008908 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008909 } catch (SecurityException e) {
8910 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8911 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008912 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008913 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008914 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008915 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008916 }
sandeepjsb6c87872021-09-27 15:34:44 +00008917 // checking compatibility, if calling app's target SDK is T and beyond.
8918 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8919 Binder.getCallingUid())) {
8920 isIccIdAccessRestricted = true;
8921 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008922 final long identity = Binder.clearCallingIdentity();
8923 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008924 UiccController uiccController = UiccController.getInstance();
8925 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008926 if (hasReadPermission) {
8927 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008928 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008929
8930 // Remove private info if the caller doesn't have access
8931 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8932 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008933 //setting the value after compatibility check
8934 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008935 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8936 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008937 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008938 if (card == null) {
8939 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008940 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008941 continue;
8942 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008943 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8944 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008945 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008946 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008947 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008948 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8949 for (UiccPortInfo portInfo : portInfos) {
8950 UiccPort port = uiccController.getUiccPortForSlot(
8951 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8952 if (port == null) {
8953 // assume no access if port is null
8954 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8955 continue;
8956 }
8957 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8958 uiccPortInfos.add(portInfo);
8959 } else {
8960 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8961 }
8962 }
8963 filteredInfos.add(new UiccCardInfo(
8964 cardInfo.isEuicc(),
8965 cardInfo.getCardId(),
8966 null,
8967 cardInfo.getPhysicalSlotIndex(),
8968 cardInfo.isRemovable(),
8969 cardInfo.isMultipleEnabledProfilesSupported(),
8970 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008971 }
8972 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 }
8977
sandeepjsb6c87872021-09-27 15:34:44 +00008978 /**
8979 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8980 * generally private and require carrier privileges to view.
8981 *
8982 * @hide
8983 */
8984 @NonNull
8985 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8986 List<UiccPortInfo> portinfo = new ArrayList<>();
8987 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8988 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8989 }
8990 return new UiccCardInfo(
8991 cardInfo.isEuicc(),
8992 cardInfo.getCardId(),
8993 null,
8994 cardInfo.getPhysicalSlotIndex(),
8995 cardInfo.isRemovable(),
8996 cardInfo.isMultipleEnabledProfilesSupported(),
8997 portinfo
8998 );
8999 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009000
sandeepjsb6c87872021-09-27 15:34:44 +00009001 /**
9002 * @hide
9003 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9004 * These values are generally private and require carrier privileges to view.
9005 */
9006 @NonNull
9007 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9008 return new UiccPortInfo(
9009 UiccPortInfo.ICCID_REDACTED,
9010 portInfo.getPortIndex(),
9011 portInfo.getLogicalSlotIndex(),
9012 portInfo.isActive()
9013 );
9014 }
9015 @Override
9016 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009017 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009018 mApp.getSystemService(AppOpsManager.class)
9019 .checkPackage(Binder.getCallingUid(), callingPackage);
9020
sandeepjsb6c87872021-09-27 15:34:44 +00009021 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009022
Aman Guptaf3c90b32022-03-17 04:54:16 +00009023 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9024 // we are reading iccId which is PII data.
9025 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009026
9027 // checking compatibility, if calling app's target SDK is T and beyond.
9028 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9029 Binder.getCallingUid())) {
9030 isLogicalSlotAccessRestricted = true;
9031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009032 final long identity = Binder.clearCallingIdentity();
9033 try {
9034 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009035 if (slots == null || slots.length == 0) {
9036 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009037 return null;
9038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9040 for (int i = 0; i < slots.length; i++) {
9041 UiccSlot slot = slots[i];
9042 if (slot == null) {
9043 continue;
9044 }
9045
Jordan Liu7be7e652019-05-06 18:55:02 +00009046 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 UiccCard card = slot.getUiccCard();
9048 if (card != null) {
9049 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009050 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009051 cardId = slot.getEid();
9052 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009053 // If cardId is null, use iccId of default port as cardId.
9054 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009056 }
9057
Jordan Liu857451f2019-05-09 16:35:35 -07009058 if (cardId != null) {
9059 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9060 // if cardId is an EID, it's all digits so this is fine
9061 cardId = IccUtils.stripTrailingFs(cardId);
9062 }
9063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009064 int cardState = 0;
9065 switch (slot.getCardState()) {
9066 case CARDSTATE_ABSENT:
9067 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9068 break;
9069 case CARDSTATE_PRESENT:
9070 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9071 break;
9072 case CARDSTATE_ERROR:
9073 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9074 break;
9075 case CARDSTATE_RESTRICTED:
9076 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9077 break;
9078 default:
9079 break;
9080
9081 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009082 List<UiccPortInfo> portInfos = new ArrayList<>();
9083 int[] portIndexes = slot.getPortList();
9084 for (int portIdx : portIndexes) {
9085 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009086 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009087 portInfos.add(new UiccPortInfo(iccId, portIdx,
9088 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009090 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 slot.isEuicc(),
9092 cardId,
9093 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009094 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009095 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009096 //setting the value after compatibility check
9097 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 }
9099 return infos;
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009102 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009103 }
9104
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009105 /* Returns null if doesn't have read permission or carrier privilege access. */
9106 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9107 boolean hasReadPermission) {
9108 String iccId = slot.getIccId(portIndex);
9109 if (hasReadPermission) { // if has read permission
9110 return iccId;
9111 } else {
9112 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9113 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9114 // if no read permission, checking carrier privilege access
9115 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9116 return iccId;
9117 }
9118 }
9119 }
9120 // No read permission or carrier privilege access.
9121 return UiccPortInfo.ICCID_REDACTED;
9122 }
9123
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009124 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009125 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009126 public boolean switchSlots(int[] physicalSlots) {
9127 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009128
9129 final long identity = Binder.clearCallingIdentity();
9130 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009131 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9132 for (int i = 0; i < physicalSlots.length; i++) {
9133 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9134 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9135 physicalSlots[i], i));
9136 }
9137 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009141 }
Jack Yu4c988042018-02-27 15:30:01 -08009142
9143 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009144 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9145 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9146 enforceModifyPermission();
9147
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009150 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009151 } finally {
9152 Binder.restoreCallingIdentity(identity);
9153 }
9154 }
9155
9156 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009157 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 return UiccController.getInstance().getCardIdForDefaultEuicc();
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
Pengquan Meng85728fb2018-03-12 16:31:21 -07009166 /**
goneil47ffb6e2018-04-06 15:40:58 -07009167 * A test API to reload the UICC profile.
9168 *
9169 * <p>Requires that the calling app has permission
9170 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9171 * @hide
9172 */
9173 @Override
9174 public void refreshUiccProfile(int subId) {
9175 enforceModifyPermission();
9176
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 Phone phone = getPhone(subId);
9180 if (phone == null) {
9181 return;
9182 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009183 UiccPort uiccPort = phone.getUiccPort();
9184 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009185 return;
9186 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009187 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009188 if (uiccProfile == null) {
9189 return;
9190 }
9191 uiccProfile.refresh();
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
9194 }
9195 }
9196
9197 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009198 * Returns false if the mobile data is disabled by default, otherwise return true.
9199 */
9200 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009201 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009202 }
9203
9204 /**
9205 * Returns true if the data roaming is enabled by default, i.e the system property
9206 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9207 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9208 */
9209 private boolean getDefaultDataRoamingEnabled(int subId) {
9210 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009211 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009212 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009213 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9214 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9215 return isDataRoamingEnabled;
9216 }
9217
9218 /**
9219 * Returns the default network type for the given {@code subId}, if the default network type is
9220 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9221 */
9222 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009223 List<Integer> list = TelephonyProperties.default_network();
9224 int phoneId = mSubscriptionController.getPhoneId(subId);
9225 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9226 return list.get(phoneId);
9227 }
9228 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009229 }
fionaxua13278b2018-03-21 00:08:13 -07009230
9231 @Override
9232 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009233 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009234 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009235
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 final Phone phone = getPhone(subId);
9239 if (phone == null) {
9240 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9241 return;
9242 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009243 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9244 if (cpt != null) {
9245 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9246 }
9247 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009248 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9249 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009250 if (carrierPrivilegeRules == null) {
9251 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9252 } else {
9253 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009255 } finally {
9256 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009257 }
fionaxua13278b2018-03-21 00:08:13 -07009258 }
9259
9260 @Override
9261 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009262 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009263
9264 final long identity = Binder.clearCallingIdentity();
9265 try {
9266 final Phone phone = getPhone(subId);
9267 if (phone == null) {
9268 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9269 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9270 }
9271 return phone.getCarrierIdListVersion();
9272 } finally {
9273 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009274 }
fionaxua13278b2018-03-21 00:08:13 -07009275 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009276
9277 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009278 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9279 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009281 mApp, subId, callingPackage, callingFeatureId,
9282 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009283 return -1;
9284 }
9285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9289 } finally {
9290 Binder.restoreCallingIdentity(identity);
9291 }
9292 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009293
9294 @Override
9295 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009296 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009297 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009298 mApp, subId, "getCdmaRoamingMode");
9299
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9303 } finally {
9304 Binder.restoreCallingIdentity(identity);
9305 }
9306 }
9307
9308 @Override
9309 public boolean setCdmaRoamingMode(int subId, int mode) {
9310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9311 mApp, subId, "setCdmaRoamingMode");
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
9318 }
9319 }
9320
9321 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009322 public int getCdmaSubscriptionMode(int subId) {
9323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009325 mApp, subId, "getCdmaSubscriptionMode");
9326
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
9334
9335 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009336 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9338 mApp, subId, "setCdmaSubscriptionMode");
9339
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009347
sqianc5eccab2018-10-19 18:46:41 -07009348 @Override
sqian8c685422019-02-22 15:55:18 -08009349 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009350 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009352 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9353 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009354 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9355 }
9356 final long identity = Binder.clearCallingIdentity();
9357 try {
sqian854d44b2018-12-12 16:48:18 -08009358 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9359 for (Phone phone: PhoneFactory.getPhones()) {
9360 if (phone.getEmergencyNumberTracker() != null
9361 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9362 emergencyNumberListInternal.put(
9363 phone.getSubId(),
9364 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9365 }
sqian11b7a0e2018-12-05 18:48:28 -08009366 }
sqian854d44b2018-12-12 16:48:18 -08009367 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009368 } finally {
9369 Binder.restoreCallingIdentity(identity);
9370 }
sqianc5eccab2018-10-19 18:46:41 -07009371 }
9372
9373 @Override
sqian8c685422019-02-22 15:55:18 -08009374 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009375 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009376 if (!exactMatch) {
9377 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009378 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009379 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009380 }
9381 final long identity = Binder.clearCallingIdentity();
9382 try {
sqian854d44b2018-12-12 16:48:18 -08009383 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009384 //Note: we ignore passed in param exactMatch. We can remove it once
9385 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009386 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009387 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009388 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009389 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009390 }
sqian11b7a0e2018-12-05 18:48:28 -08009391 }
9392 return false;
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396 }
9397
sqianf4ca7ed2019-01-15 18:32:07 -08009398 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009399 * Start emergency callback mode for GsmCdmaPhone for testing.
9400 */
9401 @Override
9402 public void startEmergencyCallbackMode() {
9403 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9404 "startEmergencyCallbackMode");
9405 enforceModifyPermission();
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
9408 for (Phone phone : PhoneFactory.getPhones()) {
9409 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9410 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9411 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9412 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9413 gsmCdmaPhone.obtainMessage(
9414 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9415 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9416 }
9417 }
9418 } finally {
9419 Binder.restoreCallingIdentity(identity);
9420 }
9421 }
9422
9423 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009424 * Update emergency number list for test mode.
9425 */
9426 @Override
9427 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9429 "updateEmergencyNumberListTestMode");
9430
9431 final long identity = Binder.clearCallingIdentity();
9432 try {
9433 for (Phone phone: PhoneFactory.getPhones()) {
9434 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9435 if (tracker != null) {
9436 tracker.executeEmergencyNumberTestModeCommand(action, num);
9437 }
9438 }
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
9443
9444 /**
9445 * Get the full emergency number list for test mode.
9446 */
9447 @Override
9448 public List<String> getEmergencyNumberListTestMode() {
9449 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9450 "getEmergencyNumberListTestMode");
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
9454 Set<String> emergencyNumbers = new HashSet<>();
9455 for (Phone phone: PhoneFactory.getPhones()) {
9456 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9457 if (tracker != null) {
9458 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9459 emergencyNumbers.add(num.getNumber());
9460 }
9461 }
9462 }
9463 return new ArrayList<>(emergencyNumbers);
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
9468
chen xud6b45bd2018-10-30 22:27:10 -07009469 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009470 public int getEmergencyNumberDbVersion(int subId) {
9471 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9472
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 final Phone phone = getPhone(subId);
9476 if (phone == null) {
9477 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9478 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9479 }
9480 return phone.getEmergencyNumberDbVersion();
9481 } finally {
9482 Binder.restoreCallingIdentity(identity);
9483 }
9484 }
9485
9486 @Override
9487 public void notifyOtaEmergencyNumberDbInstalled() {
9488 enforceModifyPermission();
9489
9490 final long identity = Binder.clearCallingIdentity();
9491 try {
9492 for (Phone phone: PhoneFactory.getPhones()) {
9493 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9494 if (tracker != null) {
9495 tracker.updateOtaEmergencyNumberDatabase();
9496 }
9497 }
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
9500 }
9501 }
9502
9503 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009504 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009505 enforceActiveEmergencySessionPermission();
9506
9507 final long identity = Binder.clearCallingIdentity();
9508 try {
9509 for (Phone phone: PhoneFactory.getPhones()) {
9510 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9511 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009512 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9513 }
9514 }
9515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
9518 }
9519
9520 @Override
9521 public void resetOtaEmergencyNumberDbFilePath() {
9522 enforceActiveEmergencySessionPermission();
9523
9524 final long identity = Binder.clearCallingIdentity();
9525 try {
9526 for (Phone phone: PhoneFactory.getPhones()) {
9527 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9528 if (tracker != null) {
9529 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009530 }
9531 }
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009538 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9539 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9540 Phone phone = getPhone(subId);
9541 if (phone == null) {
9542 return null;
9543 }
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 UiccProfile profile = UiccController.getInstance()
9547 .getUiccProfileForPhone(phone.getPhoneId());
9548 if (profile != null) {
9549 return profile.getCertsFromCarrierPrivilegeAccessRules();
9550 }
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 return null;
9555 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009556
9557 /**
9558 * Enable or disable a modem stack.
9559 */
9560 @Override
9561 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9562 enforceModifyPermission();
9563
9564 final long identity = Binder.clearCallingIdentity();
9565 try {
9566 Phone phone = PhoneFactory.getPhone(slotIndex);
9567 if (phone == null) {
9568 return false;
9569 } else {
9570 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9571 }
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
Michelecea4cf22018-12-21 15:00:11 -08009576
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009577 /**
9578 * Whether a modem stack is enabled or not.
9579 */
9580 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009581 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9582 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009583 Phone phone = PhoneFactory.getPhone(slotIndex);
9584 if (phone == null) return false;
9585
9586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009587 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9588 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009589 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9590 }
9591
9592 final long identity = Binder.clearCallingIdentity();
9593 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009594 try {
9595 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9596 } catch (NoSuchElementException ex) {
9597 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9598 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009599 } finally {
9600 Binder.restoreCallingIdentity(identity);
9601 }
9602 }
9603
Michelecea4cf22018-12-21 15:00:11 -08009604 @Override
Michele0ea7d782019-03-19 14:58:42 -07009605 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009606 enforceModifyPermission();
9607
9608 final long identity = Binder.clearCallingIdentity();
9609 try {
9610 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009611 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009612 .commit();
9613 } finally {
9614 Binder.restoreCallingIdentity(identity);
9615 }
9616 }
9617
9618 @Override
Michele0ea7d782019-03-19 14:58:42 -07009619 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009620 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009622 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9623 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009624 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009625 }
Michelecea4cf22018-12-21 15:00:11 -08009626
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
Michele0ea7d782019-03-19 14:58:42 -07009629 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009630 } finally {
9631 Binder.restoreCallingIdentity(identity);
9632 }
9633 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009634
Michele0ea7d782019-03-19 14:58:42 -07009635 @TelephonyManager.IsMultiSimSupportedResult
9636 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009637 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9638 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9639 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009640 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9641 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009642 }
9643 // Check if the hardware supports multisim functionality. If usage of multisim is not
9644 // supported by the modem, indicate that it is restricted.
9645 PhoneCapability staticCapability =
9646 mPhoneConfigurationManager.getStaticPhoneCapability();
9647 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009648 loge("isMultiSimSupportedInternal: no static configuration available");
9649 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009650 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009651 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009652 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9653 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009654 }
9655 // Check if support of multiple SIMs is restricted by carrier
9656 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009657 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009658 }
9659
Michele0ea7d782019-03-19 14:58:42 -07009660 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009661 }
9662
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009663 /**
9664 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009665 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9666 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9667 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009668 * @param numOfSims number of active sims we want to switch to
9669 */
9670 @Override
9671 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009672 if (numOfSims == 1) {
9673 enforceModifyPermission();
9674 } else {
9675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9676 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9677 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009678 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009679
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009680 try {
Michele30b57b22019-03-01 12:01:14 -08009681 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009682 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009683 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9684 return;
9685 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009686 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009692 @Override
9693 public boolean isApplicationOnUicc(int subId, int appType) {
9694 enforceReadPrivilegedPermission("isApplicationOnUicc");
9695 Phone phone = getPhone(subId);
9696 if (phone == null) {
9697 return false;
9698 }
9699 final long identity = Binder.clearCallingIdentity();
9700 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009701 UiccPort uiccPort = phone.getUiccPort();
9702 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009703 return false;
9704 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009705 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009706 if (uiccProfile == null) {
9707 return false;
9708 }
9709 if (TelephonyManager.APPTYPE_SIM <= appType
9710 && appType <= TelephonyManager.APPTYPE_ISIM) {
9711 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9712 }
9713 return false;
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
9718
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009719 /**
chen xub4baa772019-04-03 10:23:41 -07009720 * Get whether making changes to modem configurations will trigger reboot.
9721 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009722 */
9723 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009724 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9725 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009727 mApp, subId, callingPackage, callingFeatureId,
9728 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009729 return false;
9730 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009731 final long identity = Binder.clearCallingIdentity();
9732 try {
9733 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9734 } finally {
9735 Binder.restoreCallingIdentity(identity);
9736 }
9737 }
9738
Nathan Harold29f5f052019-02-15 13:41:57 -08009739 private void updateModemStateMetrics() {
9740 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9741 // TODO: check the state for each modem if the api is ready.
9742 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9743 }
9744
Pengquan Meng3889a572019-01-23 11:16:29 -08009745 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009746 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009747 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009748 // Verify that the callingPackage belongs to the calling UID
9749 mApp.getSystemService(AppOpsManager.class)
9750 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009751 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009752 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009753 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009754 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9755 if (slotInfos != null) {
9756 for (int i = 0; i < slotInfos.length; i++) {
9757 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9758 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9759 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9760 portInfo.getLogicalSlotIndex()));
9761 }
9762 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009763 }
9764 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009765 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009770
9771 /**
9772 * Get the IRadio HAL Version
9773 */
9774 @Override
9775 public int getRadioHalVersion() {
9776 Phone phone = getDefaultPhone();
9777 if (phone == null) return -1;
9778 HalVersion hv = phone.getHalVersion();
9779 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9780 return hv.major * 100 + hv.minor;
9781 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009782
9783 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009784 * Get the current calling package name.
9785 * @return the current calling package name
9786 */
9787 @Override
9788 public String getCurrentPackageName() {
9789 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9790 }
9791
9792 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009793 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9794 * corresponding network requests on a subId.
9795 *
9796 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009797 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009798 * 2) APN is un-metered for this subscription, or
9799 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009800 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009801 *
9802 * @return whether data is allowed for a apn type.
9803 *
9804 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009805 */
9806 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009807 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009808 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9809 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009810
9811 // Now that all security checks passes, perform the operation as ourselves.
9812 final long identity = Binder.clearCallingIdentity();
9813 try {
9814 Phone phone = getPhone(subId);
9815 if (phone == null) return false;
9816
Jack Yu27422a52022-03-21 10:38:05 -07009817 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009818 boolean isDataEnabled;
Jack Yuf745f972022-08-15 19:53:50 +00009819 if (phone.isUsingNewDataStack()) {
9820 isMetered = phone.getDataNetworkController().getDataConfigManager()
9821 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9822 phone.getServiceState().getDataRoaming());
9823 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
9824 } else {
9825 isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
9826 isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType);
9827 }
Jack Yu99e87332021-12-17 23:14:15 -08009828 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009829 } finally {
9830 Binder.restoreCallingIdentity(identity);
9831 }
9832 }
9833
9834 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009835 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009836 enforceReadPrivilegedPermission("isApnMetered");
9837
9838 // Now that all security checks passes, perform the operation as ourselves.
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
9841 Phone phone = getPhone(subId);
9842 if (phone == null) return true; // By default return true.
Jack Yuf745f972022-08-15 19:53:50 +00009843 if (phone.isUsingNewDataStack()) {
9844 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9845 DataUtils.apnTypeToNetworkCapability(apnType),
9846 phone.getServiceState().getDataRoaming());
9847 }
9848
9849 return ApnSettingUtils.isMeteredApnType(apnType, phone);
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
Hall Liua62f5da2020-09-25 10:42:19 -07009979 switch (policy) {
9980 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf745f972022-08-15 19:53:50 +00009981 if (phone.isUsingNewDataStack()) {
9982 return phone.getDataSettingsManager().isDataAllowedInVoiceCall();
9983 } else {
9984 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9985 }
Hall Liua62f5da2020-09-25 10:42:19 -07009986 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf745f972022-08-15 19:53:50 +00009987 if (phone.isUsingNewDataStack()) {
9988 return phone.getDataSettingsManager().isMmsAlwaysAllowed();
9989 } else {
9990 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9991 }
Hall Liua62f5da2020-09-25 10:42:19 -07009992 default:
9993 throw new IllegalArgumentException(policy + " is not a valid policy");
9994 }
Jack Yub07d4972019-05-28 16:12:25 -07009995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
9999
10000 @Override
Hall Liuc66bb112021-02-02 12:09:32 -080010001 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -070010002 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +080010003 enforceModifyPermission();
10004
changbettyd5c246e2019-12-24 15:40:37 +080010005 final long identity = Binder.clearCallingIdentity();
10006 try {
Hall Liua62f5da2020-09-25 10:42:19 -070010007 Phone phone = getPhone(subscriptionId);
10008 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +080010009
Hall Liua62f5da2020-09-25 10:42:19 -070010010 switch (policy) {
10011 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
Jack Yuf745f972022-08-15 19:53:50 +000010012 if (phone.isUsingNewDataStack()) {
10013 phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled);
10014 } else {
10015 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
10016 }
Hall Liua62f5da2020-09-25 10:42:19 -070010017 break;
10018 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
Jack Yuf745f972022-08-15 19:53:50 +000010019 if (phone.isUsingNewDataStack()) {
10020 phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled);
10021 } else {
10022 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
10023 }
Hall Liua62f5da2020-09-25 10:42:19 -070010024 break;
10025 default:
10026 throw new IllegalArgumentException(policy + " is not a valid policy");
10027 }
changbettyd5c246e2019-12-24 15:40:37 +080010028 } finally {
10029 Binder.restoreCallingIdentity(identity);
10030 }
10031 }
10032
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010033 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010034 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010035 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10036 * otherwise.
10037 */
10038 @Override
10039 public void setCepEnabled(boolean isCepEnabled) {
10040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10041
10042 final long identity = Binder.clearCallingIdentity();
10043 try {
10044 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10045 for (Phone phone : PhoneFactory.getPhones()) {
10046 Phone defaultPhone = phone.getImsPhone();
10047 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10048 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10049 ImsPhoneCallTracker imsPhoneCallTracker =
10050 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10051 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10052 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10053 + imsPhone.getMsisdn());
10054 }
10055 }
10056 } finally {
10057 Binder.restoreCallingIdentity(identity);
10058 }
10059 }
allenwtsu46dcc572020-01-08 18:24:03 +080010060
10061 /**
10062 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10063 *
10064 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10065 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10066 * before being read.
10067 */
10068 @Override
10069 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10070 isCompressed) {
10071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10072 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010073 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10074 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10075 }
10076 if (!isImsAvailableOnDevice()) {
10077 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10078 "IMS not available on device.");
10079 }
10080
10081 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010082 try {
Hui Wang761a6682020-10-31 05:12:53 +000010083 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010086 }
10087 }
zoey chene02881a2019-12-30 16:11:23 +080010088
10089 @Override
10090 public boolean isIccLockEnabled(int subId) {
10091 enforceReadPrivilegedPermission("isIccLockEnabled");
10092
10093 // Now that all security checks passes, perform the operation as ourselves.
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 Phone phone = getPhone(subId);
10097 if (phone != null && phone.getIccCard() != null) {
10098 return phone.getIccCard().getIccLockEnabled();
10099 } else {
10100 return false;
10101 }
10102 } finally {
10103 Binder.restoreCallingIdentity(identity);
10104 }
10105 }
10106
10107 /**
10108 * Set the ICC pin lock enabled or disabled.
10109 *
10110 * @return an integer representing the status of IccLock enabled or disabled in the following
10111 * three cases:
10112 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10113 * 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 setIccLockEnabled(int subId, boolean enabled, String password) {
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_SET_ICC_LOCK_ENABLED,
10130 new Pair<Boolean, String>(enabled, password), phone, null);
10131 return attemptsRemaining;
10132
10133 } catch (Exception e) {
10134 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10135 } finally {
10136 Binder.restoreCallingIdentity(identity);
10137 }
10138 return 0;
10139 }
10140
10141 /**
10142 * Change the ICC password used in ICC pin lock.
10143 *
10144 * @return an integer representing the status of IccLock changed in the following three cases:
10145 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10146 * - Positive number and zero for remaining password attempts.
10147 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10148 *
10149 */
10150 @Override
10151 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10152 enforceModifyPermission();
10153
10154 Phone phone = getPhone(subId);
10155 if (phone == null) {
10156 return 0;
10157 }
10158 // Now that all security checks passes, perform the operation as ourselves.
10159 final long identity = Binder.clearCallingIdentity();
10160 try {
10161 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10162 new Pair<String, String>(oldPassword, newPassword), phone, null);
10163 return attemptsRemaining;
10164
10165 } catch (Exception e) {
10166 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 return 0;
10171 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010172
10173 /**
10174 * Request for receiving user activity notification
10175 */
10176 @Override
10177 public void requestUserActivityNotification() {
10178 if (!mNotifyUserActivity.get()
10179 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10180 mNotifyUserActivity.set(true);
10181 }
10182 }
10183
10184 /**
10185 * Called when userActivity is signalled in the power manager.
10186 * This is safe to call from any thread, with any window manager locks held or not.
10187 */
10188 @Override
10189 public void userActivity() {
10190 // ***************************************
10191 // * Inherited from PhoneWindowManager *
10192 // ***************************************
10193 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10194 // WITH ITS LOCKS HELD.
10195 //
10196 // This code must be VERY careful about the locks
10197 // it acquires.
10198 // In fact, the current code acquires way too many,
10199 // and probably has lurking deadlocks.
10200
10201 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10202 throw new SecurityException("Only the OS may call notifyUserActivity()");
10203 }
10204
10205 if (mNotifyUserActivity.getAndSet(false)) {
10206 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10207 USER_ACTIVITY_NOTIFICATION_DELAY);
10208 }
10209 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010210
10211 @Override
10212 public boolean canConnectTo5GInDsdsMode() {
10213 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10214 }
Jack Yud10cdd42020-09-28 20:28:01 -070010215
10216 @Override
10217 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10218 String callingFeatureId) {
10219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10220 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10221 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10222 }
10223
10224 Phone phone = getPhone(subId);
10225 if (phone == null) {
10226 throw new RuntimeException("phone is not available");
10227 }
10228 // Now that all security checks passes, perform the operation as ourselves.
10229 final long identity = Binder.clearCallingIdentity();
10230 try {
10231 return phone.getEquivalentHomePlmns();
10232 } finally {
10233 Binder.restoreCallingIdentity(identity);
10234 }
10235 }
Daniel Bright59e67312020-11-13 11:49:37 -080010236
10237 @Override
10238 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010239 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10240 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010241 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010242 if (radioInterfaceCapabilities == null) {
10243 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010244 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010245 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010246 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010247
Hui Wang641e81c2020-10-12 12:14:23 -070010248 @Override
10249 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10250 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010251 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10252 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10253 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10254 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10255 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010256 if (DBG) {
10257 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10258 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10259 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10260 }
10261
10262 if (!SubscriptionManager.isValidSubscriptionId(subId)
10263 || appType < TelephonyManager.APPTYPE_UNKNOWN
10264 || appType > TelephonyManager.APPTYPE_ISIM
10265 || nafUrl == null || securityProtocol == null || callback == null) {
10266 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10267 if (callback != null) {
10268 try {
10269 callback.onAuthenticationFailure(
10270 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10271 } catch (RemoteException exception) {
10272 log("Fail to notify onAuthenticationFailure due to " + exception);
10273 }
10274 return;
10275 }
10276 }
10277
10278 final long token = Binder.clearCallingIdentity();
10279 try {
10280 getGbaManager(subId).bootstrapAuthenticationRequest(
10281 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10282 forceBootStrapping, callback));
10283 } finally {
10284 Binder.restoreCallingIdentity(token);
10285 }
10286 }
10287
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010289 * Attempts to set the radio power state for all phones for thermal reason.
10290 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 * requested radio power state will actually be set. See {@link
10292 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10293 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 * @param enable {@code true} if trying to turn radio on.
10295 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10296 * false}.
10297 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010298 private boolean setRadioPowerForThermal(boolean enable) {
10299 boolean isPhoneAvailable = false;
10300 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10301 Phone phone = PhoneFactory.getPhone(i);
10302 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010303 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010304 isPhoneAvailable = true;
10305 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010306 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010307
10308 // return true if successfully informed the phone object about the thermal radio power
10309 // request.
10310 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010311 }
10312
10313 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010314 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010315 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10316 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10317 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10318 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10319 throw new IllegalArgumentException("modem does not support data throttling");
10320 }
10321
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010322 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10323 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010324 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010325 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10326 }
10327
Sarah Chinecc78c42022-03-31 21:16:48 -070010328 setDataEnabledForReason(
10329 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010330
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010331 if (isDataThrottlingSupported) {
10332 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010333 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010334 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10335 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10336 } else if (thermalMitigationResult
10337 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010338 log("Modem likely does not support data throttling on secondary carrier. Data " +
10339 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10340 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010341 }
10342 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010343 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010344
10345 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010346 }
10347
Jack Nudelman644b91a2021-03-12 14:09:48 -080010348 private static List<String> getThermalMitigationAllowlist(Context context) {
10349 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10350 for (String pckg : context.getResources()
10351 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10352 sThermalMitigationAllowlistedPackages.add(pckg);
10353 }
10354 }
10355
10356 return sThermalMitigationAllowlistedPackages;
10357 }
10358
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010359 private boolean isAnyPhoneInEmergencyState() {
10360 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10361 if (tm.isInEmergencyCall()) {
10362 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10363 return true;
10364 }
10365 for (Phone phone : PhoneFactory.getPhones()) {
10366 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10367 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10368 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10369 + phone.isInEcm());
10370 return true;
10371 }
10372 }
10373
10374 return false;
10375 }
10376
Jack Nudelman644b91a2021-03-12 14:09:48 -080010377 /**
10378 * Used by shell commands to add an authorized package name for thermal mitigation.
10379 * @param packageName name of package to be allowlisted
10380 * @param context
10381 */
10382 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10383 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10384 sThermalMitigationAllowlistedPackages.add(packageName);
10385 }
10386
10387 /**
10388 * Used by shell commands to remove an authorized package name for thermal mitigation.
10389 * @param packageName name of package to remove from allowlist
10390 * @param context
10391 */
10392 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10393 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10394 sThermalMitigationAllowlistedPackages.remove(packageName);
10395 }
10396
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010397 /**
10398 * Thermal mitigation request to control functionalities at modem.
10399 *
10400 * @param subId the id of the subscription.
10401 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010402 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 *
10404 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10405 */
10406 @Override
10407 @ThermalMitigationResult
10408 public int sendThermalMitigationRequest(
10409 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010410 ThermalMitigationRequest thermalMitigationRequest,
10411 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010412 enforceModifyPermission();
10413
Jack Nudelman644b91a2021-03-12 14:09:48 -080010414 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10415 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10416 .contains(callingPackage)) {
10417 throw new SecurityException("Calling package must be configured in the device config. "
10418 + "calling package: " + callingPackage);
10419 }
10420
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10422 final long identity = Binder.clearCallingIdentity();
10423
10424 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10425 try {
10426 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10427 switch (thermalMitigationAction) {
10428 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10429 thermalMitigationResult =
10430 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010431 thermalMitigationRequest.getDataThrottlingRequest(),
10432 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010433 break;
10434 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10435 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10436 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10437 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10438 }
10439
10440 // Ensure that radio is on. If not able to power on due to phone being
10441 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010442 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010443 thermalMitigationResult =
10444 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10445 break;
10446 }
10447
10448 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010449 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010450 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10451 break;
10452 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10453 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10454 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10455 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10456 }
10457
10458 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10459 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010460 Phone phone = getPhone(subId);
10461 if (phone == null) {
10462 thermalMitigationResult =
10463 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10464 break;
10465 }
10466
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010467 TelephonyConnectionService service =
10468 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010469 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010470 Log.e(LOG_TAG, "An emergency call is pending");
10471 thermalMitigationResult =
10472 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10473 break;
10474 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010475 thermalMitigationResult =
10476 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10477 break;
10478 }
10479 } else {
10480 thermalMitigationResult =
10481 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10482 break;
10483 }
10484
10485 // Turn radio off. If not able to power off due to phone being unavailable,
10486 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010487 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010488 thermalMitigationResult =
10489 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10490 break;
10491 }
10492 thermalMitigationResult =
10493 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10494 break;
10495 default:
10496 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10497 + "not exist. Requested action: " + thermalMitigationAction);
10498 }
10499 } catch (IllegalArgumentException e) {
10500 throw e;
10501 } catch (Exception e) {
10502 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10503 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10504 } finally {
10505 Binder.restoreCallingIdentity(identity);
10506 }
10507
10508 if (DBG) {
10509 log("thermalMitigationRequest returning with thermalMitigationResult: "
10510 + thermalMitigationResult);
10511 }
10512
10513 return thermalMitigationResult;
10514 }
Hui Wang641e81c2020-10-12 12:14:23 -070010515
10516 /**
10517 * Set the GbaService Package Name that Telephony will bind to.
10518 *
10519 * @param subId The sim that the GbaService is associated with.
10520 * @param packageName The name of the package to be replaced with.
10521 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10522 */
10523 @Override
10524 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10525 enforceModifyPermission();
10526
10527 final long identity = Binder.clearCallingIdentity();
10528 try {
10529 return getGbaManager(subId).overrideServicePackage(packageName);
10530 } finally {
10531 Binder.restoreCallingIdentity(identity);
10532 }
10533 }
10534
10535 /**
10536 * Return the package name of the currently bound GbaService.
10537 *
10538 * @param subId The sim that the GbaService is associated with.
10539 * @return the package name of the GbaService configuration, null if GBA is not supported.
10540 */
10541 @Override
10542 public String getBoundGbaService(int subId) {
10543 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10544
10545 final long identity = Binder.clearCallingIdentity();
10546 try {
10547 return getGbaManager(subId).getServicePackage();
10548 } finally {
10549 Binder.restoreCallingIdentity(identity);
10550 }
10551 }
10552
10553 /**
10554 * Set the release time for telephony to unbind GbaService.
10555 *
10556 * @param subId The sim that the GbaService is associated with.
10557 * @param interval The release time to unbind GbaService by millisecond.
10558 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10559 */
10560 @Override
10561 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10562 enforceModifyPermission();
10563
10564 final long identity = Binder.clearCallingIdentity();
10565 try {
10566 return getGbaManager(subId).overrideReleaseTime(interval);
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
10571
10572 /**
10573 * Return the release time for telephony to unbind GbaService.
10574 *
10575 * @param subId The sim that the GbaService is associated with.
10576 * @return The release time to unbind GbaService by millisecond.
10577 */
10578 @Override
10579 public int getGbaReleaseTime(int subId) {
10580 enforceReadPrivilegedPermission("getGbaReleaseTime");
10581
10582 final long identity = Binder.clearCallingIdentity();
10583 try {
10584 return getGbaManager(subId).getReleaseTime();
10585 } finally {
10586 Binder.restoreCallingIdentity(identity);
10587 }
10588 }
10589
10590 private GbaManager getGbaManager(int subId) {
10591 GbaManager instance = GbaManager.getInstance(subId);
10592 if (instance == null) {
10593 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10594 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10595 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10596 }
10597 return instance;
10598 }
Hui Wang761a6682020-10-31 05:12:53 +000010599
10600 /**
10601 * indicate whether the device and the carrier can support
10602 * RCS VoLTE single registration.
10603 */
10604 @Override
10605 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010606 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10607 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10608 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10609 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010610
10611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10612 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10613 }
10614
10615 final long identity = Binder.clearCallingIdentity();
10616 try {
10617 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10618 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010619 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10620 if (isCapable != null) {
10621 return isCapable;
10622 }
Hui Wang761a6682020-10-31 05:12:53 +000010623 }
Hui Wang67af90e2021-06-04 16:57:15 -070010624 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10625 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010626 } finally {
10627 Binder.restoreCallingIdentity(identity);
10628 }
10629 }
10630
10631 /**
10632 * Register RCS provisioning callback.
10633 */
10634 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010635 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010636 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010637 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010638 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010639 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10640 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010641
10642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10643 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10644 }
10645 if (!isImsAvailableOnDevice()) {
10646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10647 "IMS not available on device.");
10648 }
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010652 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010653 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010654 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10655 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010656 }
Hui Wang761a6682020-10-31 05:12:53 +000010657 } finally {
10658 Binder.restoreCallingIdentity(identity);
10659 }
10660 }
10661
10662 /**
10663 * Unregister RCS provisioning callback.
10664 */
10665 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010666 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010667 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010668 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010669 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010670 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10671 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010672
10673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10674 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10675 }
10676 if (!isImsAvailableOnDevice()) {
10677 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10678 "IMS not available on device.");
10679 }
10680
10681 final long identity = Binder.clearCallingIdentity();
10682 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010683 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010684 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010685 } finally {
10686 Binder.restoreCallingIdentity(identity);
10687 }
10688 }
10689
10690 /**
10691 * trigger RCS reconfiguration.
10692 */
10693 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010694 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10695 "triggerRcsReconfiguration",
10696 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010697
10698 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10699 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10700 }
10701 if (!isImsAvailableOnDevice()) {
10702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10703 "IMS not available on device.");
10704 }
10705
10706 final long identity = Binder.clearCallingIdentity();
10707 try {
10708 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
10713
10714 /**
10715 * Provide the client configuration parameters of the RCS application.
10716 */
10717 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010718 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10719 "setRcsClientConfiguration",
10720 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010721
10722 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10723 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10724 }
10725 if (!isImsAvailableOnDevice()) {
10726 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10727 "IMS not available on device.");
10728 }
10729
10730 final long identity = Binder.clearCallingIdentity();
10731
10732 try {
10733 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10734 if (configBinder == null) {
10735 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010736 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10737 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010738 } else {
10739 configBinder.setRcsClientConfiguration(rcc);
10740 }
joonhunshin3e154242021-09-17 06:33:39 +000010741
10742 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10743 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010744 } catch (RemoteException e) {
10745 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010746 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10747 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010748 } finally {
10749 Binder.restoreCallingIdentity(identity);
10750 }
10751 }
10752
10753 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010754 * Enables or disables the test mode for RCS VoLTE single registration.
10755 */
10756 @Override
10757 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10759 "setRcsSingleRegistrationTestModeEnabled");
10760
10761 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10762 }
10763
10764 /**
10765 * Gets the test mode for RCS VoLTE single registration.
10766 */
10767 @Override
10768 public boolean getRcsSingleRegistrationTestModeEnabled() {
10769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10770 "getRcsSingleRegistrationTestModeEnabled");
10771
10772 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10773 }
10774
10775 /**
Hui Wang761a6682020-10-31 05:12:53 +000010776 * Overrides the config of RCS VoLTE single registration enabled for the device.
10777 */
10778 @Override
10779 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10781 "setDeviceSingleRegistrationEnabledOverride");
10782 enforceModifyPermission();
10783
10784 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10785 : Boolean.parseBoolean(enabledStr);
10786 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010787 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010788 }
10789
10790 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010791 * Sends a device to device communication message. Only usable via shell.
10792 * @param message message to send.
10793 * @param value message value.
10794 */
10795 @Override
10796 public void sendDeviceToDeviceMessage(int message, int value) {
10797 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010798 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010799 enforceModifyPermission();
10800
10801 final long identity = Binder.clearCallingIdentity();
10802 try {
10803 TelephonyConnectionService service =
10804 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10805 if (service == null) {
10806 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10807 return;
10808 }
10809 service.sendTestDeviceToDeviceMessage(message, value);
10810 } finally {
10811 Binder.restoreCallingIdentity(identity);
10812 }
10813 }
10814
Tyler Gunnbabbda02021-02-10 11:05:02 -080010815 /**
10816 * Sets the specified device to device transport active.
10817 * @param transport The transport to set active.
10818 */
10819 @Override
10820 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10821 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10822 "setActiveDeviceToDeviceTransport");
10823 enforceModifyPermission();
10824
10825 final long identity = Binder.clearCallingIdentity();
10826 try {
10827 TelephonyConnectionService service =
10828 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10829 if (service == null) {
10830 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10831 return;
10832 }
10833 service.setActiveDeviceToDeviceTransport(transport);
10834 } finally {
10835 Binder.restoreCallingIdentity(identity);
10836 }
10837 }
Tyler Gunn92479152021-01-20 16:30:10 -080010838
Tyler Gunnd4339262021-05-03 14:46:49 -070010839 @Override
10840 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10841 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10842 "setDeviceToDeviceForceEnabled");
10843
10844 final long identity = Binder.clearCallingIdentity();
10845 try {
10846 Arrays.stream(PhoneFactory.getPhones()).forEach(
10847 p -> {
10848 Phone thePhone = p.getImsPhone();
10849 if (thePhone != null && thePhone instanceof ImsPhone) {
10850 ImsPhone imsPhone = (ImsPhone) thePhone;
10851 CallTracker tracker = imsPhone.getCallTracker();
10852 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10853 ImsPhoneCallTracker imsPhoneCallTracker =
10854 (ImsPhoneCallTracker) tracker;
10855 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10856 }
10857 }
10858 }
10859 );
10860 } finally {
10861 Binder.restoreCallingIdentity(identity);
10862 }
10863 }
10864
Tyler Gunn92479152021-01-20 16:30:10 -080010865 /**
Hui Wang761a6682020-10-31 05:12:53 +000010866 * Gets the config of RCS VoLTE single registration enabled for the device.
10867 */
10868 @Override
10869 public boolean getDeviceSingleRegistrationEnabled() {
10870 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10871 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10872 }
10873
10874 /**
10875 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10876 */
10877 @Override
10878 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10880 "setCarrierSingleRegistrationEnabledOverride");
10881 enforceModifyPermission();
10882
10883 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10884 : Boolean.parseBoolean(enabledStr);
10885 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10886 subId, enabled);
10887 }
10888
10889 /**
10890 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10891 */
10892 @Override
10893 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10894 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10895 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10896 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010897
10898 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010899 * Overrides the ims feature validation result
10900 */
10901 @Override
10902 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10904 "setImsFeatureValidationOverride");
10905
10906 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10907 : Boolean.parseBoolean(enabledStr);
10908 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10909 subId, enabled);
10910 }
10911
10912 /**
10913 * Gets the ims feature validation override value
10914 */
10915 @Override
10916 public boolean getImsFeatureValidationOverride(int subId) {
10917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10918 "getImsFeatureValidationOverride");
10919 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10920 }
10921
10922 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010923 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10924 * their mobile plan.
10925 */
10926 @Override
10927 public String getMobileProvisioningUrl() {
10928 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10929 final long identity = Binder.clearCallingIdentity();
10930 try {
10931 return getDefaultPhone().getMobileProvisioningUrl();
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010936
James.cf Linbcdf8b32021-01-14 16:44:13 +080010937 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010938 * Get the EAB contact from the EAB database.
10939 */
10940 @Override
10941 public String getContactFromEab(String contact) {
10942 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10943 enforceModifyPermission();
10944 final long identity = Binder.clearCallingIdentity();
10945 try {
10946 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10947 } finally {
10948 Binder.restoreCallingIdentity(identity);
10949 }
10950 }
10951
10952 /**
Calvin Pana1434322021-07-01 19:27:01 +080010953 * Get the EAB capability from the EAB database.
10954 */
10955 @Override
10956 public String getCapabilityFromEab(String contact) {
10957 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10958 enforceModifyPermission();
10959 final long identity = Binder.clearCallingIdentity();
10960 try {
10961 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10962 } finally {
10963 Binder.restoreCallingIdentity(identity);
10964 }
10965 }
10966
10967 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010968 * Remove the EAB contacts from the EAB database.
10969 */
10970 @Override
10971 public int removeContactFromEab(int subId, String contacts) {
10972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10973 enforceModifyPermission();
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
10976 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10977 } finally {
10978 Binder.restoreCallingIdentity(identity);
10979 }
10980 }
10981
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010982 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010983 public boolean getDeviceUceEnabled() {
10984 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10985 final long identity = Binder.clearCallingIdentity();
10986 try {
10987 return mApp.getDeviceUceEnabled();
10988 } finally {
10989 Binder.restoreCallingIdentity(identity);
10990 }
10991 }
10992
10993 @Override
10994 public void setDeviceUceEnabled(boolean isEnabled) {
10995 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10996 final long identity = Binder.clearCallingIdentity();
10997 try {
10998 mApp.setDeviceUceEnabled(isEnabled);
10999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
Brad Ebinger14d467f2021-02-12 06:18:28 +000011004 /**
11005 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
11006 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11007 */
11008 // Used for SHELL command only right now.
11009 @Override
11010 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
11011 List<String> featureTags) {
11012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11013 "addUceRegistrationOverrideShell");
11014 final long identity = Binder.clearCallingIdentity();
11015 try {
11016 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
11017 new ArraySet<>(featureTags));
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 /**
11026 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
11027 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11028 */
11029 // Used for SHELL command only right now.
11030 @Override
11031 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11032 List<String> featureTags) {
11033 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11034 "removeUceRegistrationOverrideShell");
11035 final long identity = Binder.clearCallingIdentity();
11036 try {
11037 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11038 new ArraySet<>(featureTags));
11039 } catch (ImsException e) {
11040 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11041 } finally {
11042 Binder.restoreCallingIdentity(identity);
11043 }
11044 }
11045
11046 /**
11047 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11048 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11049 */
11050 // Used for SHELL command only right now.
11051 @Override
11052 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11054 "clearUceRegistrationOverrideShell");
11055 final long identity = Binder.clearCallingIdentity();
11056 try {
11057 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11058 } catch (ImsException e) {
11059 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11060 } finally {
11061 Binder.restoreCallingIdentity(identity);
11062 }
11063 }
11064
11065 /**
11066 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11067 */
11068 // Used for SHELL command only right now.
11069 @Override
11070 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11072 "getLatestRcsContactUceCapabilityShell");
11073 final long identity = Binder.clearCallingIdentity();
11074 try {
11075 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11076 } catch (ImsException e) {
11077 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11078 } finally {
11079 Binder.restoreCallingIdentity(identity);
11080 }
11081 }
11082
11083 /**
11084 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11085 * device does not have an active PUBLISH.
11086 */
11087 // Used for SHELL command only right now.
11088 @Override
11089 public String getLastUcePidfXmlShell(int subId) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11091 final long identity = Binder.clearCallingIdentity();
11092 try {
11093 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11094 } catch (ImsException e) {
11095 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11096 } finally {
11097 Binder.restoreCallingIdentity(identity);
11098 }
11099 }
11100
James.cf Line8713a42021-04-29 16:04:26 +080011101 /**
11102 * Remove UCE requests cannot be sent to the network status.
11103 */
11104 // Used for SHELL command only right now.
11105 @Override
11106 public boolean removeUceRequestDisallowedStatus(int subId) {
11107 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11108 final long identity = Binder.clearCallingIdentity();
11109 try {
11110 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11111 } catch (ImsException e) {
11112 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11113 } finally {
11114 Binder.restoreCallingIdentity(identity);
11115 }
11116 }
11117
James.cf Lin18bb9002021-05-25 01:37:38 +080011118 /**
11119 * Remove UCE requests cannot be sent to the network status.
11120 */
11121 // Used for SHELL command only.
11122 @Override
11123 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11125 final long identity = Binder.clearCallingIdentity();
11126 try {
11127 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11128 } catch (ImsException e) {
11129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11130 } finally {
11131 Binder.restoreCallingIdentity(identity);
11132 }
11133 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011134
James.cf Lin4b784aa2021-01-31 03:25:15 +080011135 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011136 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11137 String callingPackage) {
11138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11139 mApp, subId, "setSignalStrengthUpdateRequest");
11140
11141 final int callingUid = Binder.getCallingUid();
11142 // Verify that tha callingPackage belongs to the calling UID
11143 mApp.getSystemService(AppOpsManager.class)
11144 .checkPackage(callingUid, callingPackage);
11145
Rambo Wang3607f502021-02-01 21:51:40 -080011146 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011147
11148 final long identity = Binder.clearCallingIdentity();
11149 try {
11150 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11151 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11152
11153 if (result instanceof IllegalStateException) {
11154 throw (IllegalStateException) result;
11155 }
11156 } finally {
11157 Binder.restoreCallingIdentity(identity);
11158 }
11159 }
11160
11161 @Override
11162 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11163 String callingPackage) {
11164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11165 mApp, subId, "clearSignalStrengthUpdateRequest");
11166
11167 final int callingUid = Binder.getCallingUid();
11168 // Verify that tha callingPackage belongs to the calling UID
11169 mApp.getSystemService(AppOpsManager.class)
11170 .checkPackage(callingUid, callingPackage);
11171
11172 final long identity = Binder.clearCallingIdentity();
11173 try {
11174 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11175 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11176
11177 if (result instanceof IllegalStateException) {
11178 throw (IllegalStateException) result;
11179 }
11180 } finally {
11181 Binder.restoreCallingIdentity(identity);
11182 }
11183 }
11184
Rambo Wang3607f502021-02-01 21:51:40 -080011185 private static void validateSignalStrengthUpdateRequest(Context context,
11186 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011187 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11188 // phone/system process do not have further restriction on request
11189 return;
11190 }
11191
11192 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011193 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011194 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011195 context.enforceCallingOrSelfPermission(
11196 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11197 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011198 }
11199
11200 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11201 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11202 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11203 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11204 || info.isEnabled()) {
11205 throw new IllegalArgumentException(
11206 "Only system can set hide fields in SignalThresholdInfo");
11207 }
11208
11209 // Thresholds length for each RAN need in range. This has been validated in
11210 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11211 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11212 final int[] thresholds = info.getThresholds();
11213 Objects.requireNonNull(thresholds);
11214 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11215 || thresholds.length
11216 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11217 throw new IllegalArgumentException(
11218 "thresholds length is out of range: " + thresholds.length);
11219 }
11220 }
11221 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011222
11223 /**
11224 * Gets the current phone capability.
11225 *
11226 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11227 * @return the PhoneCapability which describes the data connection capability of modem.
11228 * It's used to evaluate possible phone config change, for example from single
11229 * SIM device to multi-SIM device.
11230 */
11231 @Override
11232 public PhoneCapability getPhoneCapability() {
11233 enforceReadPrivilegedPermission("getPhoneCapability");
11234 final long identity = Binder.clearCallingIdentity();
11235 try {
11236 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11237 } finally {
11238 Binder.restoreCallingIdentity(identity);
11239 }
11240 }
Michele Berionne5e411512020-11-13 02:36:59 +000011241
11242 /**
11243 * Prepare TelephonyManager for an unattended reboot. The reboot is
11244 * required to be done shortly after the API is invoked.
11245 */
11246 @Override
11247 @TelephonyManager.PrepareUnattendedRebootResult
11248 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011250 enforceRebootPermission();
11251
11252 final long identity = Binder.clearCallingIdentity();
11253 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011254 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011255 } finally {
11256 Binder.restoreCallingIdentity(identity);
11257 }
11258 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011259
11260 /**
11261 * Request to get the current slicing configuration including URSP rules and
11262 * NSSAIs (configured, allowed and rejected).
11263 *
11264 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11265 */
11266 @Override
11267 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011268 TelephonyPermissions
11269 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11270 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011271
11272 final long identity = Binder.clearCallingIdentity();
11273 try {
11274 Phone phone = getDefaultPhone();
11275 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11276 } finally {
11277 Binder.restoreCallingIdentity(identity);
11278 }
11279 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011280
11281 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011282 * Check whether the given premium capability is available for purchase from the carrier.
11283 *
11284 * @param capability The premium capability to check.
11285 * @param subId The subId to check the premium capability for.
11286 *
11287 * @return Whether the given premium capability is available to purchase.
11288 */
11289 @Override
11290 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11291 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11292 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11293 log("Premium capability "
11294 + TelephonyManager.convertPremiumCapabilityToString(capability)
11295 + " is not available for purchase due to missing permissions.");
11296 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11297 + "permission READ_BASIC_PHONE_STATE.");
11298 }
11299
11300 Phone phone = getPhone(subId);
11301 final long identity = Binder.clearCallingIdentity();
11302 try {
11303 return SliceStore.getInstance(phone)
11304 .isPremiumCapabilityAvailableForPurchase(capability);
11305 } finally {
11306 Binder.restoreCallingIdentity(identity);
11307 }
11308 }
11309
11310 /**
11311 * Purchase the given premium capability from the carrier.
11312 *
11313 * @param capability The premium capability to purchase.
11314 * @param callback The result of the purchase request.
11315 * @param subId The subId to purchase the premium capability for.
11316 */
11317 @Override
11318 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11319 log("purchasePremiumCapability: capability="
11320 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11321 + getCurrentPackageName());
11322
11323 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11324 mApp, "purchasePremiumCapability")) {
11325 log("purchasePremiumCapability "
11326 + TelephonyManager.convertPremiumCapabilityToString(capability)
11327 + " failed due to missing permissions.");
11328 throw new SecurityException("purchasePremiumCapability requires permission "
11329 + "READ_BASIC_PHONE_STATE.");
11330 }
11331
11332 Phone phone = getPhone(subId);
11333 Pair<Integer, IIntegerConsumer> argument = new Pair<>(capability, callback);
11334 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, argument, phone, null);
11335 }
11336
11337 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011338 * Register an IMS connection state callback
11339 */
11340 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011341 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11342 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011343 if (feature == ImsFeature.FEATURE_MMTEL) {
11344 // ImsMmTelManager
11345 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11346 TelephonyPermissions
11347 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11348 mApp, subId, "registerImsStateCallback");
11349 } else if (feature == ImsFeature.FEATURE_RCS) {
11350 // ImsRcsManager or SipDelegateManager
11351 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11352 Binder.getCallingUid(), "registerImsStateCallback",
11353 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11354 Manifest.permission.READ_PRECISE_PHONE_STATE,
11355 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11356 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11357 }
11358
11359 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11360 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11361 "IMS not available on device.");
11362 }
11363
11364 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11365 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11366 }
11367
11368 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11369 if (controller == null) {
11370 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11371 "IMS not available on device.");
11372 }
11373
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011374 if (callingPackage == null) {
11375 callingPackage = getCurrentPackageName();
11376 }
11377
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011378 final long token = Binder.clearCallingIdentity();
11379 try {
11380 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011381 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011382 } catch (ImsException e) {
11383 throw new ServiceSpecificException(e.getCode());
11384 } finally {
11385 Binder.restoreCallingIdentity(token);
11386 }
11387 }
11388
11389 /**
11390 * Unregister an IMS connection state callback
11391 */
11392 @Override
11393 public void unregisterImsStateCallback(IImsStateCallback cb) {
11394 final long token = Binder.clearCallingIdentity();
11395 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11396 if (controller == null) {
11397 return;
11398 }
11399 try {
11400 controller.unregisterImsStateCallback(cb);
11401 } finally {
11402 Binder.restoreCallingIdentity(token);
11403 }
11404 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011405
11406 /**
11407 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11408 *
11409 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11410 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11411 * SecurityException.
11412 * If there is current registered network this value will be same as the registered cell
11413 * identity. If the device goes out of service the previous cell identity is cached and
11414 * will be returned. If the cache age of the Cell identity is more than 24 hours
11415 * it will be cleared and null will be returned.
11416 *
11417 */
11418 @Override
11419 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11420 String callingFeatureId) {
11421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11422 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11423 LocationAccessPolicy.checkLocationPermission(mApp,
11424 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11425 .setCallingPackage(callingPackage)
11426 .setCallingFeatureId(callingFeatureId)
11427 .setCallingPid(Binder.getCallingPid())
11428 .setCallingUid(Binder.getCallingUid())
11429 .setMethod("getLastKnownCellIdentity")
11430 .setLogAsInfo(true)
11431 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11432 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11433 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11434 .build());
11435
11436 boolean hasFinePermission =
11437 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11438 if (!hasFinePermission
11439 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11440 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011441 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011442 }
11443
11444 final long identity = Binder.clearCallingIdentity();
11445 try {
11446 Phone phone = getPhone(subId);
11447 if (phone == null) return null;
11448 ServiceStateTracker sst = phone.getServiceStateTracker();
11449 if (sst == null) return null;
11450 return sst.getLastKnownCellIdentity();
11451 } finally {
11452 Binder.restoreCallingIdentity(identity);
11453 }
11454 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011455
Jack Yuf745f972022-08-15 19:53:50 +000011456 @Override
11457 public boolean isUsingNewDataStack() {
11458 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack");
11459 return getDefaultPhone().isUsingNewDataStack();
11460 }
11461
jimsun3b9ccac2021-10-26 15:01:23 +080011462 /**
11463 * Sets the modem service class Name that Telephony will bind to.
11464 *
11465 * @param serviceName The class name of the modem service.
11466 * @return true if the operation is succeed, otherwise false.
11467 */
11468 public boolean setModemService(String serviceName) {
11469 Log.d(LOG_TAG, "setModemService - " + serviceName);
11470 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11472 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11473 "setModemService");
11474 return mPhoneConfigurationManager.setModemService(serviceName);
11475 }
11476
11477 /**
11478 * Return the class name of the currently bounded modem service.
11479 *
11480 * @return the class name of the modem service.
11481 */
11482 public String getModemService() {
11483 String result;
11484 Log.d(LOG_TAG, "getModemService");
11485 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11486 TelephonyPermissions
11487 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11488 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11489 "getModemService");
11490 result = mPhoneConfigurationManager.getModemService();
11491 Log.d(LOG_TAG, "result = " + result);
11492 return result;
11493 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011494
11495 @Override
11496 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11497 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11498 mApp.enforceCallingOrSelfPermission(
11499 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11501
11502 final long identity = Binder.clearCallingIdentity();
11503 try {
11504 Phone phone = getPhone(subId);
11505 if (phone == null) return;
11506 phone.setVoiceServiceStateOverride(hasService);
11507 } finally {
11508 Binder.restoreCallingIdentity(identity);
11509 }
11510 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011511
11512 /**
11513 * set removable eSIM as default eUICC.
11514 *
11515 * @hide
11516 */
11517 @Override
11518 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11519 enforceModifyPermission();
11520 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11521
11522 final long identity = Binder.clearCallingIdentity();
11523 try {
11524 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11525 } finally {
11526 Binder.restoreCallingIdentity(identity);
11527 }
11528 }
11529
11530 /**
11531 * Returns whether the removable eSIM is default eUICC or not.
11532 *
11533 * @hide
11534 */
11535 @Override
11536 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11537 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11539
11540 final long identity = Binder.clearCallingIdentity();
11541 try {
11542 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11543 } finally {
11544 Binder.restoreCallingIdentity(identity);
11545 }
11546 }
11547
11548
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011549}