blob: 88b44434bf97a97937797d545950340b29a8c4f2 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
joonhunshin3e154242021-09-17 06:33:39 +000025import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT;
Ta-wei Yen87c49842016-05-13 21:19:52 -070026
Brad Ebinger34c09a52021-02-17 23:23:21 +000027import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080029import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070030import android.annotation.Nullable;
sandeepjsb6c87872021-09-27 15:34:44 +000031import android.annotation.RequiresPermission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080033import android.app.PendingIntent;
Tyler Gunn64144d92022-03-17 14:16:41 -070034import android.app.PropertyInvalidatedCache;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000035import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080036import android.app.role.RoleManager;
sandeepjsb6c87872021-09-27 15:34:44 +000037import android.compat.annotation.ChangeId;
38import android.compat.annotation.EnabledSince;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070039import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070040import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.content.Context;
42import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070043import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070044import android.content.pm.ComponentInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070045import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.net.Uri;
47import android.os.AsyncResult;
48import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080049import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050import android.os.Bundle;
51import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070052import android.os.IBinder;
tom hsu0b59d292022-09-29 23:49:21 +080053import android.os.LocaleList;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.Looper;
55import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070056import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080057import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070058import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070059import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080060import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080061import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070062import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070063import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080064import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070066import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070068import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070069import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080070import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070071import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090072import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080073import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080074import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070075import android.telecom.TelecomManager;
Gary Jian3aa9a762022-01-24 16:41:19 +080076import android.telephony.AccessNetworkConstants;
77import android.telephony.ActivityStatsTechSpecificInfo;
Chen Xu227e06f2019-09-26 22:48:11 -070078import android.telephony.Annotation.ApnType;
Jack Yu0eda6842022-04-18 00:34:46 -070079import android.telephony.Annotation.DataActivityType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080080import android.telephony.Annotation.ThermalMitigationResult;
Sarah Chin2ec39f62022-08-31 17:03:26 -070081import android.telephony.AnomalyReporter;
Shuo Qian4a594052020-01-23 11:59:30 -080082import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070083import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080084import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070085import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080086import android.telephony.CellIdentityCdma;
87import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070089import android.telephony.CellInfoGsm;
90import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070091import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080092import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070093import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070094import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070095import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080096import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080098import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070099import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -0800100import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800101import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800105import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800106import android.telephony.SignalStrengthUpdateRequest;
107import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800108import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800110import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700111import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700112import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800113import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800114import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800115import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000116import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000118import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700119import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700120import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800121import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800122import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700123import android.telephony.gba.GbaAuthRequest;
124import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700125import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000127import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000128import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700129import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000130import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700131import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800132import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700133import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800134import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700135import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000136import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700137import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800138import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800139import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700142import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800144import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800145
Andrew Lee312e8172014-10-23 17:01:36 -0700146import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800147import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800148import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800149import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800150import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700152import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700153import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800154import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800155import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700156import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700157import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800158import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700159import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800160import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800161import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800162import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700163import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000164import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800166import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700167import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800169import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700171import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700174import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800175import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700176import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700177import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700178import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700179import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800180import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800181import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700182import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700183import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700184import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800185import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800186import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700188import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700190import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800191import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700192import com.android.internal.telephony.imsphone.ImsPhone;
193import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000194import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800195import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700196import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197import com.android.internal.telephony.uicc.IccIoResult;
198import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800199import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700200import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800201import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700202import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000203import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800204import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000205import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800206import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700207import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700208import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800209import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800210import com.android.phone.callcomposer.CallComposerPictureManager;
211import com.android.phone.callcomposer.CallComposerPictureTransfer;
212import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700213import com.android.phone.settings.PickSmsSubscriptionActivity;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700214import com.android.phone.slicestore.SliceStore;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700215import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800216import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700217import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700218import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800219import com.android.services.telephony.TelecomAccountRegistry;
220import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800221import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800222
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700224import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.io.IOException;
226import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700227import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229import java.util.Arrays;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +0000230import java.util.Collection;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -0800231import java.util.Collections;
sqian11b7a0e2018-12-05 18:48:28 -0800232import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800233import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800234import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100235import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700237import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800238import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800239import java.util.Set;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700240import java.util.UUID;
Hall Liu82694d52020-12-11 18:22:04 -0800241import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800242import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800243import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
245/**
246 * Implementation of the ITelephony interface.
247 */
Santos Cordon117fee72014-05-16 17:56:12 -0700248public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 private static final String LOG_TAG = "PhoneInterfaceManager";
250 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
251 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800252 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253
254 // Message codes used with mMainThreadHandler
255 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700256 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
257 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700258 private static final int CMD_OPEN_CHANNEL = 9;
259 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
260 private static final int CMD_CLOSE_CHANNEL = 11;
261 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800262 private static final int CMD_NV_READ_ITEM = 13;
263 private static final int EVENT_NV_READ_ITEM_DONE = 14;
264 private static final int CMD_NV_WRITE_ITEM = 15;
265 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
266 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
267 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_RESET_MODEM_CONFIG = 19;
269 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800270 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
271 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800272 private static final int CMD_SEND_ENVELOPE = 25;
273 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000274 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
275 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700276 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
277 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
278 private static final int CMD_EXCHANGE_SIM_IO = 31;
279 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800280 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
281 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700282 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
283 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700284 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
285 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700286 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
287 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
288 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
289 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700290 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
291 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
292 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
293 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700294 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800295 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
296 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000297 private static final int CMD_SWITCH_SLOTS = 50;
298 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700299 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
300 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
301 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
302 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
303 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
304 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
305 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
306 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700307 private static final int CMD_GET_ALL_CELL_INFO = 60;
308 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
309 private static final int CMD_GET_CELL_LOCATION = 62;
310 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700311 private static final int CMD_MODEM_REBOOT = 64;
312 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700313 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
314 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800315 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
316 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700317 private static final int CMD_GET_MODEM_STATUS = 70;
318 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700319 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
320 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700321 private static final int CMD_ERASE_MODEM_CONFIG = 74;
322 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800323 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
324 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
325 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
326 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800327 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
328 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800329 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800330 private static final int CMD_GET_CALL_FORWARDING = 83;
331 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
332 private static final int CMD_SET_CALL_FORWARDING = 85;
333 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
334 private static final int CMD_GET_CALL_WAITING = 87;
335 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
336 private static final int CMD_SET_CALL_WAITING = 89;
337 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700338 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
339 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
340 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
341 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700342 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
343 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800344 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
345 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800346 private static final int CMD_SET_DATA_THROTTLING = 99;
347 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800348 private static final int CMD_SET_SIM_POWER = 101;
349 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800350 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
351 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
352 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
353 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800354 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
355 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000356 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800357 private static final int CMD_GET_SLICING_CONFIG = 110;
358 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800359 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700360 private static final int CMD_ENABLE_VONR = 113;
361 private static final int EVENT_ENABLE_VONR_DONE = 114;
362 private static final int CMD_IS_VONR_ENABLED = 115;
363 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Sarah Chin2ec39f62022-08-31 17:03:26 -0700364 private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117;
365 private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800367 // Parameters of select command.
368 private static final int SELECT_COMMAND = 0xA4;
369 private static final int SELECT_P1 = 0x04;
370 private static final int SELECT_P2 = 0;
371 private static final int SELECT_P3 = 0x10;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 /** The singleton instance. */
374 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800375 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Wink Saville3ab207e2014-11-20 13:07:20 -0800377 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800379 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700380 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800381 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700382 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800383 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800384 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800385 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700386 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800387 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 /** User Activity */
390 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800391 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
392
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700393 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
394
Derek Tan97ebb422014-09-05 16:55:38 -0700395 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
396 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800397 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800398 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700399
Michelecea4cf22018-12-21 15:00:11 -0800400 // String to store multi SIM allowed
401 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
402
Derek Tan740e1672017-06-27 14:56:27 -0700403 // The AID of ISD-R.
404 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
405
yinxub1bed742017-04-17 11:45:04 -0700406 private NetworkScanRequestTracker mNetworkScanRequestTracker;
407
David Kelly5e06a7f2018-03-12 14:10:59 +0000408 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
409 private static final int MANUFACTURER_CODE_LENGTH = 8;
410
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800412 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800413
Sarah Chin2ec39f62022-08-31 17:03:26 -0700414 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
415 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
416
Derek Tan89e89d42014-07-08 17:00:10 -0700417 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700418 * Experiment flag to enable erase modem config on reset network, default value is false
419 */
420 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
421 "reset_network_erase_modem_config_enabled";
422
Rambo Wang0f050d82021-02-12 11:43:36 -0800423 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800424
sandeepjsb6c87872021-09-27 15:34:44 +0000425 /**
426 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
427 * one ICCID active at the same time.
428 * Apps should use below API signatures if targeting SDK is T and beyond.
429 *
430 * @hide
431 */
432 @ChangeId
433 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
434 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800435
Naina Nallurid63128d2019-09-17 14:10:30 -0700436 /**
Chen Xu540470b2021-12-14 17:15:47 -0800437 * Apps targeting on Android T and beyond will get exception whenever icc close channel
438 * operation fails.
439 */
440 @ChangeId
441 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
442 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
443
444 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 * A request object to use for transmitting data to an ICC.
446 */
447 private static final class IccAPDUArgument {
448 public int channel, cla, command, p1, p2, p3;
449 public String data;
450
451 public IccAPDUArgument(int channel, int cla, int command,
452 int p1, int p2, int p3, String data) {
453 this.channel = channel;
454 this.cla = cla;
455 this.command = command;
456 this.p1 = p1;
457 this.p2 = p2;
458 this.p3 = p3;
459 this.data = data;
460 }
461 }
462
463 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700464 * A request object to use for transmitting data to an ICC.
465 */
466 private static final class ManualNetworkSelectionArgument {
467 public OperatorInfo operatorInfo;
468 public boolean persistSelection;
469
470 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
471 this.operatorInfo = operatorInfo;
472 this.persistSelection = persistSelection;
473 }
474 }
475
Sarah Chin71b3a852022-09-28 15:54:19 -0700476 private static final class PurchasePremiumCapabilityArgument {
477 public @TelephonyManager.PremiumCapability int capability;
478 public @NonNull String appName;
479 public @NonNull IIntegerConsumer callback;
480
481 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
482 @NonNull String appName, @NonNull IIntegerConsumer callback) {
483 this.capability = capability;
484 this.appName = appName;
485 this.callback = callback;
486 }
487 }
488
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700489 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
491 * request after sending. The main thread will notify the request when it is complete.
492 */
493 private static final class MainThreadRequest {
494 /** The argument to use for the request */
495 public Object argument;
496 /** The result of the request that is run on the main thread */
497 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800498 // The subscriber id that this request applies to. Defaults to
499 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
500 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501
Nathan Harold92bed182018-10-12 18:16:49 -0700502 // In cases where subId is unavailable, the caller needs to specify the phone.
503 public Phone phone;
504
vagdeviaf9a5b92018-08-15 16:01:53 -0700505 public WorkSource workSource;
506
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700507 public MainThreadRequest(Object argument) {
508 this.argument = argument;
509 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800510
Nathan Harold92bed182018-10-12 18:16:49 -0700511 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
512 this.argument = argument;
513 if (phone != null) {
514 this.phone = phone;
515 }
516 this.workSource = workSource;
517 }
518
vagdeviaf9a5b92018-08-15 16:01:53 -0700519 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800520 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800521 if (subId != null) {
522 this.subId = subId;
523 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700524 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 }
527
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800528 private static final class IncomingThirdPartyCallArgs {
529 public final ComponentName component;
530 public final String callId;
531 public final String callerDisplayName;
532
533 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
534 String callerDisplayName) {
535 this.component = component;
536 this.callId = callId;
537 this.callerDisplayName = callerDisplayName;
538 }
539 }
540
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 /**
542 * A handler that processes messages on the main thread in the phone process. Since many
543 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
544 * inbound binder threads to the main thread in the phone process. The Binder thread
545 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
546 * on, which will be notified when the operation completes and will contain the result of the
547 * request.
548 *
549 * <p>If a MainThreadRequest object is provided in the msg.obj field,
550 * note that request.result must be set to something non-null for the calling thread to
551 * unblock.
552 */
553 private final class MainThreadHandler extends Handler {
554 @Override
555 public void handleMessage(Message msg) {
556 MainThreadRequest request;
557 Message onCompleted;
558 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000559 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800561 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700562
563 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 case CMD_HANDLE_USSD_REQUEST: {
565 request = (MainThreadRequest) msg.obj;
566 final Phone phone = getPhoneFromRequest(request);
567 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800568 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700570
Pengquan Menga1bb6272018-09-06 09:59:22 -0700571 if (!isUssdApiAllowed(request.subId)) {
572 // Carrier does not support use of this API, return failure.
573 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
574 UssdResponse response = new UssdResponse(ussdRequest, null);
575 Bundle returnData = new Bundle();
576 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
577 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700578
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 request.result = true;
580 notifyRequester(request);
581 return;
582 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700583
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 try {
585 request.result = phone != null
586 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
587 } catch (CallStateException cse) {
588 request.result = false;
589 }
590 // Wake up the requesting thread
591 notifyRequester(request);
592 break;
pkanwar32d516d2016-10-14 19:37:38 -0700593 }
594
Yorke Lee716f67e2015-06-17 15:39:16 -0700595 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700596 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700597 final Phone phone = getPhoneFromRequest(request);
598 request.result = phone != null ?
599 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
600 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700601 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700603 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700608 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000609 uiccPort = getUiccPortFromRequest(request);
610 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800616 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000617 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800618 iccArgument.channel, iccArgument.cla, iccArgument.command,
619 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
620 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
627 if (ar.exception == null && ar.result != null) {
628 request.result = ar.result;
629 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800630 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.result == null) {
632 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800633 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800635 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 } else {
637 loge("iccTransmitApduLogicalChannel: Unknown exception");
638 }
639 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
645 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000646 uiccPort = getUiccPortFromRequest(request);
647 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 } else {
652 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800653 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000654 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800655 iccArgument.cla, iccArgument.command, iccArgument.p1,
656 iccArgument.p2,
657 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 }
659 break;
660
661 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
666 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800667 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 if (ar.result == null) {
669 loge("iccTransmitApduBasicChannel: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("iccTransmitApduBasicChannel: CommandException: " +
672 ar.exception);
673 } else {
674 loge("iccTransmitApduBasicChannel: Unknown exception");
675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 break;
679
680 case CMD_EXCHANGE_SIM_IO:
681 request = (MainThreadRequest) msg.obj;
682 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000683 uiccPort = getUiccPortFromRequest(request);
684 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700685 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800686 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
690 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000691 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
693 iccArgument.data, onCompleted);
694 }
695 break;
696
697 case EVENT_EXCHANGE_SIM_IO_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
700 if (ar.exception == null && ar.result != null) {
701 request.result = ar.result;
702 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800703 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 break;
707
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 case CMD_SEND_ENVELOPE:
709 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000710 uiccPort = getUiccPortFromRequest(request);
711 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800713 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700714 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 } else {
716 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800717 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800719 break;
720
721 case EVENT_SEND_ENVELOPE_DONE:
722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800726 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800727 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700728 if (ar.result == null) {
729 loge("sendEnvelopeWithStatus: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("sendEnvelopeWithStatus: CommandException: " +
732 ar.exception);
733 } else {
734 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
735 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800738 break;
739
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 case CMD_OPEN_CHANNEL:
741 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000742 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800743 IccLogicalChannelRequest openChannelRequest =
744 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000745 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800747 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800748 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800752 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
753 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_OPEN_CHANNEL_DONE:
758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700760 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700762 int[] result = (int[]) ar.result;
763 int channelId = result[0];
764 byte[] selectResponse = null;
765 if (result.length > 1) {
766 selectResponse = new byte[result.length - 1];
767 for (int i = 1; i < result.length; ++i) {
768 selectResponse[i - 1] = (byte) result[i];
769 }
770 }
771 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800772 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800773
774 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700775 if (uiccPort == null) {
776 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
777 } else {
778 IccLogicalChannelRequest channelRequest =
779 (IccLogicalChannelRequest) request.argument;
780 channelRequest.channel = channelId;
781 uiccPort.onLogicalChannelOpened(channelRequest);
782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 if (ar.result == null) {
785 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700787 if (ar.exception != null) {
788 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
789 }
790
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700791 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800794 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700795 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700796 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700797 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700798 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700799 }
800 }
801 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800802 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700803 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700804 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700806 break;
807
808 case CMD_CLOSE_CHANNEL:
809 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000810 uiccPort = getUiccPortFromRequest(request);
811 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700812 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800813 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800814 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800815 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700816 } else {
817 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000818 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700819 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700820 break;
821
822 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null) {
826 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800827 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700828 if (uiccPort == null) {
829 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
830 } else {
831 final int channelId = (Integer) request.argument;
832 uiccPort.onLogicalChannelClosed(channelId);
833 }
Chen Xu540470b2021-12-14 17:15:47 -0800834 } else {
835 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800836 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800837 if (ar.exception instanceof CommandException) {
838 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
839 CommandException.Error error =
840 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800841 if (error == CommandException.Error.INVALID_ARGUMENTS) {
842 // should only throw exceptions from the binder threads.
843 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800844 "iccCloseLogicalChannel: invalid argument ");
845 }
846 } else {
847 loge("iccCloseLogicalChannel: Unknown exception");
848 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800849 request.result = (exception != null) ? exception :
850 new IllegalStateException(
851 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800852 }
853 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800854 break;
855
856 case CMD_NV_READ_ITEM:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800859 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
860 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800861 break;
862
863 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700868 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800869 request.result = "";
870 if (ar.result == null) {
871 loge("nvReadItem: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("nvReadItem: CommandException: " +
874 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700875 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800876 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700877 }
878 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700879 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700880 break;
881
Jake Hambye994d462014-02-03 13:10:13 -0800882 case CMD_NV_WRITE_ITEM:
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
885 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800886 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700887 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800888 break;
889
890 case EVENT_NV_WRITE_ITEM_DONE:
891 handleNullReturnEvent(msg, "nvWriteItem");
892 break;
893
894 case CMD_NV_WRITE_CDMA_PRL:
895 request = (MainThreadRequest) msg.obj;
896 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800897 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800898 break;
899
900 case EVENT_NV_WRITE_CDMA_PRL_DONE:
901 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
902 break;
903
chen xu6dac5ab2018-10-26 17:39:23 -0700904 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800905 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700906 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800908 break;
909
chen xu6dac5ab2018-10-26 17:39:23 -0700910 case EVENT_RESET_MODEM_CONFIG_DONE:
911 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800912 break;
913
Sooraj Sasindran37444802020-08-11 10:40:43 -0700914 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
917 request);
918 Phone phone = getPhoneFromRequest(request);
919 if (phone != null) {
920 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
921 } else {
922 loge("isNRDualConnectivityEnabled: No phone object");
923 request.result = false;
924 notifyRequester(request);
925 }
926 break;
927 }
928
929 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 // request.result must be set to something non-null
936 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700937 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700938 request.result = ar.result;
939 } else {
940 request.result = false;
941 }
942 if (ar.result == null) {
943 loge("isNRDualConnectivityEnabled: Empty response");
944 } else if (ar.exception instanceof CommandException) {
945 loge("isNRDualConnectivityEnabled: CommandException: "
946 + ar.exception);
947 } else {
948 loge("isNRDualConnectivityEnabled: Unknown exception");
949 }
950 }
951 notifyRequester(request);
952 break;
953
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700954 case CMD_IS_VONR_ENABLED: {
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
957 request);
958 Phone phone = getPhoneFromRequest(request);
959 if (phone != null) {
960 phone.isVoNrEnabled(onCompleted, request.workSource);
961 } else {
962 loge("isVoNrEnabled: No phone object");
963 request.result = false;
964 notifyRequester(request);
965 }
966 break;
967 }
968
969 case EVENT_IS_VONR_ENABLED_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 if (ar.exception == null && ar.result != null) {
973 request.result = ar.result;
974 } else {
975 // request.result must be set to something non-null
976 // for the calling thread to unblock
977 if (ar.result != null) {
978 request.result = ar.result;
979 } else {
980 request.result = false;
981 }
982 if (ar.result == null) {
983 loge("isVoNrEnabled: Empty response");
984 } else if (ar.exception instanceof CommandException) {
985 loge("isVoNrEnabled: CommandException: "
986 + ar.exception);
987 } else {
988 loge("isVoNrEnabled: Unknown exception");
989 }
990 }
991 notifyRequester(request);
992 break;
993
Sooraj Sasindran37444802020-08-11 10:40:43 -0700994 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
997 Phone phone = getPhoneFromRequest(request);
998 if (phone != null) {
999 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1000 request.workSource);
1001 } else {
1002 loge("enableNrDualConnectivity: No phone object");
1003 request.result =
1004 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1005 notifyRequester(request);
1006 }
1007 break;
1008 }
1009
1010 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result =
1015 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1016 } else {
1017 request.result =
1018 TelephonyManager
1019 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1020 if (ar.exception instanceof CommandException) {
1021 CommandException.Error error =
1022 ((CommandException) (ar.exception)).getCommandError();
1023 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1024 request.result =
1025 TelephonyManager
1026 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1028 request.result =
1029 TelephonyManager
1030 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001031 }
1032 loge("enableNrDualConnectivity" + ": CommandException: "
1033 + ar.exception);
1034 } else {
1035 loge("enableNrDualConnectivity" + ": Unknown exception");
1036 }
1037 }
1038 notifyRequester(request);
1039 break;
1040 }
1041
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001042 case CMD_ENABLE_VONR: {
1043 request = (MainThreadRequest) msg.obj;
1044 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1045 Phone phone = getPhoneFromRequest(request);
1046 if (phone != null) {
1047 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1048 request.workSource);
1049 } else {
1050 loge("setVoNrEnabled: No phone object");
1051 request.result =
1052 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1053 notifyRequester(request);
1054 }
1055 break;
1056 }
1057
1058 case EVENT_ENABLE_VONR_DONE: {
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
1061 if (ar.exception == null) {
1062 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1063 } else {
1064 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1065 if (ar.exception instanceof CommandException) {
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1069 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1070 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1071 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1072 } else {
1073 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1074 }
1075 loge("setVoNrEnabled" + ": CommandException: "
1076 + ar.exception);
1077 } else {
1078 loge("setVoNrEnabled" + ": Unknown exception");
1079 }
1080 }
1081 notifyRequester(request);
1082 break;
1083 }
1084
SongFerngWang3ef3e072020-12-21 16:41:52 +08001085 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001086 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001087 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1088 request);
1089 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 break;
1091
SongFerngWang3ef3e072020-12-21 16:41:52 +08001092 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null && ar.result != null) {
1096 request.result = ar.result; // Integer
1097 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301098 // request.result must be set to something non-null
1099 // for the calling thread to unblock
1100 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001101 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001102 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001103 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001104 loge("getAllowedNetworkTypesBitmask: CommandException: "
1105 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001106 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001108 }
1109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001110 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001111 break;
1112
SongFerngWang3ef3e072020-12-21 16:41:52 +08001113 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001114 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001115 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1116 request);
1117 Pair<Integer, Long> reasonWithNetworkTypes =
1118 (Pair<Integer, Long>) request.argument;
1119 getPhoneFromRequest(request).setAllowedNetworkTypes(
1120 reasonWithNetworkTypes.first,
1121 reasonWithNetworkTypes.second,
1122 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001123 break;
1124
SongFerngWang3ef3e072020-12-21 16:41:52 +08001125 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1126 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001127 break;
1128
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001129 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1130 request = (MainThreadRequest)msg.obj;
1131 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001132 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001133 break;
1134
1135 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1136 ar = (AsyncResult)msg.obj;
1137 request = (MainThreadRequest)ar.userObj;
1138 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001139 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001140 break;
1141
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001142 case CMD_SET_VOICEMAIL_NUMBER:
1143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1145 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001146 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1147 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001148 break;
1149
1150 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1151 handleNullReturnEvent(msg, "setVoicemailNumber");
1152 break;
1153
Stuart Scott54788802015-03-30 13:18:01 -07001154 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1155 request = (MainThreadRequest) msg.obj;
1156 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1157 request);
1158 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1159 break;
1160
1161 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1162 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1163 break;
1164
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 case CMD_PERFORM_NETWORK_SCAN:
1166 request = (MainThreadRequest) msg.obj;
1167 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1168 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1169 break;
1170
Hall Liu27d24262020-09-18 19:04:59 -07001171 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001172 request = (MainThreadRequest) msg.obj;
1173 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001174 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1175 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1176 request.argument;
1177 int callForwardingReason = args.first;
1178 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
1181 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001182 ar = (AsyncResult) msg.obj;
1183 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001184 TelephonyManager.CallForwardingInfoCallback callback =
1185 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1186 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001187 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001188 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001189 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1190 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1191 // Service Class is a bit mask per 3gpp 27.007. Search for
1192 // any service for voice call.
1193 if ((callForwardInfo.serviceClass
1194 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001195 callForwardingInfo = new CallForwardingInfo(
1196 callForwardInfo.status
1197 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001198 callForwardInfo.reason,
1199 callForwardInfo.number,
1200 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001201 break;
1202 }
1203 }
1204 // Didn't find a call forward info for voice call.
1205 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1207 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001208 }
Hall Liu27d24262020-09-18 19:04:59 -07001209 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001210 } else {
1211 if (ar.result == null) {
1212 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1213 }
1214 if (ar.exception != null) {
1215 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1216 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001217 int errorCode = TelephonyManager
1218 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001219 if (ar.exception instanceof CommandException) {
1220 CommandException.Error error =
1221 ((CommandException) (ar.exception)).getCommandError();
1222 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001223 errorCode = TelephonyManager
1224 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001225 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001226 errorCode = TelephonyManager
1227 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001228 }
1229 }
Hall Liu27d24262020-09-18 19:04:59 -07001230 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001231 }
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 request = (MainThreadRequest) msg.obj;
1237 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001238 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001239 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001240 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1241 request.argument).first;
1242 request.phone.setCallForwardingOption(
1243 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001244 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001245 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001246 callForwardingInfoToSet.getReason(),
1247 callForwardingInfoToSet.getNumber(),
1248 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1249 break;
Hall Liu27d24262020-09-18 19:04:59 -07001250 }
Shuo Qian4a594052020-01-23 11:59:30 -08001251
Hall Liu27d24262020-09-18 19:04:59 -07001252 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001253 ar = (AsyncResult) msg.obj;
1254 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001255 Consumer<Integer> callback =
1256 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1257 request.argument).second;
1258 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001259 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001260 int errorCode = TelephonyManager.CallForwardingInfoCallback
1261 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001262 if (ar.exception instanceof CommandException) {
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001266 errorCode = TelephonyManager.CallForwardingInfoCallback
1267 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001268 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001269 errorCode = TelephonyManager.CallForwardingInfoCallback
1270 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001271 }
1272 }
1273 callback.accept(errorCode);
1274 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001275 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001276 }
Shuo Qian4a594052020-01-23 11:59:30 -08001277 break;
Hall Liu27d24262020-09-18 19:04:59 -07001278 }
Shuo Qian4a594052020-01-23 11:59:30 -08001279
Hall Liu27d24262020-09-18 19:04:59 -07001280 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1283 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1284 break;
Hall Liu27d24262020-09-18 19:04:59 -07001285 }
Shuo Qian4a594052020-01-23 11:59:30 -08001286
Hall Liu27d24262020-09-18 19:04:59 -07001287 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001288 ar = (AsyncResult) msg.obj;
1289 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001290 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001291 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001292 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001293 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001294 // Service Class is a bit mask per 3gpp 27.007.
1295 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001296 if (callForwardResults.length > 1
1297 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001298 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001299 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001300 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1301 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001302 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001303 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001304 }
1305 } else {
1306 if (ar.result == null) {
1307 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1308 }
1309 if (ar.exception != null) {
1310 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1311 }
1312 if (ar.exception instanceof CommandException) {
1313 CommandException.Error error =
1314 ((CommandException) (ar.exception)).getCommandError();
1315 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001316 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001317 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001318 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1319 callWaitingStatus =
1320 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001321 }
1322 }
1323 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001324 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001325 break;
Hall Liu27d24262020-09-18 19:04:59 -07001326 }
Shuo Qian4a594052020-01-23 11:59:30 -08001327
Hall Liu27d24262020-09-18 19:04:59 -07001328 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001331 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1332 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001333 break;
Hall Liu27d24262020-09-18 19:04:59 -07001334 }
Shuo Qian4a594052020-01-23 11:59:30 -08001335
Hall Liu27d24262020-09-18 19:04:59 -07001336 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001339 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1340 Consumer<Integer> callback =
1341 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1342 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001343 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001344 if (ar.exception instanceof CommandException) {
1345 CommandException.Error error =
1346 ((CommandException) (ar.exception)).getCommandError();
1347 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1348 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001349 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1350 callback.accept(
1351 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001352 } else {
1353 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1354 }
1355 } else {
1356 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1357 }
1358 } else {
1359 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1360 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001361 }
Shuo Qian4a594052020-01-23 11:59:30 -08001362 break;
Hall Liu27d24262020-09-18 19:04:59 -07001363 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001364 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 CellNetworkScanResult cellScanResult;
1368 if (ar.exception == null && ar.result != null) {
1369 cellScanResult = new CellNetworkScanResult(
1370 CellNetworkScanResult.STATUS_SUCCESS,
1371 (List<OperatorInfo>) ar.result);
1372 } else {
1373 if (ar.result == null) {
1374 loge("getCellNetworkScanResults: Empty response");
1375 }
1376 if (ar.exception != null) {
1377 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1378 }
1379 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1380 if (ar.exception instanceof CommandException) {
1381 CommandException.Error error =
1382 ((CommandException) (ar.exception)).getCommandError();
1383 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1384 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1385 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1386 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1387 }
1388 }
1389 cellScanResult = new CellNetworkScanResult(errorCode, null);
1390 }
1391 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001392 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001393 break;
1394
1395 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1396 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001397 ManualNetworkSelectionArgument selArg =
1398 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001399 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1400 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001401 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1402 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001403 break;
1404
1405 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 if (ar.exception == null) {
1409 request.result = true;
1410 } else {
1411 request.result = false;
1412 loge("setNetworkSelectionModeManual " + ar.exception);
1413 }
1414 notifyRequester(request);
1415 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001416 break;
1417
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001418 case CMD_GET_MODEM_ACTIVITY_INFO:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001421 if (defaultPhone != null) {
1422 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001423 } else {
1424 ResultReceiver result = (ResultReceiver) request.argument;
1425 Bundle bundle = new Bundle();
1426 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001427 new ModemActivityInfo(0, 0, 0,
1428 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001429 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001430 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001431 break;
1432
Hall Liud0f208c2020-10-14 16:54:44 -07001433 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001436 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001437 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001438 if (mLastModemActivityInfo == null) {
1439 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1440 mLastModemActivitySpecificInfo[0] =
1441 new ActivityStatsTechSpecificInfo(
1442 0,
1443 0,
1444 new int[ModemActivityInfo.getNumTxPowerLevels()],
1445 0);
1446 mLastModemActivityInfo =
1447 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1448 }
1449
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001451 // Update the last modem activity info and the result of the request.
1452 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1453 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001454 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001455 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001456 mLastModemActivityInfo =
1457 new ModemActivityInfo(
1458 mLastModemActivityInfo.getTimestampMillis(),
1459 mLastModemActivityInfo.getSleepTimeMillis(),
1460 mLastModemActivityInfo.getIdleTimeMillis(),
1461 mLastModemActivitySpecificInfo);
1462
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001463 } else {
1464 if (ar.result == null) {
1465 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001466 error = TelephonyManager.ModemActivityInfoException
1467 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001468 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001469 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001470 error = TelephonyManager.ModemActivityInfoException
1471 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472 } else {
1473 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001474 error = TelephonyManager.ModemActivityInfoException
1475 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001476 }
1477 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001478 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001479 if (mLastModemActivityInfo != null) {
1480 bundle.putParcelable(
1481 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1482 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001483 } else {
1484 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1485 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001486 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001487 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001488 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001489 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001490
Meng Wang1a7c35a2016-05-05 20:56:15 -07001491 case CMD_SET_ALLOWED_CARRIERS:
1492 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001493 CarrierRestrictionRules argument =
1494 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001495 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001496 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001497 break;
1498
1499 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 if (ar.exception == null && ar.result != null) {
1503 request.result = ar.result;
1504 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001505 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1506 if (ar.exception instanceof CommandException) {
1507 loge("setAllowedCarriers: CommandException: " + ar.exception);
1508 CommandException.Error error =
1509 ((CommandException) (ar.exception)).getCommandError();
1510 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1511 request.result =
1512 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1513 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001514 } else {
1515 loge("setAllowedCarriers: Unknown exception");
1516 }
1517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001518 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001519 break;
1520
1521 case CMD_GET_ALLOWED_CARRIERS:
1522 request = (MainThreadRequest) msg.obj;
1523 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001524 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001525 break;
1526
1527 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null && ar.result != null) {
1531 request.result = ar.result;
1532 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001533 request.result = new IllegalStateException(
1534 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001535 if (ar.result == null) {
1536 loge("getAllowedCarriers: Empty response");
1537 } else if (ar.exception instanceof CommandException) {
1538 loge("getAllowedCarriers: CommandException: " +
1539 ar.exception);
1540 } else {
1541 loge("getAllowedCarriers: Unknown exception");
1542 }
1543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001544 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001545 break;
1546
Nathan Haroldb3014052017-01-25 15:57:32 -08001547 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1548 ar = (AsyncResult) msg.obj;
1549 request = (MainThreadRequest) ar.userObj;
1550 if (ar.exception == null && ar.result != null) {
1551 request.result = ar.result;
1552 } else {
1553 request.result = new IllegalArgumentException(
1554 "Failed to retrieve Forbidden Plmns");
1555 if (ar.result == null) {
1556 loge("getForbiddenPlmns: Empty response");
1557 } else {
1558 loge("getForbiddenPlmns: Unknown exception");
1559 }
1560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001561 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001562 break;
1563
1564 case CMD_GET_FORBIDDEN_PLMNS:
1565 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001566 uiccPort = getUiccPortFromRequest(request);
1567 if (uiccPort == null) {
1568 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001569 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001570 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001572 break;
1573 }
1574 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001575 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001576 if (uiccApp == null) {
1577 loge("getForbiddenPlmns() no app with specified type -- "
1578 + appType);
1579 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001580 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001581 break;
1582 } else {
1583 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1584 + " specified type -- " + appType);
1585 }
1586 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1587 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1588 onCompleted);
1589 break;
1590
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001591 case CMD_SWITCH_SLOTS:
1592 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001593 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001594 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001595 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001596 break;
1597
1598 case EVENT_SWITCH_SLOTS_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001602 notifyRequester(request);
1603 break;
1604 case CMD_GET_NETWORK_SELECTION_MODE:
1605 request = (MainThreadRequest) msg.obj;
1606 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1607 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1608 break;
1609
1610 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception != null) {
1614 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1615 } else {
1616 int mode = ((int[]) ar.result)[0];
1617 if (mode == 0) {
1618 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1619 } else {
1620 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1621 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001623 notifyRequester(request);
1624 break;
1625 case CMD_GET_CDMA_ROAMING_MODE:
1626 request = (MainThreadRequest) msg.obj;
1627 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1628 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1629 break;
1630 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1631 ar = (AsyncResult) msg.obj;
1632 request = (MainThreadRequest) ar.userObj;
1633 if (ar.exception != null) {
1634 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1635 } else {
1636 request.result = ((int[]) ar.result)[0];
1637 }
1638 notifyRequester(request);
1639 break;
1640 case CMD_SET_CDMA_ROAMING_MODE:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1643 int mode = (int) request.argument;
1644 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1645 break;
1646 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1647 ar = (AsyncResult) msg.obj;
1648 request = (MainThreadRequest) ar.userObj;
1649 request.result = ar.exception == null;
1650 notifyRequester(request);
1651 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001652 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1653 request = (MainThreadRequest) msg.obj;
1654 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1655 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1656 break;
1657 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 if (ar.exception != null) {
1661 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1662 } else {
1663 request.result = ((int[]) ar.result)[0];
1664 }
1665 notifyRequester(request);
1666 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001667 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1670 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001671 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1672 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001673 break;
1674 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 request.result = ar.exception == null;
1678 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001679 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001680 case CMD_GET_ALL_CELL_INFO:
1681 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001682 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001683 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001684 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 case EVENT_GET_ALL_CELL_INFO_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001688 // If a timeout occurs, the response will be null
1689 request.result = (ar.exception == null && ar.result != null)
1690 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001691 synchronized (request) {
1692 request.notifyAll();
1693 }
1694 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001695 case CMD_REQUEST_CELL_INFO_UPDATE:
1696 request = (MainThreadRequest) msg.obj;
1697 request.phone.requestCellInfoUpdate(request.workSource,
1698 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1699 break;
1700 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1701 ar = (AsyncResult) msg.obj;
1702 request = (MainThreadRequest) ar.userObj;
1703 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1704 try {
1705 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001706 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001707 cb.onError(
1708 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1709 ar.exception.getClass().getName(),
1710 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001711 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001713 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001714 } else {
1715 // use the result as returned
1716 cb.onCellInfo((List<CellInfo>) ar.result);
1717 }
1718 } catch (RemoteException re) {
1719 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1720 }
1721 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001722 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001723 request = (MainThreadRequest) msg.obj;
1724 WorkSource ws = (WorkSource) request.argument;
1725 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001726 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001727 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001728 }
1729 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception == null) {
1733 request.result = ar.result;
1734 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001735 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001736 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001737 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001738 }
1739
1740 synchronized (request) {
1741 request.notifyAll();
1742 }
1743 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 }
chen xu6dac5ab2018-10-26 17:39:23 -07001745 case CMD_MODEM_REBOOT:
1746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001748 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001749 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001750 case EVENT_CMD_MODEM_REBOOT_DONE:
1751 handleNullReturnEvent(msg, "rebootModem");
1752 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001753 case CMD_REQUEST_ENABLE_MODEM:
1754 request = (MainThreadRequest) msg.obj;
1755 boolean enable = (boolean) request.argument;
1756 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001757 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001758 PhoneConfigurationManager.getInstance()
1759 .enablePhone(request.phone, enable, onCompleted);
1760 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001761 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001762 ar = (AsyncResult) msg.obj;
1763 request = (MainThreadRequest) ar.userObj;
1764 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001765 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001766 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001767 if ((boolean) request.result) {
1768 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1769 updateModemStateMetrics();
1770 } else {
1771 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1772 + ar.exception);
1773 }
1774 notifyRequester(request);
1775 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001776 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001777 case CMD_GET_MODEM_STATUS:
1778 request = (MainThreadRequest) msg.obj;
1779 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1780 PhoneConfigurationManager.getInstance()
1781 .getPhoneStatusFromModem(request.phone, onCompleted);
1782 break;
1783 case EVENT_GET_MODEM_STATUS_DONE:
1784 ar = (AsyncResult) msg.obj;
1785 request = (MainThreadRequest) ar.userObj;
1786 int id = request.phone.getPhoneId();
1787 if (ar.exception == null && ar.result != null) {
1788 request.result = ar.result;
1789 //update the cache as modem status has changed
1790 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1791 (boolean) request.result);
1792 } else {
1793 // Return true if modem status cannot be retrieved. For most cases,
1794 // modem status is on. And for older version modems, GET_MODEM_STATUS
1795 // and disable modem are not supported. Modem is always on.
1796 // TODO: this should be fixed in R to support a third
1797 // status UNKNOWN b/131631629
1798 request.result = true;
1799 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1800 + ar.exception);
1801 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001802 notifyRequester(request);
1803 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001804 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1805 request = (MainThreadRequest) msg.obj;
1806 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1807 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1808 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1809 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1810 break;
1811 }
1812 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1813 ar = (AsyncResult) msg.obj;
1814 request = (MainThreadRequest) ar.userObj;
1815 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1816 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1817 args.second.accept(ar.exception == null);
1818 notifyRequester(request);
1819 break;
1820 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001821 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1822 request = (MainThreadRequest) msg.obj;
1823 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1824 Phone phone = getPhoneFromRequest(request);
1825 if (phone != null) {
1826 phone.getSystemSelectionChannels(onCompleted);
1827 } else {
1828 loge("getSystemSelectionChannels: No phone object");
1829 request.result = new ArrayList<RadioAccessSpecifier>();
1830 notifyRequester(request);
1831 }
1832 break;
1833 }
1834 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1835 ar = (AsyncResult) msg.obj;
1836 request = (MainThreadRequest) ar.userObj;
1837 if (ar.exception == null && ar.result != null) {
1838 request.result = ar.result;
1839 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001840 request.result = new IllegalStateException(
1841 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001842 if (ar.result == null) {
1843 loge("getSystemSelectionChannels: Empty response");
1844 } else {
1845 loge("getSystemSelectionChannels: Unknown exception");
1846 }
1847 }
1848 notifyRequester(request);
1849 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001850 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1851 ar = (AsyncResult) msg.obj;
1852 request = (MainThreadRequest) ar.userObj;
1853 if (ar.exception == null && ar.result != null) {
1854 request.result = ar.result;
1855 } else {
1856 request.result = -1;
1857 loge("Failed to set Forbidden Plmns");
1858 if (ar.result == null) {
1859 loge("setForbidenPlmns: Empty response");
1860 } else if (ar.exception != null) {
1861 loge("setForbiddenPlmns: Exception: " + ar.exception);
1862 request.result = -1;
1863 } else {
1864 loge("setForbiddenPlmns: Unknown exception");
1865 }
1866 }
1867 notifyRequester(request);
1868 break;
1869 case CMD_SET_FORBIDDEN_PLMNS:
1870 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001871 uiccPort = getUiccPortFromRequest(request);
1872 if (uiccPort == null) {
1873 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001874 request.result = -1;
1875 notifyRequester(request);
1876 break;
1877 }
1878 Pair<Integer, List<String>> setFplmnsArgs =
1879 (Pair<Integer, List<String>>) request.argument;
1880 appType = setFplmnsArgs.first;
1881 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001882 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001883 if (uiccApp == null) {
1884 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1885 request.result = -1;
1886 loge("Failed to get UICC App");
1887 notifyRequester(request);
1888 } else {
1889 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1890 ((SIMRecords) uiccApp.getIccRecords())
1891 .setForbiddenPlmns(onCompleted, fplmns);
1892 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001893 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001894 case CMD_ERASE_MODEM_CONFIG:
1895 request = (MainThreadRequest) msg.obj;
1896 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1897 defaultPhone.eraseModemConfig(onCompleted);
1898 break;
1899 case EVENT_ERASE_MODEM_CONFIG_DONE:
1900 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001901 break;
zoey chene02881a2019-12-30 16:11:23 +08001902
Kai Shif70f46f2021-03-03 13:59:46 -08001903 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1904 request = (MainThreadRequest) msg.obj;
1905 request.result = defaultPhone.eraseDataInSharedPreferences();
1906 notifyRequester(request);
1907 break;
1908
zoey chene02881a2019-12-30 16:11:23 +08001909 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1910 request = (MainThreadRequest) msg.obj;
1911 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1912 Pair<String, String> changed = (Pair<String, String>) request.argument;
1913 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1914 changed.first, changed.second, onCompleted);
1915 break;
1916 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1917 ar = (AsyncResult) msg.obj;
1918 request = (MainThreadRequest) ar.userObj;
1919 if (ar.exception == null) {
1920 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001921 // If the operation is successful, update the PIN storage
1922 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1923 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001924 UiccController.getInstance().getPinStorage()
1925 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001926 } else {
1927 request.result = msg.arg1;
1928 }
1929 notifyRequester(request);
1930 break;
1931
Michele Berionne5e411512020-11-13 02:36:59 +00001932 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1935 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1936 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1937 enabled.first, enabled.second, onCompleted);
1938 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001939 }
zoey chene02881a2019-12-30 16:11:23 +08001940 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 if (ar.exception == null) {
1944 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001945 // If the operation is successful, update the PIN storage
1946 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1947 int phoneId = getPhoneFromRequest(request).getPhoneId();
1948 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001949 UiccController.getInstance().getPinStorage()
1950 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001951 } else {
1952 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1953 }
zoey chene02881a2019-12-30 16:11:23 +08001954 } else {
1955 request.result = msg.arg1;
1956 }
Michele Berionne5e411512020-11-13 02:36:59 +00001957
1958
zoey chene02881a2019-12-30 16:11:23 +08001959 notifyRequester(request);
1960 break;
1961
Peter Wangdafb9ac2020-01-15 14:13:38 -08001962 case MSG_NOTIFY_USER_ACTIVITY:
1963 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001964 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001965 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1966 getDefaultPhone().getContext().sendBroadcastAsUser(
1967 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1968 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001969
1970 case CMD_SET_DATA_THROTTLING: {
1971 request = (MainThreadRequest) msg.obj;
1972 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1973 DataThrottlingRequest dataThrottlingRequest =
1974 (DataThrottlingRequest) request.argument;
1975 Phone phone = getPhoneFromRequest(request);
1976 if (phone != null) {
1977 phone.setDataThrottling(onCompleted,
1978 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1979 dataThrottlingRequest.getCompletionDurationMillis());
1980 } else {
1981 loge("setDataThrottling: No phone object");
1982 request.result =
1983 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1984 notifyRequester(request);
1985 }
1986
1987 break;
1988 }
1989 case EVENT_SET_DATA_THROTTLING_DONE:
1990 ar = (AsyncResult) msg.obj;
1991 request = (MainThreadRequest) ar.userObj;
1992
1993 if (ar.exception == null) {
1994 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1995 } else if (ar.exception instanceof CommandException) {
1996 loge("setDataThrottling: CommandException: " + ar.exception);
1997 CommandException.Error error =
1998 ((CommandException) (ar.exception)).getCommandError();
1999
2000 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2001 request.result = TelephonyManager
2002 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2003 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2004 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002005 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2006 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002007 } else {
2008 request.result =
2009 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2010 }
2011 } else {
2012 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2013 }
2014 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2015 notifyRequester(request);
2016 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002017
2018 case CMD_SET_SIM_POWER: {
2019 request = (MainThreadRequest) msg.obj;
2020 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2021 request = (MainThreadRequest) msg.obj;
2022 int stateToSet =
2023 ((Pair<Integer, IIntegerConsumer>)
2024 request.argument).first;
2025 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2026 break;
2027 }
2028 case EVENT_SET_SIM_POWER_DONE: {
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 IIntegerConsumer callback =
2032 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2033 if (ar.exception != null) {
2034 loge("setSimPower exception: " + ar.exception);
2035 int errorCode = TelephonyManager.CallForwardingInfoCallback
2036 .RESULT_ERROR_UNKNOWN;
2037 if (ar.exception instanceof CommandException) {
2038 CommandException.Error error =
2039 ((CommandException) (ar.exception)).getCommandError();
2040 if (error == CommandException.Error.SIM_ERR) {
2041 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2042 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2043 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2044 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2045 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2046 } else {
2047 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2048 }
2049 }
2050 try {
2051 callback.accept(errorCode);
2052 } catch (RemoteException e) {
2053 // Ignore if the remote process is no longer available to call back.
2054 Log.w(LOG_TAG, "setSimPower: callback not available.");
2055 }
2056 } else {
2057 try {
2058 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2059 } catch (RemoteException e) {
2060 // Ignore if the remote process is no longer available to call back.
2061 Log.w(LOG_TAG, "setSimPower: callback not available.");
2062 }
2063 }
2064 break;
2065 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002066 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2067 request = (MainThreadRequest) msg.obj;
2068
2069 final Phone phone = getPhoneFromRequest(request);
2070 if (phone == null || phone.getServiceStateTracker() == null) {
2071 request.result = new IllegalStateException("Phone or SST is null");
2072 notifyRequester(request);
2073 break;
2074 }
2075
2076 Pair<Integer, SignalStrengthUpdateRequest> pair =
2077 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2078 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2079 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002080 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002081 request.subId, pair.first /*callingUid*/,
2082 pair.second /*request*/, onCompleted);
2083 break;
2084 }
2085 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2086 ar = (AsyncResult) msg.obj;
2087 request = (MainThreadRequest) ar.userObj;
2088 // request.result will be the exception of ar if present, true otherwise.
2089 // Be cautious not to leave result null which will wait() forever
2090 request.result = ar.exception != null ? ar.exception : true;
2091 notifyRequester(request);
2092 break;
2093 }
2094 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2095 request = (MainThreadRequest) msg.obj;
2096
2097 Phone phone = getPhoneFromRequest(request);
2098 if (phone == null || phone.getServiceStateTracker() == null) {
2099 request.result = new IllegalStateException("Phone or SST is null");
2100 notifyRequester(request);
2101 break;
2102 }
2103
2104 Pair<Integer, SignalStrengthUpdateRequest> pair =
2105 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2106 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2107 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002108 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002109 request.subId, pair.first /*callingUid*/,
2110 pair.second /*request*/, onCompleted);
2111 break;
2112 }
2113 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2114 ar = (AsyncResult) msg.obj;
2115 request = (MainThreadRequest) ar.userObj;
2116 request.result = ar.exception != null ? ar.exception : true;
2117 notifyRequester(request);
2118 break;
2119 }
Jordan Liu109698e2020-11-24 14:50:34 -08002120
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 case CMD_GET_SLICING_CONFIG: {
2122 request = (MainThreadRequest) msg.obj;
2123 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2124 request.phone.getSlicingConfig(onCompleted);
2125 break;
2126 }
2127 case EVENT_GET_SLICING_CONFIG_DONE: {
2128 ar = (AsyncResult) msg.obj;
2129 request = (MainThreadRequest) ar.userObj;
2130 ResultReceiver result = (ResultReceiver) request.argument;
2131
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002132 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002133 Bundle bundle = new Bundle();
2134 int resultCode = 0;
2135 if (ar.exception != null) {
2136 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2137 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002138 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002139 } else if (ar.result == null) {
2140 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002141 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002142 } else {
2143 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002144 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2145 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002146 }
2147
2148 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002149 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002150 }
2151 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2152 result.send(resultCode, bundle);
2153 notifyRequester(request);
2154 break;
2155 }
2156
Sarah Chin71b3a852022-09-28 15:54:19 -07002157 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002158 request = (MainThreadRequest) msg.obj;
2159 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002160 PurchasePremiumCapabilityArgument arg =
2161 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002162 SliceStore.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002163 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002164 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002165 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002166
Sarah Chin71b3a852022-09-28 15:54:19 -07002167 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002168 ar = (AsyncResult) msg.obj;
2169 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002170 PurchasePremiumCapabilityArgument arg =
2171 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002172 try {
2173 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002174 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002175 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002176 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002177 + ", result= "
2178 + TelephonyManager.convertPurchaseResultToString(result));
2179 } catch (RemoteException e) {
2180 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002181 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002182 + " failed: " + e;
2183 if (DBG) log(logStr);
2184 AnomalyReporter.reportAnomaly(
2185 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2186 }
2187 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002188 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002189
Michele Berionne5e411512020-11-13 02:36:59 +00002190 case CMD_PREPARE_UNATTENDED_REBOOT:
2191 request = (MainThreadRequest) msg.obj;
2192 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002193 UiccController.getInstance().getPinStorage()
2194 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002195 notifyRequester(request);
2196 break;
2197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 default:
2199 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2200 break;
2201 }
2202 }
Jake Hambye994d462014-02-03 13:10:13 -08002203
Pengquan Menga1bb6272018-09-06 09:59:22 -07002204 private void notifyRequester(MainThreadRequest request) {
2205 synchronized (request) {
2206 request.notifyAll();
2207 }
2208 }
2209
Jake Hambye994d462014-02-03 13:10:13 -08002210 private void handleNullReturnEvent(Message msg, String command) {
2211 AsyncResult ar = (AsyncResult) msg.obj;
2212 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2213 if (ar.exception == null) {
2214 request.result = true;
2215 } else {
2216 request.result = false;
2217 if (ar.exception instanceof CommandException) {
2218 loge(command + ": CommandException: " + ar.exception);
2219 } else {
2220 loge(command + ": Unknown exception");
2221 }
2222 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002223 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 }
2226
2227 /**
2228 * Posts the specified command to be executed on the main thread,
2229 * waits for the request to complete, and returns the result.
2230 * @see #sendRequestAsync
2231 */
2232 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002233 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2234 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002235 }
2236
2237 /**
2238 * Posts the specified command to be executed on the main thread,
2239 * waits for the request to complete, and returns the result.
2240 * @see #sendRequestAsync
2241 */
2242 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2243 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002244 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002245 }
2246
2247 /**
2248 * Posts the specified command to be executed on the main thread,
2249 * waits for the request to complete, and returns the result.
2250 * @see #sendRequestAsync
2251 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002252 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002253 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2254 }
2255
2256 /**
2257 * Posts the specified command to be executed on the main thread,
2258 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2259 * if not timeout or null otherwise.
2260 * @see #sendRequestAsync
2261 */
2262 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2263 long timeoutInMs) {
2264 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002265 }
2266
2267 /**
2268 * Posts the specified command to be executed on the main thread,
2269 * waits for the request to complete, and returns the result.
2270 * @see #sendRequestAsync
2271 */
Nathan Harold92bed182018-10-12 18:16:49 -07002272 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002273 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002274 }
2275
2276 /**
2277 * Posts the specified command to be executed on the main thread,
2278 * waits for the request to complete, and returns the result.
2279 * @see #sendRequestAsync
2280 */
2281 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002282 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2283 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002284 }
2285
2286 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002287 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2288 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2289 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002290 * @see #sendRequestAsync
2291 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002292 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2293 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2295 throw new RuntimeException("This method will deadlock if called from the main thread.");
2296 }
2297
Nathan Harold92bed182018-10-12 18:16:49 -07002298 MainThreadRequest request = null;
2299 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2300 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2301 } else if (phone != null) {
2302 request = new MainThreadRequest(argument, phone, workSource);
2303 } else {
2304 request = new MainThreadRequest(argument, subId, workSource);
2305 }
2306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 Message msg = mMainThreadHandler.obtainMessage(command, request);
2308 msg.sendToTarget();
2309
Rambo Wang0f050d82021-02-12 11:43:36 -08002310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002312 if (timeoutInMs >= 0) {
2313 // Wait for at least timeoutInMs before returning null request result
2314 long now = SystemClock.elapsedRealtime();
2315 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002316 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002317 try {
2318 request.wait(deadline - now);
2319 } catch (InterruptedException e) {
2320 // Do nothing, go back and check if request is completed or timeout
2321 } finally {
2322 now = SystemClock.elapsedRealtime();
2323 }
2324 }
2325 } else {
2326 // Wait for the request to complete
2327 while (request.result == null) {
2328 try {
2329 request.wait();
2330 } catch (InterruptedException e) {
2331 // Do nothing, go back and wait until the request is complete
2332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334 }
2335 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002336 if (request.result == null) {
2337 Log.wtf(LOG_TAG,
2338 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 return request.result;
2341 }
2342
2343 /**
2344 * Asynchronous ("fire and forget") version of sendRequest():
2345 * Posts the specified command to be executed on the main thread, and
2346 * returns immediately.
2347 * @see #sendRequest
2348 */
2349 private void sendRequestAsync(int command) {
2350 mMainThreadHandler.sendEmptyMessage(command);
2351 }
2352
2353 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002354 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002355 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002356 */
2357 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002358 sendRequestAsync(command, argument, null, null);
2359 }
2360
2361 /**
2362 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2363 * @see {@link #sendRequest(int,Object)}
2364 */
2365 private void sendRequestAsync(
2366 int command, Object argument, Phone phone, WorkSource workSource) {
2367 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002368 Message msg = mMainThreadHandler.obtainMessage(command, request);
2369 msg.sendToTarget();
2370 }
2371
2372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 * Initialize the singleton PhoneInterfaceManager instance.
2374 * This is only done once, at startup, from PhoneApp.onCreate().
2375 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002376 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 synchronized (PhoneInterfaceManager.class) {
2378 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002379 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 } else {
2381 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2382 }
2383 return sInstance;
2384 }
2385 }
2386
2387 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002388 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002391 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002392 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002394 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002397 mTelephonySharedPreferences =
2398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002401 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002402 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002403 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 publish();
2405 }
2406
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002407 private Phone getDefaultPhone() {
2408 Phone thePhone = getPhone(getDefaultSubscription());
2409 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2410 }
2411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 private void publish() {
2413 if (DBG) log("publish: " + this);
2414
Peter Wangc035ce42020-01-08 21:00:22 -08002415 TelephonyFrameworkInitializer
2416 .getTelephonyServiceManager()
2417 .getTelephonyServiceRegisterer()
2418 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
Stuart Scott584921c2015-01-15 17:10:34 -08002421 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002422 if (request.phone != null) {
2423 return request.phone;
2424 } else {
2425 return getPhoneFromSubId(request.subId);
2426 }
2427 }
2428
2429 private Phone getPhoneFromSubId(int subId) {
2430 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2431 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002432 }
2433
Rambo Wange53e07d2022-05-10 13:01:13 -07002434 @Nullable
2435 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 Phone phone = getPhoneFromRequest(request);
2437 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002438 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002439 }
2440
Wink Saville36469e72014-06-11 15:17:00 -07002441 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002442 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002443 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445
Kai Shif70f46f2021-03-03 13:59:46 -08002446 private void sendEraseModemConfig(@NonNull Phone phone) {
2447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2449 }
2450
2451 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2452 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2453 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002454 }
2455
Peter Wang44b186e2020-01-13 23:33:09 -08002456 private boolean isImsAvailableOnDevice() {
2457 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2458 if (pm == null) {
2459 // For some reason package manger is not available.. This will fail internally anyway,
2460 // so do not throw error and allow.
2461 return true;
2462 }
2463 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2464 }
2465
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002467 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Wink Savilleb564aae2014-10-23 10:18:09 -07002470 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 if (DBG) log("dial: " + number);
2472 // No permission check needed here: This is just a wrapper around the
2473 // ACTION_DIAL intent, which is available to any app since it puts up
2474 // the UI before it does anything.
2475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
2478 String url = createTelUrl(number);
2479 if (url == null) {
2480 return;
2481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483 // PENDING: should we just silently fail if phone is offhook or ringing?
2484 PhoneConstants.State state = mCM.getState(subId);
2485 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2486 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2487 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2488 mApp.startActivity(intent);
2489 }
2490 } finally {
2491 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 }
2493 }
2494
2495 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002496 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002497 }
2498
Wink Savilleb564aae2014-10-23 10:18:09 -07002499 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 if (DBG) log("call: " + number);
2501
2502 // This is just a wrapper around the ACTION_CALL intent, but we still
2503 // need to do a permission check since we're calling startActivity()
2504 // from the context of the phone app.
2505 enforceCallPermission();
2506
Jordan Liu1617b712019-07-10 15:06:26 -07002507 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 != AppOpsManager.MODE_ALLOWED) {
2509 return;
2510 }
2511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 String url = createTelUrl(number);
2515 if (url == null) {
2516 return;
2517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519 boolean isValid = false;
2520 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2521 if (slist != null) {
2522 for (SubscriptionInfo subInfoRecord : slist) {
2523 if (subInfoRecord.getSubscriptionId() == subId) {
2524 isValid = true;
2525 break;
2526 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002527 }
Wink Saville08874612014-08-31 19:19:58 -07002528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 if (!isValid) {
2530 return;
2531 }
Wink Saville08874612014-08-31 19:19:58 -07002532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2534 intent.putExtra(SUBSCRIPTION_KEY, subId);
2535 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2536 mApp.startActivity(intent);
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
2541
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002543 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002544 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2545 }
2546
Wink Savilleb564aae2014-10-23 10:18:09 -07002547 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002548 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002549 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2550 }
2551
Wink Savilleb564aae2014-10-23 10:18:09 -07002552 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002557 Phone phone = getPhone(subId);
2558 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 checkSimPin.start();
2560 return checkSimPin.unlockSim(null, pin);
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002571 Phone phone = getPhone(subId);
2572 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573 checkSimPuk.start();
2574 return checkSimPuk.unlockSim(puk, pin);
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002578 }
2579
2580 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002581 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 * a synchronous one.
2583 */
2584 private static class UnlockSim extends Thread {
2585
2586 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002587 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002588
2589 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002590 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2591 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 // For replies from SimCard interface
2594 private Handler mHandler;
2595
2596 // For async handler to identify request type
2597 private static final int SUPPLY_PIN_COMPLETE = 100;
2598
Michele Berionne5e411512020-11-13 02:36:59 +00002599 UnlockSim(int phoneId, IccCard simCard) {
2600 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 mSimCard = simCard;
2602 }
2603
2604 @Override
2605 public void run() {
2606 Looper.prepare();
2607 synchronized (UnlockSim.this) {
2608 mHandler = new Handler() {
2609 @Override
2610 public void handleMessage(Message msg) {
2611 AsyncResult ar = (AsyncResult) msg.obj;
2612 switch (msg.what) {
2613 case SUPPLY_PIN_COMPLETE:
2614 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2615 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002616 mRetryCount = msg.arg1;
2617 if (ar.exception != null) {
2618 if (ar.exception instanceof CommandException &&
2619 ((CommandException)(ar.exception)).getCommandError()
2620 == CommandException.Error.PASSWORD_INCORRECT) {
2621 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002622 } //When UiccCardApp dispose,handle message and return exception
2623 else if (ar.exception instanceof CommandException &&
2624 ((CommandException) (ar.exception)).getCommandError()
2625 == CommandException.Error.ABORTED) {
2626 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002627 } else {
2628 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2629 }
2630 } else {
2631 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 mDone = true;
2634 UnlockSim.this.notifyAll();
2635 }
2636 break;
2637 }
2638 }
2639 };
2640 UnlockSim.this.notifyAll();
2641 }
2642 Looper.loop();
2643 }
2644
2645 /*
2646 * Use PIN or PUK to unlock SIM card
2647 *
2648 * If PUK is null, unlock SIM card with PIN
2649 *
2650 * If PUK is not null, unlock SIM card with PUK and set PIN code
2651 */
Wink Saville9de0f752013-10-22 19:04:03 -07002652 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653
2654 while (mHandler == null) {
2655 try {
2656 wait();
2657 } catch (InterruptedException e) {
2658 Thread.currentThread().interrupt();
2659 }
2660 }
2661 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2662
2663 if (puk == null) {
2664 mSimCard.supplyPin(pin, callback);
2665 } else {
2666 mSimCard.supplyPuk(puk, pin, callback);
2667 }
2668
2669 while (!mDone) {
2670 try {
2671 Log.d(LOG_TAG, "wait for done");
2672 wait();
2673 } catch (InterruptedException e) {
2674 // Restore the interrupted status
2675 Thread.currentThread().interrupt();
2676 }
2677 }
2678 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002679 int[] resultArray = new int[2];
2680 resultArray[0] = mResult;
2681 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002682
2683 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002684 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002685 }
2686
Wink Saville9de0f752013-10-22 19:04:03 -07002687 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689 }
2690
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002691 /**
2692 * This method has been removed due to privacy and stability concerns.
2693 */
2694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002696 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2697 return;
Wink Saville36469e72014-06-11 15:17:00 -07002698 }
2699
Nathan Harold1f889d82020-06-04 17:05:26 -07002700 @Override
2701 public void updateServiceLocationWithPackageName(String callingPackage) {
2702 mApp.getSystemService(AppOpsManager.class)
2703 .checkPackage(Binder.getCallingUid(), callingPackage);
2704
Nathan Haroldf096d982020-11-18 17:18:06 -08002705 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002706 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2707 // Callers targeting S have no business invoking this method.
2708 return;
2709 }
2710
2711 LocationAccessPolicy.LocationPermissionResult locationResult =
2712 LocationAccessPolicy.checkLocationPermission(mApp,
2713 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2714 .setCallingPackage(callingPackage)
2715 .setCallingFeatureId(null)
2716 .setCallingPid(Binder.getCallingPid())
2717 .setCallingUid(Binder.getCallingUid())
2718 .setMethod("updateServiceLocation")
2719 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2720 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2721 .build());
2722 // Apps that lack location permission have no business calling this method;
2723 // however, because no permission was declared in the public API, denials must
2724 // all be "soft".
2725 switch (locationResult) {
2726 case DENIED_HARD: /* fall through */
2727 case DENIED_SOFT:
2728 return;
2729 }
2730
2731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002734 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002736 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002743 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002744 @Override
2745 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002746 return isRadioOnWithFeature(callingPackage, null);
2747 }
2748
2749
2750 @Override
2751 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2752 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2753 callingFeatureId);
2754 }
2755
2756 @Deprecated
2757 @Override
2758 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2759 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002760 }
2761
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002763 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002766 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002767 return false;
2768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769
2770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 return isRadioOnForSubscriber(subId);
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
2775 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 }
2777
2778 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(subId);
2782 if (phone != null) {
2783 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
2792 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002793 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
Wink Saville36469e72014-06-11 15:17:00 -07002795
Wink Savilleb564aae2014-10-23 10:18:09 -07002796 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798
2799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
2803 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002807 }
Wink Saville36469e72014-06-11 15:17:00 -07002808 }
2809
2810 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002811 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
Wink Savilleb564aae2014-10-23 10:18:09 -07002814 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone == null) {
2821 return false;
2822 }
2823 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2824 toggleRadioOnOffForSubscriber(subId);
2825 }
2826 return true;
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
Wink Saville36469e72014-06-11 15:17:00 -07002831
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002832 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002833 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002834 /*
2835 * If any of the Radios are available, it will need to be
2836 * shutdown. So return true if any Radio is available.
2837 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2841 Phone phone = PhoneFactory.getPhone(i);
2842 if (phone != null && phone.isRadioAvailable()) return true;
2843 }
2844 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2845 return false;
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002848 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002849 }
2850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002852 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 enforceModifyPermission();
2854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2858 logv("Shutting down Phone " + i);
2859 shutdownRadioUsingPhoneId(i);
2860 }
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002863 }
2864 }
2865
2866 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 Phone phone = PhoneFactory.getPhone(phoneId);
2868 if (phone != null && phone.isRadioAvailable()) {
2869 phone.shutdownRadio();
2870 }
2871 }
2872
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2879 if (defaultPhone != null) {
2880 defaultPhone.setRadioPower(turnOn);
2881 return true;
2882 } else {
2883 loge("There's no default phone.");
2884 return false;
2885 }
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002888 }
Wink Saville36469e72014-06-11 15:17:00 -07002889 }
2890
Wink Savilleb564aae2014-10-23 10:18:09 -07002891 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 final Phone phone = getPhone(subId);
2897 if (phone != null) {
2898 phone.setRadioPower(turnOn);
2899 return true;
2900 } else {
2901 return false;
2902 }
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002908 /**
2909 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2910 * no reason to power it off. When any of the voters want to power it off, it will be turned
2911 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2912 * powering it off, and these radio off votes will be cleared.
2913 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2914 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2915 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2916 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2917 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2918 * check its vote.
2919 *
2920 * @param subId The subscription ID.
2921 * @param reason The reason for powering off radio.
2922 * @return true on success and false on failure.
2923 */
2924 public boolean requestRadioPowerOffForReason(int subId,
2925 @TelephonyManager.RadioPowerReason int reason) {
2926 enforceModifyPermission();
2927
2928 final long identity = Binder.clearCallingIdentity();
2929 try {
2930 final Phone phone = getPhone(subId);
2931 if (phone != null) {
2932 phone.setRadioPowerForReason(false, reason);
2933 return true;
2934 } else {
2935 return false;
2936 }
2937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 /**
2943 * Remove the vote on powering off the radio for a reason, as requested by
2944 * {@link requestRadioPowerOffForReason}.
2945 *
2946 * @param subId The subscription ID.
2947 * @param reason The reason for powering off radio.
2948 * @return true on success and false on failure.
2949 */
2950 public boolean clearRadioPowerOffForReason(int subId,
2951 @TelephonyManager.RadioPowerReason int reason) {
2952 enforceModifyPermission();
2953
2954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 if (phone != null) {
2958 phone.setRadioPowerForReason(true, reason);
2959 return true;
2960 } else {
2961 return false;
2962 }
2963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 /**
2969 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2970 *
2971 * @param subId The subscription ID.
2972 * @param callingPackage The package making the call.
2973 * @param callingFeatureId The feature in the package.
2974 * @return List of reasons for powering off radio.
2975 */
2976 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2977 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2978
2979 final long identity = Binder.clearCallingIdentity();
2980 List result = new ArrayList();
2981 try {
2982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2983 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2984 return result;
2985 }
2986
2987 final Phone phone = getPhone(subId);
2988 if (phone != null) {
2989 result.addAll(phone.getRadioPowerOffReasons());
2990 }
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 return result;
2995 }
2996
Wink Saville36469e72014-06-11 15:17:00 -07002997 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002998 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002999 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 int subId = mSubscriptionController.getDefaultDataSubId();
3005 final Phone phone = getPhone(subId);
3006 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003007 phone.getDataSettingsManager().setDataEnabled(
3008 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009 return true;
3010 } else {
3011 return false;
3012 }
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Wink Saville36469e72014-06-11 15:17:00 -07003018 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003020 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 int subId = mSubscriptionController.getDefaultDataSubId();
3026 final Phone phone = getPhone(subId);
3027 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003028 phone.getDataSettingsManager().setDataEnabled(
3029 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003030 return true;
3031 } else {
3032 return false;
3033 }
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003037 }
3038
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003040 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003045 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 } else {
3047 return false;
3048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 }
3053
3054 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003055 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003056 }
3057
pkanwarae03a6b2016-11-06 20:37:09 -08003058 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 enforceCallPermission();
3060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3064 return;
3065 }
3066 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3067 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
pkanwar32d516d2016-10-14 19:37:38 -07003071 };
3072
Wink Savilleb564aae2014-10-23 10:18:09 -07003073 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3079 return false;
3080 }
3081 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085 }
3086
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003087 /**
3088 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3089 * tag on getCallState Binder call.
3090 */
3091 @Deprecated
3092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003093 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003094 if (CompatChanges.isChangeEnabled(
3095 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3096 Binder.getCallingUid())) {
3097 // Do not allow this API to be called on API version 31+, it should only be
3098 // called on old apps using this Binder call directly.
3099 throw new SecurityException("This method can only be used for applications "
3100 + "targeting API version 30 or less.");
3101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003104 Phone phone = getPhone(getDefaultSubscription());
3105 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3106 PhoneConstantConversions.convertCallState(phone.getState());
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3114 if (CompatChanges.isChangeEnabled(
3115 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3116 Binder.getCallingUid())) {
3117 // Check READ_PHONE_STATE for API version 31+
3118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3119 featureId, "getCallStateForSubscription")) {
3120 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3121 + "targeting API level 31+.");
3122 }
3123 }
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3128 PhoneConstantConversions.convertCallState(phone.getState());
3129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003132 }
3133
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003135 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003136 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3137 }
3138
3139 @Override
3140 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003141 final long identity = Binder.clearCallingIdentity();
3142 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003143 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003145 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 } else {
3147 return PhoneConstantConversions.convertDataState(
3148 PhoneConstants.DataState.DISCONNECTED);
3149 }
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003156 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003157 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3158 }
3159
3160 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003161 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003164 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003165 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003166 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 } else {
3168 return TelephonyManager.DATA_ACTIVITY_NONE;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003176 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003177 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003178 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003179
3180 LocationAccessPolicy.LocationPermissionResult locationResult =
3181 LocationAccessPolicy.checkLocationPermission(mApp,
3182 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3183 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003184 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003185 .setCallingPid(Binder.getCallingPid())
3186 .setCallingUid(Binder.getCallingUid())
3187 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003188 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3190 .build());
3191 switch (locationResult) {
3192 case DENIED_HARD:
3193 throw new SecurityException("Not allowed to access cell location");
3194 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003195 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3196 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 }
3198
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003199 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003203 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003204 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
Svetoslav64fad262015-04-14 14:35:21 -07003208 }
3209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003211 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003212 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3213 // registered cell info, so return a NULL country instead.
3214 final long identity = Binder.clearCallingIdentity();
3215 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003216 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3217 // Get default phone in this case.
3218 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3219 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003220 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003221 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003222 if (phone == null) return "";
3223 ServiceStateTracker sst = phone.getServiceStateTracker();
3224 if (sst == null) return "";
3225 LocaleTracker lt = sst.getLocaleTracker();
3226 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003227 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003231 }
3232
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003233 /**
3234 * This method was removed due to potential issues caused by performing partial
3235 * updates of service state, and lack of a credible use case.
3236 *
3237 * This has the ability to break the telephony implementation by disabling notification of
3238 * changes in device connectivity. DO NOT USE THIS!
3239 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003240 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003241 public void enableLocationUpdates() {
3242 mApp.enforceCallingOrSelfPermission(
3243 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003244 }
3245
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003246 /**
3247 * This method was removed due to potential issues caused by performing partial
3248 * updates of service state, and lack of a credible use case.
3249 *
3250 * This has the ability to break the telephony implementation by disabling notification of
3251 * changes in device connectivity. DO NOT USE THIS!
3252 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 @Override
3254 public void disableLocationUpdates() {
3255 mApp.enforceCallingOrSelfPermission(
3256 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
3259 @Override
3260 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003261 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3262 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003263 try {
3264 mApp.getSystemService(AppOpsManager.class)
3265 .checkPackage(Binder.getCallingUid(), callingPackage);
3266 } catch (SecurityException e) {
3267 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3268 throw e;
3269 }
3270
Nathan Haroldf096d982020-11-18 17:18:06 -08003271 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003272 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3273 throw new SecurityException(
3274 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3275 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003276
Jordan Liu1617b712019-07-10 15:06:26 -07003277 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3279 return null;
3280 }
Svetoslav64fad262015-04-14 14:35:21 -07003281
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003282 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003284 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003285 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286
Nathan Haroldf180aac2018-06-01 18:43:55 -07003287 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3288 for (CellInfo ci : info) {
3289 if (ci instanceof CellInfoGsm) {
3290 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3291 } else if (ci instanceof CellInfoWcdma) {
3292 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003295 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003296 }
3297
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003298 private List<CellInfo> getCachedCellInfo() {
3299 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3300 for (Phone phone : PhoneFactory.getPhones()) {
3301 List<CellInfo> info = phone.getAllCellInfo();
3302 if (info != null) cellInfos.addAll(info);
3303 }
3304 return cellInfos;
3305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003306
3307 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003308 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003310 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003311
3312 LocationAccessPolicy.LocationPermissionResult locationResult =
3313 LocationAccessPolicy.checkLocationPermission(mApp,
3314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3315 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003316 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003317 .setCallingPid(Binder.getCallingPid())
3318 .setCallingUid(Binder.getCallingUid())
3319 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003320 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003321 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3322 .build());
3323 switch (locationResult) {
3324 case DENIED_HARD:
3325 throw new SecurityException("Not allowed to access cell info");
3326 case DENIED_SOFT:
3327 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
Nathan Haroldf096d982020-11-18 17:18:06 -08003330 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003331 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3332 return getCachedCellInfo();
3333 }
3334
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003335 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3340 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003341 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003342 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 if (info != null) cellInfos.addAll(info);
3344 }
3345 return cellInfos;
3346 } finally {
3347 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 }
3349 }
3350
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003351 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003352 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3353 String callingFeatureId) {
3354 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3355 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003356 }
3357
3358 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003359 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3360 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003361 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003362 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003363 }
3364
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003365 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3366 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003367 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003368 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003369
3370 LocationAccessPolicy.LocationPermissionResult locationResult =
3371 LocationAccessPolicy.checkLocationPermission(mApp,
3372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3373 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003374 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003375 .setCallingPid(Binder.getCallingPid())
3376 .setCallingUid(Binder.getCallingUid())
3377 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003378 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3379 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003380 .build());
3381 switch (locationResult) {
3382 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003383 if (TelephonyPermissions
3384 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003385 // Safetynet logging for b/154934934
3386 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3387 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003388 throw new SecurityException("Not allowed to access cell info");
3389 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003390 if (TelephonyPermissions
3391 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003392 // Safetynet logging for b/154934934
3393 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3394 }
Nathan Harold5320c422019-05-09 10:26:08 -07003395 try {
3396 cb.onCellInfo(new ArrayList<CellInfo>());
3397 } catch (RemoteException re) {
3398 // Drop without consequences
3399 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003400 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003401 }
3402
Nathan Harolda939a962019-05-09 10:13:47 -07003403
3404 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3406
3407 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3408 }
3409
3410 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003411 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003412 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003417 Phone phone = getPhone(subId);
3418 if (phone == null) {
3419 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3420 } else {
3421 phone.setCellInfoListRate(rateInMillis, workSource);
3422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003426 }
3427
Shishir Agrawala9f32182016-04-12 12:00:16 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 Phone phone = PhoneFactory.getPhone(slotIndex);
3431 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 return null;
3433 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003434 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003435 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003436 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003437 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 return null;
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 return phone.getImei();
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003447 }
3448
3449 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003450 public String getTypeAllocationCodeForSlot(int slotIndex) {
3451 Phone phone = PhoneFactory.getPhone(slotIndex);
3452 String tac = null;
3453 if (phone != null) {
3454 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003455 try {
3456 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3457 } catch (IndexOutOfBoundsException e) {
3458 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3459 return null;
3460 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003461 }
3462 return tac;
3463 }
3464
3465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003466 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003467 try {
3468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3469 } catch (SecurityException se) {
3470 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3471 throw new SecurityException("Package " + callingPackage + " does not belong to "
3472 + Binder.getCallingUid());
3473 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003474 Phone phone = PhoneFactory.getPhone(slotIndex);
3475 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003476 return null;
3477 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478
Jeff Davidson913390f2018-02-23 17:11:49 -08003479 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003480 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003481 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003482 return null;
3483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003484
3485 final long identity = Binder.clearCallingIdentity();
3486 try {
3487 return phone.getMeid();
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
Jack Yu2af8d712017-03-15 17:14:14 -07003491 }
3492
3493 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003494 public String getManufacturerCodeForSlot(int slotIndex) {
3495 Phone phone = PhoneFactory.getPhone(slotIndex);
3496 String manufacturerCode = null;
3497 if (phone != null) {
3498 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003499 try {
3500 manufacturerCode =
3501 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3502 } catch (IndexOutOfBoundsException e) {
3503 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3504 return null;
3505 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003506 }
3507 return manufacturerCode;
3508 }
3509
3510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3512 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003513 Phone phone = PhoneFactory.getPhone(slotIndex);
3514 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 return null;
3516 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 int subId = phone.getSubId();
3518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 mApp, subId, callingPackage, callingFeatureId,
3520 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 return null;
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
3524 final long identity = Binder.clearCallingIdentity();
3525 try {
3526 return phone.getDeviceSvn();
3527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003530 }
3531
fionaxu43304da2017-11-27 22:51:16 -08003532 @Override
3533 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 final Phone phone = getPhone(subId);
3537 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
fionaxu43304da2017-11-27 22:51:16 -08003541 }
3542
3543 @Override
3544 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 return phone == null ? null : phone.getCarrierName();
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
fionaxu43304da2017-11-27 22:51:16 -08003552 }
3553
calvinpanffe225e2018-11-01 19:43:06 +08003554 @Override
chen xu0026ca62019-03-06 15:28:50 -08003555 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003560 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
3564 }
3565
3566 @Override
chen xu0026ca62019-03-06 15:28:50 -08003567 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003571 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
chen xu651eec72018-11-11 19:03:44 -08003577 @Override
chen xu864e11c2018-12-06 22:10:03 -08003578 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3579 if (!isSubscriptionMccMnc) {
3580 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3581 }
chen xu651eec72018-11-11 19:03:44 -08003582 final Phone phone = PhoneFactory.getPhone(slotIndex);
3583 if (phone == null) {
3584 return TelephonyManager.UNKNOWN_CARRIER_ID;
3585 }
3586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 //
3595 // Internal helper methods.
3596 //
3597
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003598 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003599 * Make sure the caller is the calling package itself
3600 *
3601 * @throws SecurityException if the caller is not the calling package
3602 */
3603 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3604 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003605 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3606 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003607 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003608 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003609 } catch (PackageManager.NameNotFoundException e) {
3610 // packageUid is -1
3611 }
3612 if (packageUid != callingUid) {
3613 throw new SecurityException(message + ": Package " + callingPackage
3614 + " does not belong to " + callingUid);
3615 }
3616 }
3617
3618 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003619 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3620 *
3621 * @throws SecurityException if the caller does not have the required permission
3622 */
3623 private void enforceModifyPermission() {
3624 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3625 }
3626
Shuo Qian3b6ee772019-11-13 17:43:31 -08003627 private void enforceActiveEmergencySessionPermission() {
3628 mApp.enforceCallingOrSelfPermission(
3629 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3630 }
3631
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003632 /**
3633 * Make sure the caller has the CALL_PHONE permission.
3634 *
3635 * @throws SecurityException if the caller does not have the required permission
3636 */
3637 private void enforceCallPermission() {
3638 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3639 }
3640
paulhu5a773602019-08-23 19:17:33 +08003641 private void enforceSettingsPermission() {
3642 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003643 }
3644
Michele Berionne5e411512020-11-13 02:36:59 +00003645 private void enforceRebootPermission() {
3646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3647 }
3648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 private String createTelUrl(String number) {
3650 if (TextUtils.isEmpty(number)) {
3651 return null;
3652 }
3653
Jake Hambye994d462014-02-03 13:10:13 -08003654 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003655 }
3656
Ihab Awadf9e92732013-12-05 18:02:52 -08003657 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003658 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3659 }
3660
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003661 private static void logv(String msg) {
3662 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3663 }
3664
Ihab Awadf9e92732013-12-05 18:02:52 -08003665 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003666 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3667 }
3668
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003669 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003671 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Sanket Padawe356d7632015-06-22 14:03:32 -07003674 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003675 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 final Phone phone = PhoneFactory.getPhone(slotIndex);
3679 if (phone == null) {
3680 return PhoneConstants.PHONE_TYPE_NONE;
3681 } else {
3682 return phone.getPhoneType();
3683 }
3684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003687 }
3688
3689 /**
3690 * Returns the CDMA ERI icon index to display
3691 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003693 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3694 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3695 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003696 }
3697
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003699 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3700 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003702 mApp, subId, callingPackage, callingFeatureId,
3703 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003704 return -1;
3705 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 final Phone phone = getPhone(subId);
3710 if (phone != null) {
3711 return phone.getCdmaEriIconIndex();
3712 } else {
3713 return -1;
3714 }
3715 } finally {
3716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003718 }
3719
3720 /**
3721 * Returns the CDMA ERI icon mode,
3722 * 0 - ON
3723 * 1 - FLASHING
3724 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003725 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003726 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3727 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3728 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003729 }
3730
Sanket Padawe356d7632015-06-22 14:03:32 -07003731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003732 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3733 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003735 mApp, subId, callingPackage, callingFeatureId,
3736 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 return -1;
3738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739
3740 final long identity = Binder.clearCallingIdentity();
3741 try {
3742 final Phone phone = getPhone(subId);
3743 if (phone != null) {
3744 return phone.getCdmaEriIconMode();
3745 } else {
3746 return -1;
3747 }
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003751 }
3752
3753 /**
3754 * Returns the CDMA ERI text,
3755 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003756 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003757 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3758 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3759 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003760 }
3761
Sanket Padawe356d7632015-06-22 14:03:32 -07003762 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003763 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3764 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003766 mApp, subId, callingPackage, callingFeatureId,
3767 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003768 return null;
3769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
3771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 final Phone phone = getPhone(subId);
3774 if (phone != null) {
3775 return phone.getCdmaEriText();
3776 } else {
3777 return null;
3778 }
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003781 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003782 }
3783
3784 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003785 * Returns the CDMA MDN.
3786 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003787 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003788 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 return phone.getLine1Number();
3797 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003798 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 return null;
3800 }
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003803 }
3804 }
3805
3806 /**
3807 * Returns the CDMA MIN.
3808 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003809 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003810 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3812 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813
3814 final long identity = Binder.clearCallingIdentity();
3815 try {
3816 final Phone phone = getPhone(subId);
3817 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3818 return phone.getCdmaMin();
3819 } else {
3820 return null;
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003824 }
3825 }
3826
Hall Liud892bec2018-11-30 14:51:45 -08003827 @Override
3828 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3829 INumberVerificationCallback callback, String callingPackage) {
3830 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3831 != PERMISSION_GRANTED) {
3832 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3833 }
3834 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3835
3836 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3837 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003838 throw new SecurityException("Calling package must be configured in the device config: "
3839 + "calling package: " + callingPackage
3840 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003841 }
3842
3843 if (range == null) {
3844 throw new NullPointerException("Range must be non-null");
3845 }
3846
3847 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003848 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003849
3850 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3851 }
3852
Junda Liuca05d5d2014-08-14 22:36:34 -07003853 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 * Returns true if CDMA provisioning needs to run.
3855 */
3856 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003857 final long identity = Binder.clearCallingIdentity();
3858 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003859 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 } finally {
3861 Binder.restoreCallingIdentity(identity);
3862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003863 }
3864
3865 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003866 * Sets the voice mail number of a given subId.
3867 */
3868 @Override
3869 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3871 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872
3873 final long identity = Binder.clearCallingIdentity();
3874 try {
3875 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3876 new Pair<String, String>(alphaTag, number), new Integer(subId));
3877 return success;
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003881 }
3882
Ta-wei Yen87c49842016-05-13 21:19:52 -07003883 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003884 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003886 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3887 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003888 if (!TextUtils.equals(callingPackage, systemDialer)) {
3889 throw new SecurityException("caller must be system dialer");
3890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003891
3892 final long identity = Binder.clearCallingIdentity();
3893 try {
3894 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3895 if (phoneAccountHandle == null) {
3896 return null;
3897 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 } finally {
3900 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003901 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003902 }
3903
3904 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003905 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3906 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003907 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003909 mApp, subId, callingPackage, callingFeatureId,
3910 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003911 return null;
3912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003914 final long identity = Binder.clearCallingIdentity();
3915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003920 }
3921
3922 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003923 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3924 VisualVoicemailSmsFilterSettings settings) {
3925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926
3927 final long identity = Binder.clearCallingIdentity();
3928 try {
3929 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003930 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003931 } finally {
3932 Binder.restoreCallingIdentity(identity);
3933 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003934 }
3935
3936 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003937 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3938 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003947 }
3948
3949 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003950 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3951 String callingPackage, int subId) {
3952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953
3954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 } finally {
3959 Binder.restoreCallingIdentity(identity);
3960 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003961 }
3962
3963 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003964 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003966
3967 final long identity = Binder.clearCallingIdentity();
3968 try {
3969 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003970 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003974 }
3975
3976 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003977 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3978 String callingAttributionTag, int subId, String number, int port, String text,
3979 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003981 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003982 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003983 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003984 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3985 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003986 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003987
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003988 /**
fionaxu0152e512016-11-14 13:36:14 -08003989 * Sets the voice activation state of a given subId.
3990 */
3991 @Override
3992 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3994 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995
3996 final long identity = Binder.clearCallingIdentity();
3997 try {
3998 final Phone phone = getPhone(subId);
3999 if (phone != null) {
4000 phone.setVoiceActivationState(activationState);
4001 } else {
4002 loge("setVoiceActivationState fails with invalid subId: " + subId);
4003 }
4004 } finally {
4005 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004006 }
4007 }
4008
4009 /**
4010 * Sets the data activation state of a given subId.
4011 */
4012 @Override
4013 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4015 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016
4017 final long identity = Binder.clearCallingIdentity();
4018 try {
4019 final Phone phone = getPhone(subId);
4020 if (phone != null) {
4021 phone.setDataActivationState(activationState);
4022 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004023 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004024 }
4025 } finally {
4026 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004027 }
4028 }
4029
4030 /**
4031 * Returns the voice activation state of a given subId.
4032 */
4033 @Override
4034 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004036
fionaxu0152e512016-11-14 13:36:14 -08004037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 final long identity = Binder.clearCallingIdentity();
4039 try {
4040 if (phone != null) {
4041 return phone.getVoiceActivationState();
4042 } else {
4043 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4044 }
4045 } finally {
4046 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004047 }
4048 }
4049
4050 /**
4051 * Returns the data activation state of a given subId.
4052 */
4053 @Override
4054 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056
fionaxu0152e512016-11-14 13:36:14 -08004057 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 if (phone != null) {
4061 return phone.getDataActivationState();
4062 } else {
4063 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4064 }
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004067 }
4068 }
4069
4070 /**
Wink Saville36469e72014-06-11 15:17:00 -07004071 * Returns the unread count of voicemails for a subId
4072 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4075 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004077 mApp, subId, callingPackage, callingFeatureId,
4078 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004079 return 0;
4080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 final Phone phone = getPhone(subId);
4084 if (phone != null) {
4085 return phone.getVoiceMessageCount();
4086 } else {
4087 return 0;
4088 }
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004092 }
4093
4094 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004095 * returns true, if the device is in a state where both voice and data
4096 * are supported simultaneously. This can change based on location or network condition.
4097 */
4098 @Override
4099 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 final Phone phone = getPhone(subId);
4103 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4104 } finally {
4105 Binder.restoreCallingIdentity(identity);
4106 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004107 }
4108
4109 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004110 * Send the dialer code if called from the current default dialer or the caller has
4111 * carrier privilege.
4112 * @param inputCode The dialer code to send
4113 */
4114 @Override
4115 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004116 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004118 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4119 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004120 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004122 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124
4125 final long identity = Binder.clearCallingIdentity();
4126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004127 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
fionaxu235cc5e2017-03-06 22:25:57 -08004131 }
4132
Pengquan Menga1bb6272018-09-06 09:59:22 -07004133 @Override
4134 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004135 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004136 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004137 mApp, subId, "getNetworkSelectionMode");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 if (!isActiveSubscription(subId)) {
4141 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4142 }
4143 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004146 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004147 }
4148
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004150 public boolean isInEmergencySmsMode() {
4151 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 for (Phone phone : PhoneFactory.getPhones()) {
4155 if (phone.isInEmergencySmsMode()) {
4156 return true;
4157 }
4158 }
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 return false;
4163 }
4164
shilu366312e2019-12-17 09:28:10 -08004165 /**
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 * @param c The callback that will be used to send the result.
4169 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004170 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004171 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4172 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004173 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004174 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004175
4176 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4177 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4178 "IMS not available on device.");
4179 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 final long token = Binder.clearCallingIdentity();
4181 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004182 int slotId = getSlotIndexOrException(subId);
4183 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004184
4185 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4186 if (controller != null) {
4187 ImsManager imsManager = controller.getImsManager(subId);
4188 if (imsManager != null) {
4189 imsManager.addRegistrationCallbackForSubscription(c, subId);
4190 } else {
4191 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4192 }
4193 } else {
4194 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4195 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 } catch (ImsException e) {
4197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(token);
4200 }
4201 }
4202
shilu366312e2019-12-17 09:28:10 -08004203 /**
4204 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4205 * @param subId The subscription to use to check the configuration.
4206 * @param c The callback that will be used to send the result.
4207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004209 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004210 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004211 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4214 }
Meng Wangafbc5852019-09-19 17:37:13 -07004215 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004216
Meng Wangafbc5852019-09-19 17:37:13 -07004217 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004218 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4219 if (controller != null) {
4220 ImsManager imsManager = controller.getImsManager(subId);
4221 if (imsManager != null) {
4222 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4223 } else {
4224 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4225 + "is inactive, ignoring unregister.");
4226 // If the ImsManager is not valid, just return, since the callback
4227 // will already have been removed internally.
4228 }
4229 }
Meng Wangafbc5852019-09-19 17:37:13 -07004230 } finally {
4231 Binder.restoreCallingIdentity(token);
4232 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 }
4234
Brad Ebingera34a6c22019-10-22 17:36:18 -07004235 /**
4236 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4237 */
4238 @Override
4239 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4240 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4241 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4242 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4243 "IMS not available on device.");
4244 }
4245 final long token = Binder.clearCallingIdentity();
4246 try {
4247 Phone phone = getPhone(subId);
4248 if (phone == null) {
4249 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4250 + subId + "'");
4251 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4252 }
4253 phone.getImsRegistrationState(regState -> {
4254 try {
4255 consumer.accept((regState == null)
4256 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4257 } catch (RemoteException e) {
4258 // Ignore if the remote process is no longer available to call back.
4259 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4260 }
4261 });
4262 } finally {
4263 Binder.restoreCallingIdentity(token);
4264 }
4265 }
4266
4267 /**
4268 * Get the transport type for the IMS service registration state.
4269 */
4270 @Override
4271 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004272 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004273 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004274 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4275 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4276 "IMS not available on device.");
4277 }
4278 final long token = Binder.clearCallingIdentity();
4279 try {
4280 Phone phone = getPhone(subId);
4281 if (phone == null) {
4282 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4283 + subId + "'");
4284 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4285 }
4286 phone.getImsRegistrationTech(regTech -> {
4287 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4288 int regTechConverted = (regTech == null)
4289 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4290 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4291 regTechConverted);
4292 try {
4293 consumer.accept(regTechConverted);
4294 } catch (RemoteException e) {
4295 // Ignore if the remote process is no longer available to call back.
4296 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4297 }
4298 });
4299 } finally {
4300 Binder.restoreCallingIdentity(token);
4301 }
4302 }
4303
shilu366312e2019-12-17 09:28:10 -08004304 /**
4305 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4306 * @param subId The subscription to use to check the configuration.
4307 * @param c The callback that will be used to send the result.
4308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004310 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4311 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004312 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004314 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4315 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4316 "IMS not available on device.");
4317 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 final long token = Binder.clearCallingIdentity();
4319 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004320 int slotId = getSlotIndexOrException(subId);
4321 verifyImsMmTelConfiguredOrThrow(slotId);
4322 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004325 } finally {
4326 Binder.restoreCallingIdentity(token);
4327 }
4328 }
4329
shilu366312e2019-12-17 09:28:10 -08004330 /**
4331 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 * @param c The callback that will be used to send the result.
4334 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004336 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004337 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004338 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4341 }
Meng Wangafbc5852019-09-19 17:37:13 -07004342
4343 final long token = Binder.clearCallingIdentity();
4344 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004345 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004346 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004347 } catch (ImsException e) {
4348 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4349 + "is inactive, ignoring unregister.");
4350 // If the subscription is no longer active, just return, since the callback
4351 // will already have been removed internally.
4352 } finally {
4353 Binder.restoreCallingIdentity(token);
4354 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 }
4356
4357 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004358 public boolean isCapable(int subId, int capability, int regTech) {
4359 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 final long token = Binder.clearCallingIdentity();
4361 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004362 int slotId = getSlotIndexOrException(subId);
4363 verifyImsMmTelConfiguredOrThrow(slotId);
4364 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4365 } catch (com.android.ims.ImsException e) {
4366 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4367 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004369 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4370 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 } finally {
4372 Binder.restoreCallingIdentity(token);
4373 }
4374 }
4375
4376 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004377 public boolean isAvailable(int subId, int capability, int regTech) {
4378 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long token = Binder.clearCallingIdentity();
4380 try {
4381 Phone phone = getPhone(subId);
4382 if (phone == null) return false;
4383 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004384 } catch (com.android.ims.ImsException e) {
4385 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4386 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(token);
4389 }
4390 }
4391
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004392 /**
4393 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4394 * subscription.
4395 * @param subId The subscription to use to check the configuration.
4396 * @param callback The callback that will be used to send the result.
4397 * @param capability The MmTelFeature capability that will be used to send the result.
4398 * @param transportType The transport type of the MmTelFeature capability.
4399 */
4400 @Override
4401 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4402 int transportType) {
4403 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4406 "IMS not available on device.");
4407 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004408 final long token = Binder.clearCallingIdentity();
4409 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004410 int slotId = getSlotIndex(subId);
4411 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4412 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4413 + subId + "'");
4414 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4415 }
4416 verifyImsMmTelConfiguredOrThrow(slotId);
4417 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4418 transportType, aBoolean -> {
4419 try {
4420 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4421 } catch (RemoteException e) {
4422 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4423 + "running. Ignore");
4424 }
4425 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 } catch (ImsException e) {
4427 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004428 } finally {
4429 Binder.restoreCallingIdentity(token);
4430 }
4431 }
4432
shilu366312e2019-12-17 09:28:10 -08004433 /**
4434 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4435 * @param subId The subscription to use to check the configuration.
4436 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004437 @Override
4438 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004440 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004441
Brad Ebinger35c841c2018-10-01 10:40:55 -07004442 final long token = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004444 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004445 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(token);
4451 }
4452 }
4453
4454 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004455 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004457 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004476 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
4491 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004492 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004494 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify. The
4499 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (ImsException e) {
4502 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
shilu366312e2019-12-17 09:28:10 -08004508 /**
4509 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4510 * @param subId The subscription to use to check the configuration.
4511 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004512 @Override
4513 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004514 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004515 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004518 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004519 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004520 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
4522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
4526 }
4527
4528 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004529 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004531 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004534 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004535 // This setting doesn't require an active ImsService connection, so do not verify. The
4536 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004537 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004538 } catch (ImsException e) {
4539 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
4543 }
4544
shilu366312e2019-12-17 09:28:10 -08004545 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004546 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4548 * @param subId The subscription to use to check the configuration.
4549 */
4550 @Override
4551 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004552 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004553 mApp, subId, "isCrossSimCallingEnabledByUser");
4554 final long identity = Binder.clearCallingIdentity();
4555 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004556 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004557 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004558 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004559 } catch (ImsException e) {
4560 throw new ServiceSpecificException(e.getCode());
4561 } finally {
4562 Binder.restoreCallingIdentity(identity);
4563 }
4564 }
4565
4566 /**
4567 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4568 * Requires MODIFY_PHONE_STATE permission.
4569 * @param subId The subscription to use to check the configuration.
4570 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4571 * false otherwise
4572 */
4573 @Override
4574 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4576 "setCrossSimCallingEnabled");
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004579 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004580 // This setting doesn't require an active ImsService connection, so do not verify. The
4581 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
4585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
4588 }
4589
4590 /**
shilu366312e2019-12-17 09:28:10 -08004591 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4592 * @param subId The subscription to use to check the configuration.
4593 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004594 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004595
Brad Ebinger35c841c2018-10-01 10:40:55 -07004596 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004597 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004598 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004599 final long identity = Binder.clearCallingIdentity();
4600 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004601 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004602 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004603 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004612 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004614 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004615 final long identity = Binder.clearCallingIdentity();
4616 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004617 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004618 // This setting doesn't require an active ImsService connection, so do not verify. The
4619 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004620 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (ImsException e) {
4622 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
4628 @Override
4629 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4631 "setVoWiFiNonPersistent");
4632 final long identity = Binder.clearCallingIdentity();
4633 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004634 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004635 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004636 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004637 } catch (ImsException e) {
4638 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
shilu366312e2019-12-17 09:28:10 -08004644 /**
4645 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4646 * @param subId The subscription to use to check the configuration.
4647 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004648 @Override
4649 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004650 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004651 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004654 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004655 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004656 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (ImsException e) {
4658 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public void setVoWiFiModeSetting(int subId, int mode) {
4666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4667 "setVoWiFiModeSetting");
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004670 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004671 // This setting doesn't require an active ImsService connection, so do not verify. The
4672 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004673 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 } catch (ImsException e) {
4675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 } finally {
4677 Binder.restoreCallingIdentity(identity);
4678 }
4679 }
4680
4681 @Override
4682 public int getVoWiFiRoamingModeSetting(int subId) {
4683 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004686 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004687 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004688 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (ImsException e) {
4690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
4696 @Override
4697 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4699 "setVoWiFiRoamingModeSetting");
4700 final long identity = Binder.clearCallingIdentity();
4701 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004702 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004703 // This setting doesn't require an active ImsService connection, so do not verify. The
4704 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004705 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004706 } catch (ImsException e) {
4707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 } finally {
4709 Binder.restoreCallingIdentity(identity);
4710 }
4711 }
4712
4713 @Override
4714 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4716 "setRttCapabilityEnabled");
4717 final long identity = Binder.clearCallingIdentity();
4718 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004719 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004720 // This setting doesn't require an active ImsService connection, so do not verify. The
4721 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004722 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (ImsException e) {
4724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
4728 }
4729
shilu366312e2019-12-17 09:28:10 -08004730 /**
4731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4732 * @param subId The subscription to use to check the configuration.
4733 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004734 @Override
4735 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004736 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004737 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 final long identity = Binder.clearCallingIdentity();
4739 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004740 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004741 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004742 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004743 } catch (ImsException e) {
4744 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004750 @Override
4751 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4752 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004753
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 final long identity = Binder.clearCallingIdentity();
4755 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004756 if (!isImsAvailableOnDevice()) {
4757 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4758 "IMS not available on device.");
4759 }
4760 int slotId = getSlotIndexOrException(subId);
4761 verifyImsMmTelConfiguredOrThrow(slotId);
4762 ImsManager.getInstance(mApp, slotId)
4763 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004764 } catch (ImsException e) {
4765 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
4771 @Override
4772 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4773 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004774
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4777 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4778 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004780 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004781 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004782 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004783 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4784 + "is inactive, ignoring unregister.");
4785 // If the subscription is no longer active, just return, since the callback will already
4786 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
4790 }
4791
joonhunshincffb7fc2021-11-28 07:32:01 +00004792 @Override
4793 public void registerFeatureProvisioningChangedCallback(int subId,
4794 IFeatureProvisioningCallback callback) {
4795 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4796 mApp, subId, "registerFeatureProvisioningChangedCallback");
4797
4798 final long identity = Binder.clearCallingIdentity();
4799 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4800 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4801 }
4802
joonhunshin91bc1952022-04-29 08:47:15 +00004803 try {
4804 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4805 if (controller == null) {
4806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4807 "Device does not support IMS");
4808 }
4809 controller.addFeatureProvisioningChangedCallback(subId, callback);
4810 } finally {
4811 Binder.restoreCallingIdentity(identity);
4812 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004813 }
4814
4815 @Override
4816 public void unregisterFeatureProvisioningChangedCallback(int subId,
4817 IFeatureProvisioningCallback callback) {
4818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4819 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4820
4821 final long identity = Binder.clearCallingIdentity();
4822 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4823 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4824 }
4825
joonhunshin91bc1952022-04-29 08:47:15 +00004826 try {
4827 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4828 if (controller == null) {
4829 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4830 return;
4831 }
4832 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
4835 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004836 }
allenwtsu99c623b2020-01-03 18:24:23 +08004837
4838 private void checkModifyPhoneStatePermission(int subId, String message) {
4839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4840 message);
4841 }
4842
allenwtsu99c623b2020-01-03 18:24:23 +08004843 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004844 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004845 boolean isProvisioned) {
4846 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4847
4848 final long identity = Binder.clearCallingIdentity();
4849 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004850 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4851 if (controller == null) {
4852 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4853 return;
4854 }
4855 controller.setRcsProvisioningStatusForCapability(
4856 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
allenwtsu99c623b2020-01-03 18:24:23 +08004860 }
4861
4862
4863 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004864 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4866 mApp, subId, "getRcsProvisioningStatusForCapability");
4867
allenwtsu99c623b2020-01-03 18:24:23 +08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004870 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4871 if (controller == null) {
4872 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4873
4874 // device does not support IMS, this method will return true always.
4875 return true;
4876 }
4877 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004884 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4885 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004886 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004887
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004890 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4891 if (controller == null) {
4892 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4893 return;
4894 }
4895 controller.setImsProvisioningStatusForCapability(
4896 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
4900 }
4901
4902 @Override
4903 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004904 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4905 mApp, subId, "getProvisioningStatusForCapability");
4906
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004909 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4910 if (controller == null) {
4911 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912
joonhunshin91bc1952022-04-29 08:47:15 +00004913 // device does not support IMS, this method will return true always.
4914 return true;
4915 }
4916 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 } finally {
4918 Binder.restoreCallingIdentity(identity);
4919 }
4920 }
4921
4922 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004923 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4924 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4925 mApp, subId, "isProvisioningRequiredForCapability");
4926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004929 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4930 if (controller == null) {
4931 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4932
4933 // device does not support IMS, this method will return false
4934 return false;
4935 }
4936 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004940 }
4941
4942 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004943 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4944 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4945 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 final long identity = Binder.clearCallingIdentity();
4948 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004949 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4950 if (controller == null) {
4951 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4952
4953 // device does not support IMS, this method will return false
4954 return false;
4955 }
4956 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 }
4961
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004962 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004963 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4965 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4966 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004967 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4968 mApp, subId, "getImsProvisioningInt");
4969
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 int slotId = getSlotIndex(subId);
4974 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4975 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4976 + subId + "' for key:" + key);
4977 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4978 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004979
joonhunshin91bc1952022-04-29 08:47:15 +00004980 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4981 if (controller == null) {
4982 loge("getImsProvisioningInt: Device does not support IMS");
4983
4984 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4985 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4986 }
4987 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004988 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4989 return retVal;
4990 }
4991
calvinpanb5a34062021-02-08 19:59:36 +08004992 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004993 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004994 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4995 + subId + "' for key:" + key);
4996 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
5000 }
5001
5002 @Override
5003 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005004 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5005 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5006 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5008 mApp, subId, "getImsProvisioningString");
5009
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005013 int slotId = getSlotIndex(subId);
5014 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5015 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5016 + subId + "' for key:" + key);
5017 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5018 }
calvinpanb5a34062021-02-08 19:59:36 +08005019 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005020 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005021 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5022 + subId + "' for key:" + key);
5023 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
5029 @Override
5030 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005031 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5032 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5033 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5035 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005036
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005040 int slotId = getSlotIndex(subId);
5041 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5042 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5043 + subId + "' for key:" + key);
5044 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5045 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005046
joonhunshin91bc1952022-04-29 08:47:15 +00005047 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5048 if (controller == null) {
5049 loge("setImsProvisioningInt: Device does not support IMS");
5050
5051 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5052 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5053 }
5054 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005055 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5056 return retVal;
5057 }
5058
calvinpanb5a34062021-02-08 19:59:36 +08005059 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5060 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005061 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005062 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005063 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
5069 @Override
5070 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005071 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5072 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5073 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5075 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005079 int slotId = getSlotIndex(subId);
5080 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5081 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5082 + subId + "' for key:" + key);
5083 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5084 }
calvinpanb5a34062021-02-08 19:59:36 +08005085 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5086 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005087 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005088 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005089 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
5093 }
5094
Brad Ebinger919631e2021-06-02 17:46:35 -07005095 /**
5096 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5097 * for the given slot ID or no ImsResolver instance has been created.
5098 * @param slotId The slot ID that the IMS service is created for.
5099 * @throws ImsException If there is no ImsService configured for this slot.
5100 */
5101 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5102 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5103 ImsFeature.FEATURE_MMTEL)) {
5104 throw new ImsException("This subscription does not support MMTEL over IMS",
5105 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5106 }
5107 }
5108
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005109 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005110 int slotId = SubscriptionManager.getSlotIndex(subId);
5111 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005112 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5113 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 }
5115 return slotId;
5116 }
5117
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005118 private int getSlotIndex(int subId) {
5119 int slotId = SubscriptionManager.getSlotIndex(subId);
5120 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5121 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5122 }
5123 return slotId;
5124 }
5125
Wink Saville36469e72014-06-11 15:17:00 -07005126 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005127 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005128 */
5129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005130 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5131 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005132 try {
5133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5134 } catch (SecurityException se) {
5135 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5136 throw new SecurityException("Package " + callingPackage + " does not belong to "
5137 + Binder.getCallingUid());
5138 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005139 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005140 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005141 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005142 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005143 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 mApp, subId, callingPackage, callingFeatureId,
5145 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005146 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5147 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 final Phone phone = getPhone(subId);
5152 if (phone != null) {
5153 return phone.getServiceState().getDataNetworkType();
5154 } else {
5155 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5156 }
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005159 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005160 }
5161
5162 /**
5163 * Returns the data network type
5164 */
5165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005166 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005167 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5168 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005169 }
5170
5171 /**
5172 * Returns the data network type for a subId
5173 */
5174 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005175 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5176 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005177 String functionName = "getDataNetworkTypeForSubscriber";
5178 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5179 mApp, functionName)) {
5180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5181 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5182 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5183 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 }
5185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 final long identity = Binder.clearCallingIdentity();
5187 try {
5188 final Phone phone = getPhone(subId);
5189 if (phone != null) {
5190 return phone.getServiceState().getDataNetworkType();
5191 } else {
5192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
5198
5199 /**
Wink Saville36469e72014-06-11 15:17:00 -07005200 * Returns the Voice network type for a subId
5201 */
5202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005203 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5204 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005205 String functionName = "getVoiceNetworkTypeForSubscriber";
5206 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5207 mApp, functionName)) {
5208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5209 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5210 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5211 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005212 }
5213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 final Phone phone = getPhone(subId);
5217 if (phone != null) {
5218 return phone.getServiceState().getVoiceNetworkType();
5219 } else {
5220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5221 }
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005225 }
5226
5227 /**
5228 * @return true if a ICC card is present
5229 */
5230 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005231 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005232 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5233 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005234 }
5235
5236 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005237 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005238 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005240 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 final Phone phone = PhoneFactory.getPhone(slotIndex);
5244 if (phone != null) {
5245 return phone.getIccCard().hasIccCard();
5246 } else {
5247 return false;
5248 }
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005252 }
5253
5254 /**
5255 * Return if the current radio is LTE on CDMA. This
5256 * is a tri-state return value as for a period of time
5257 * the mode may be unknown.
5258 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005259 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005260 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005261 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005262 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005264 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5265 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5266 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005267 }
5268
Sanket Padawe356d7632015-06-22 14:03:32 -07005269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005270 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5271 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005272 try {
5273 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5274 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005275 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5276 }
5277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 final Phone phone = getPhone(subId);
5281 if (phone == null) {
5282 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5283 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005284 return TelephonyProperties.lte_on_cdma_device()
5285 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005289 }
Wink Saville36469e72014-06-11 15:17:00 -07005290 }
5291
Wink Saville36469e72014-06-11 15:17:00 -07005292 /**
5293 * {@hide}
5294 * Returns Default subId, 0 in the case of single standby.
5295 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005296 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005297 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005298 }
5299
Shishir Agrawala9f32182016-04-12 12:00:16 -07005300 private int getSlotForDefaultSubscription() {
5301 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5302 }
5303
Wink Savilleb564aae2014-10-23 10:18:09 -07005304 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005305 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005306 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005307
Pengquan Menge92a50d2018-09-21 15:54:48 -07005308 private boolean isActiveSubscription(int subId) {
5309 return mSubscriptionController.isActiveSubId(subId);
5310 }
5311
Ihab Awadf2177b72013-11-25 13:33:23 -08005312 /**
5313 * @see android.telephony.TelephonyManager.WifiCallingChoices
5314 */
5315 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 final long identity = Binder.clearCallingIdentity();
5317 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5320 getWhenToMakeWifiCallsDefaultPreference());
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005324 }
5325
5326 /**
5327 * @see android.telephony.TelephonyManager.WifiCallingChoices
5328 */
5329 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005333 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005338 }
5339
Sailesh Nepald1e68152013-12-12 19:08:02 -08005340 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005341 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005342 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005343 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005344
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005345 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5346 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5347 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005348 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005349 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5350 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005351 }
5352 return PhoneFactory.getPhone(phoneId);
5353 }
5354
Shishir Agrawal566b7612013-10-28 14:41:00 -07005355 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005356 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005357 @NonNull IccLogicalChannelRequest request) {
5358 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5359 /*message=*/ "iccOpenLogicalChannel");
5360
5361 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5362 // Verify that the callingPackage in the request belongs to the calling UID
5363 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5364
5365 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005366 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005367
Rambo Wanga1782702021-11-10 20:15:19 -08005368 private Phone getPhoneFromValidIccLogicalChannelRequest(
5369 @NonNull IccLogicalChannelRequest request, String message) {
5370 Phone phone;
5371 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5373 mApp, request.subId, message);
5374 phone = getPhoneFromSubId(request.subId);
5375 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5376 enforceModifyPermission();
5377 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5378 } else {
5379 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005380 }
Rambo Wanga1782702021-11-10 20:15:19 -08005381 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005382 }
5383
5384 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005385 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005388 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5391 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5393 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 loge("The calling package is not allowed to access ISD-R.");
5395 throw new SecurityException(
5396 "The calling package is not allowed to access ISD-R.");
5397 }
Derek Tan740e1672017-06-27 14:56:27 -07005398 }
Derek Tan740e1672017-06-27 14:56:27 -07005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005401 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5402 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 return response;
5404 } finally {
5405 Binder.restoreCallingIdentity(identity);
5406 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005407 }
5408
5409 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005410 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5411 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5412 /*message=*/"iccCloseLogicalChannel");
5413
5414 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5415
5416 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005418
Rambo Wanga1782702021-11-10 20:15:19 -08005419 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5420 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005421 // before this feature is enabled, this API should only return false if
5422 // the operation fails instead of throwing runtime exception for
5423 // backward-compatibility.
5424 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5425 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 final long identity = Binder.clearCallingIdentity();
5427 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005428 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005429 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 }
Chen Xue9d737e2022-01-01 23:41:31 -08005431 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005432 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005433 Boolean success = false;
5434 if (result instanceof RuntimeException) {
5435 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005436 if (shouldThrowExceptionOnFailure) {
5437 throw (RuntimeException) result;
5438 } else {
5439 return false;
5440 }
Chen Xue9d737e2022-01-01 23:41:31 -08005441 } else if (result instanceof Boolean) {
5442 success = (Boolean) result;
5443 } else {
5444 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5445 }
Rambo Wanga1782702021-11-10 20:15:19 -08005446 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 return success;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005451 }
5452
5453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005454 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5457 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005458 if (DBG) {
5459 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5460 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5461 + p3 + " data=" + data);
5462 }
5463 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5464 command, p1, p2, p3, data);
5465 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005466
Jordan Liu4c733742019-02-28 12:03:40 -08005467 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005468 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5469 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005470 enforceModifyPermission();
5471 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5473 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5474 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005475 }
5476 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005477 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5478 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005479 }
5480
5481 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5482 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 final long identity = Binder.clearCallingIdentity();
5484 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005485 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 return "";
5487 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005490 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5491 null /* workSource */);
5492 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 // Append the returned status code to the end of the response payload.
5495 String s = Integer.toHexString(
5496 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5497 if (response.payload != null) {
5498 s = IccUtils.bytesToHexString(response.payload) + s;
5499 }
5500 return s;
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005504 }
Jake Hambye994d462014-02-03 13:10:13 -08005505
Evan Charltonc66da362014-05-16 14:06:40 -07005506 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005507 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5508 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5510 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005512 if (DBG) {
5513 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5514 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5515 }
5516 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5517 cla, command, p1, p2, p3, data);
5518 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005519
Jordan Liu4c733742019-02-28 12:03:40 -08005520 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005521 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5522 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005523 enforceModifyPermission();
5524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5525 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005526 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5527 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5528 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005529 }
5530
5531 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005532 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5533 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005534 }
5535
5536 // open APDU basic channel assuming the caller has sufficient permissions
5537 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5538 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5542 && TextUtils.equals(ISDR_AID, data)) {
5543 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005544 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5545 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 if (bestComponent == null
5547 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5548 loge("The calling package is not allowed to select ISD-R.");
5549 throw new SecurityException(
5550 "The calling package is not allowed to select ISD-R.");
5551 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005552 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005555 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5556 null /* workSource */);
5557 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 // Append the returned status code to the end of the response payload.
5560 String s = Integer.toHexString(
5561 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5562 if (response.payload != null) {
5563 s = IccUtils.bytesToHexString(response.payload) + s;
5564 }
5565 return s;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005568 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005569 }
5570
5571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5575 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005576
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 if (DBG) {
5580 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5581 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5582 }
5583
5584 IccIoResult response =
5585 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5586 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5587 subId);
5588
5589 if (DBG) {
5590 log("Exchange SIM_IO [R]" + response);
5591 }
5592
5593 byte[] result = null;
5594 int length = 2;
5595 if (response.payload != null) {
5596 length = 2 + response.payload.length;
5597 result = new byte[length];
5598 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5599 } else {
5600 result = new byte[length];
5601 }
5602
5603 result[length - 1] = (byte) response.sw2;
5604 result[length - 2] = (byte) response.sw1;
5605 return result;
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005609 }
5610
Nathan Haroldb3014052017-01-25 15:57:32 -08005611 /**
5612 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5613 * on a particular subscription
5614 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005615 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5616 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005618 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005619 return null;
5620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621
5622 final long identity = Binder.clearCallingIdentity();
5623 try {
5624 if (appType != TelephonyManager.APPTYPE_USIM
5625 && appType != TelephonyManager.APPTYPE_SIM) {
5626 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5627 return null;
5628 }
5629 Object response = sendRequest(
5630 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5631 if (response instanceof String[]) {
5632 return (String[]) response;
5633 }
yincheng zhao2737e882019-09-06 17:06:54 -07005634 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005636 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005639 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005640 }
5641
yincheng zhao2737e882019-09-06 17:06:54 -07005642 /**
5643 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5644 * subscription.
5645 *
5646 * @param subId the id of the subscription.
5647 * @param appType the uicc app type, must be USIM or SIM.
5648 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5649 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005650 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005651 * @return number of fplmns that is successfully written to the SIM.
5652 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005653 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5654 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setForbiddenPlmns");
5657
yincheng zhao2737e882019-09-06 17:06:54 -07005658 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5659 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5660 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5661 }
5662 if (fplmns == null) {
5663 throw new IllegalArgumentException("Fplmn List provided is null");
5664 }
5665 for (String fplmn : fplmns) {
5666 if (!CellIdentity.isValidPlmn(fplmn)) {
5667 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5668 }
5669 }
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 Object response = sendRequest(
5673 CMD_SET_FORBIDDEN_PLMNS,
5674 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5675 subId);
5676 return (int) response;
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
5680 }
5681
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005682 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005683 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5685 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5690 if (response.payload == null) {
5691 return "";
5692 }
Evan Charltonc66da362014-05-16 14:06:40 -07005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 // Append the returned status code to the end of the response payload.
5695 String s = Integer.toHexString(
5696 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5697 s = IccUtils.bytesToHexString(response.payload) + s;
5698 return s;
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Evan Charltonc66da362014-05-16 14:06:40 -07005702 }
5703
Jake Hambye994d462014-02-03 13:10:13 -08005704 /**
5705 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5706 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5707 *
5708 * @param itemID the ID of the item to read
5709 * @return the NV item as a String, or null on error.
5710 */
5711 @Override
5712 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005713 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
5719 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005720 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5722 return value;
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
Jake Hambye994d462014-02-03 13:10:13 -08005726 }
5727
5728 /**
5729 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5730 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5731 *
5732 * @param itemID the ID of the item to read
5733 * @param itemValue the value to write, as a String
5734 * @return true on success; false on any failure
5735 */
5736 @Override
5737 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005738 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
5744 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5745 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005746 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5748 return success;
5749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Jake Hambye994d462014-02-03 13:10:13 -08005752 }
5753
5754 /**
5755 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5756 * Used for device configuration by some CDMA operators.
5757 *
5758 * @param preferredRoamingList byte array containing the new PRL
5759 * @return true on success; false on any failure
5760 */
5761 @Override
5762 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5764 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
5768 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5769 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5770 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5771 return success;
5772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Jake Hambye994d462014-02-03 13:10:13 -08005775 }
5776
5777 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005778 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005779 * Used for device configuration by some CDMA operators.
5780 *
chen xu6dac5ab2018-10-26 17:39:23 -07005781 * @param slotIndex - device slot.
5782 *
Jake Hambye994d462014-02-03 13:10:13 -08005783 * @return true on success; false on any failure
5784 */
5785 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005786 public boolean resetModemConfig(int slotIndex) {
5787 Phone phone = PhoneFactory.getPhone(slotIndex);
5788 if (phone != null) {
5789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5790 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791
chen xu6dac5ab2018-10-26 17:39:23 -07005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5795 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5796 return success;
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 }
chen xu6dac5ab2018-10-26 17:39:23 -07005801 return false;
5802 }
5803
5804 /**
5805 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5806 *
5807 * @param slotIndex - device slot.
5808 *
5809 * @return true on success; false on any failure
5810 */
5811 @Override
5812 public boolean rebootModem(int slotIndex) {
5813 Phone phone = PhoneFactory.getPhone(slotIndex);
5814 if (phone != null) {
5815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5816 mApp, phone.getSubId(), "rebootModem");
5817
5818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5821 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5822 return success;
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
5825 }
5826 }
5827 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005828 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005829
Brad Ebinger51f743a2017-01-23 13:50:20 -08005830 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005831 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5832 * {@link #disableIms(int)}.
5833 * @param slotIndex device slot.
5834 */
5835 public void resetIms(int slotIndex) {
5836 enforceModifyPermission();
5837
5838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 if (mImsResolver == null) {
5841 // may happen if the does not support IMS.
5842 return;
5843 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005844 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005845 } finally {
5846 Binder.restoreCallingIdentity(identity);
5847 }
5848 }
5849
5850 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005851 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5852 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005853 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005854 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005855 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005860 // may happen if the device does not support IMS.
5861 return;
5862 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005867 }
5868
5869 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005870 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5871 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005872 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005873 public void disableIms(int slotId) {
5874 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875
5876 final long identity = Binder.clearCallingIdentity();
5877 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005878 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005879 // may happen if the device does not support IMS.
5880 return;
5881 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 } finally {
5884 Binder.restoreCallingIdentity(identity);
5885 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005886 }
5887
5888 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005889 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5890 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005891 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005892 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005893 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005894 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895
5896 final long identity = Binder.clearCallingIdentity();
5897 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005898 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005899 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5900 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005901 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005902 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005906 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005907 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005908 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5909 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005910 @Override
5911 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005912 enforceModifyPermission();
5913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005917 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005924 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005925 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005926 */
5927 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929
5930 final long identity = Binder.clearCallingIdentity();
5931 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005932 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005933 // may happen if the device does not support IMS.
5934 return null;
5935 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005940 }
5941
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005942 /**
5943 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005944 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005945 */
5946 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5947 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948
5949 final long identity = Binder.clearCallingIdentity();
5950 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005951 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005952 // may happen if the device does not support IMS.
5953 return null;
5954 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005959 }
5960
Brad Ebinger884c07b2018-02-15 16:17:40 -08005961 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005962 * Sets the ImsService Package Name that Telephony will bind to.
5963 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005964 * @param slotIndex the slot ID that the ImsService should bind for.
5965 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005967 * @param featureTypes An integer array of feature types associated with a packageName.
5968 * @param packageName The name of the package that the current configuration will be replaced
5969 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005971 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005972 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5973 int[] featureTypes, String packageName) {
5974 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5975 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5977 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005978 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 final long identity = Binder.clearCallingIdentity();
5981 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005983 // may happen if the device does not support IMS.
5984 return false;
5985 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 Map<Integer, String> featureConfig = new HashMap<>();
5987 for (int featureType : featureTypes) {
5988 featureConfig.put(featureType, packageName);
5989 }
5990 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5991 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005995 }
5996
5997 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005998 * Clears any carrier ImsService overrides for the slot index specified that were previously
5999 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6000 *
6001 * This should only be used for testing.
6002 *
6003 * @param slotIndex the slot ID that the ImsService should bind for.
6004 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6005 */
6006 @Override
6007 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6008 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6010 "clearCarrierImsServiceOverride");
6011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6012 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6013 "clearCarrierImsServiceOverride");
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 if (mImsResolver == null) {
6018 // may happen if the device does not support IMS.
6019 return false;
6020 }
6021 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006028 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006029 *
6030 * @param slotId The slot that the ImsService is associated with.
6031 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6032 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006033 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006034 * @return the package name of the ImsService configuration.
6035 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006036 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6037 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006038 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006039 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006040 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006041 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6042 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006046 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006047 // may happen if the device does not support IMS.
6048 return "";
6049 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006050 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006051 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6052 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006056 }
6057
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006058 /**
6059 * Get the MmTelFeature state associated with the requested subscription id.
6060 * @param subId The subscription that the MmTelFeature is associated with.
6061 * @param callback A callback with an integer containing the
6062 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6063 */
6064 @Override
6065 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6066 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6069 "IMS not available on device.");
6070 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006071 final long token = Binder.clearCallingIdentity();
6072 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006073 int slotId = getSlotIndex(subId);
6074 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6075 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6076 + subId + "'");
6077 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6078 }
6079 verifyImsMmTelConfiguredOrThrow(slotId);
6080 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6081 try {
6082 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6083 } catch (RemoteException e) {
6084 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6085 + "Ignore");
6086 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006087 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006088 } catch (ImsException e) {
6089 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006090 } finally {
6091 Binder.restoreCallingIdentity(token);
6092 }
6093 }
6094
Daniel Brightbb5840b2021-01-12 15:48:18 -08006095 /**
6096 * Sets the ims registration state on all valid {@link Phone}s.
6097 */
6098 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006103 // NOTE: Before S, this method only set the default phone.
6104 for (final Phone phone : PhoneFactory.getPhones()) {
6105 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6106 phone.setImsRegistrationState(registered);
6107 }
6108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
Wink Saville36469e72014-06-11 15:17:00 -07006112 }
6113
6114 /**
Stuart Scott54788802015-03-30 13:18:01 -07006115 * Set the network selection mode to automatic.
6116 *
6117 */
6118 @Override
6119 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6121 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
shilufc958392020-01-20 11:36:01 -08006125 if (!isActiveSubscription(subId)) {
6126 return;
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006129 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6130 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Stuart Scott54788802015-03-30 13:18:01 -07006134 }
6135
Jack Yud10cdd42020-09-28 20:28:01 -07006136 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006137 * Ask the radio to connect to the input network and change selection mode to manual.
6138 *
6139 * @param subId the id of the subscription.
6140 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6141 * the operator to attach to.
6142 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6143 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6144 * normal network selection next time.
6145 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006146 */
6147 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006148 public boolean setNetworkSelectionModeManual(
6149 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6151 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006152
6153 if (!isActiveSubscription(subId)) {
6154 return false;
6155 }
6156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006159 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006161 if (DBG) {
6162 log("setNetworkSelectionModeManual: subId: " + subId
6163 + " operator: " + operatorInfo);
6164 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006165 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
6168 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006169 }
shilu84f6e8b2019-12-19 13:58:01 -08006170 /**
6171 * Get the manual network selection
6172 *
6173 * @param subId the id of the subscription.
6174 *
6175 * @return the previously saved user selected PLMN
6176 */
6177 @Override
6178 public String getManualNetworkSelectionPlmn(int subId) {
6179 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006180 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006181 mApp, subId, "getManualNetworkSelectionPlmn");
6182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006186 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006187 }
6188
6189 final Phone phone = getPhone(subId);
6190 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006191 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006192 }
6193 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6194 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6195 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006200
6201 /**
6202 * Scans for available networks.
6203 */
6204 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006205 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6206 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6208 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006209 LocationAccessPolicy.LocationPermissionResult locationResult =
6210 LocationAccessPolicy.checkLocationPermission(mApp,
6211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6212 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006213 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006214 .setCallingPid(Binder.getCallingPid())
6215 .setCallingUid(Binder.getCallingUid())
6216 .setMethod("getCellNetworkScanResults")
6217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006218 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6219 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006220 .build());
6221 switch (locationResult) {
6222 case DENIED_HARD:
6223 throw new SecurityException("Not allowed to access scan results -- location");
6224 case DENIED_SOFT:
6225 return null;
6226 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227
Pengquan Menga1bb6272018-09-06 09:59:22 -07006228 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 try {
6230 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006231 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006236 }
6237
6238 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006239 * Get the call forwarding info, given the call forwarding reason.
6240 */
6241 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006242 public void getCallForwarding(int subId, int callForwardingReason,
6243 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006244 enforceReadPrivilegedPermission("getCallForwarding");
6245 long identity = Binder.clearCallingIdentity();
6246 try {
6247 if (DBG) {
6248 log("getCallForwarding: subId " + subId
6249 + " callForwardingReason" + callForwardingReason);
6250 }
Hall Liu27d24262020-09-18 19:04:59 -07006251
6252 Phone phone = getPhone(subId);
6253 if (phone == null) {
6254 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006255 callback.onError(
6256 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006257 } catch (RemoteException e) {
6258 // ignore
6259 }
6260 return;
6261 }
6262
6263 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6264 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6265 @Override
6266 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6267 try {
6268 callback.onCallForwardingInfoAvailable(info);
6269 } catch (RemoteException e) {
6270 // ignore
6271 }
6272 }
6273
6274 @Override
6275 public void onError(int error) {
6276 try {
6277 callback.onError(error);
6278 } catch (RemoteException e) {
6279 // ignore
6280 }
6281 }
6282 });
6283 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286 }
6287 }
6288
6289 /**
6290 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6291 * reason, the number to forward, and the timeout before the forwarding is attempted.
6292 */
6293 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006294 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6295 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006296 enforceModifyPermission();
6297 long identity = Binder.clearCallingIdentity();
6298 try {
6299 if (DBG) {
6300 log("setCallForwarding: subId " + subId
6301 + " callForwardingInfo" + callForwardingInfo);
6302 }
Hall Liu27d24262020-09-18 19:04:59 -07006303
6304 Phone phone = getPhone(subId);
6305 if (phone == null) {
6306 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006307 callback.accept(
6308 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006309 } catch (RemoteException e) {
6310 // ignore
6311 }
6312 return;
6313 }
6314
6315 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6316 FunctionalUtils.ignoreRemoteException(callback::accept));
6317
6318 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
6322 }
6323
6324 /**
Hall Liu27d24262020-09-18 19:04:59 -07006325 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006326 */
6327 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006328 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006329 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006330 long identity = Binder.clearCallingIdentity();
6331 try {
Hall Liu27d24262020-09-18 19:04:59 -07006332 Phone phone = getPhone(subId);
6333 if (phone == null) {
6334 try {
6335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6336 } catch (RemoteException e) {
6337 // ignore
6338 }
6339 return;
6340 }
SongFerngWang0e767992021-03-31 22:08:45 +08006341 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6342 PersistableBundle c = configManager.getConfigForSubId(subId);
6343 boolean requireUssd = c.getBoolean(
6344 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006345
Shuo Qian4a594052020-01-23 11:59:30 -08006346 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006347 if (requireUssd) {
6348 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6349 getSubscriptionCarrierId(subId));
6350 String newUssdCommand = "";
6351 try {
6352 newUssdCommand = carrierXmlParser.getFeature(
6353 CarrierXmlParser.FEATURE_CALL_WAITING)
6354 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6355 } catch (NullPointerException e) {
6356 loge("Failed to generate USSD number" + e);
6357 }
6358 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6359 mMainThreadHandler, callback, carrierXmlParser,
6360 CarrierXmlParser.SsEntry.SSAction.QUERY);
6361 final String ussdCommand = newUssdCommand;
6362 Executors.newSingleThreadExecutor().execute(() -> {
6363 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6364 });
6365 } else {
6366 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6367 callback::accept);
6368 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6369 }
Shuo Qian4a594052020-01-23 11:59:30 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
6375 /**
Hall Liu27d24262020-09-18 19:04:59 -07006376 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006377 */
6378 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006379 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006380 enforceModifyPermission();
6381 long identity = Binder.clearCallingIdentity();
6382 try {
Hall Liu27d24262020-09-18 19:04:59 -07006383 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6384
6385 Phone phone = getPhone(subId);
6386 if (phone == null) {
6387 try {
6388 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6389 } catch (RemoteException e) {
6390 // ignore
6391 }
6392 return;
6393 }
6394
SongFerngWang0e767992021-03-31 22:08:45 +08006395 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6396 PersistableBundle c = configManager.getConfigForSubId(subId);
6397 boolean requireUssd = c.getBoolean(
6398 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006399
SongFerngWang0e767992021-03-31 22:08:45 +08006400 if (DBG) log("getCallWaitingStatus: subId " + subId);
6401 if (requireUssd) {
6402 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6403 getSubscriptionCarrierId(subId));
6404 CarrierXmlParser.SsEntry.SSAction ssAction =
6405 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6406 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6407 String newUssdCommand = "";
6408 try {
6409 newUssdCommand = carrierXmlParser.getFeature(
6410 CarrierXmlParser.FEATURE_CALL_WAITING)
6411 .makeCommand(ssAction, null);
6412 } catch (NullPointerException e) {
6413 loge("Failed to generate USSD number" + e);
6414 }
6415 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6416 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6417 final String ussdCommand = newUssdCommand;
6418 Executors.newSingleThreadExecutor().execute(() -> {
6419 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6420 });
6421 } else {
6422 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6423 FunctionalUtils.ignoreRemoteException(callback::accept));
6424
6425 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6426 }
Shuo Qian4a594052020-01-23 11:59:30 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
6432 /**
yinxub1bed742017-04-17 11:45:04 -07006433 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006434 *
yinxub1bed742017-04-17 11:45:04 -07006435 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006436 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6437 * location related information which will be sent if the caller already possess
6438 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006439 * @param request contains the radio access networks with bands/channels to scan
6440 * @param messenger callback messenger for scan results or errors
6441 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006442 * @return the id of the requested scan which can be used to stop the scan.
6443 */
6444 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006445 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6446 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006447 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6449 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006450 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006451 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6452 if (!renounceFineLocationAccess) {
6453 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6454 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6455 .setCallingPackage(callingPackage)
6456 .setCallingFeatureId(callingFeatureId)
6457 .setCallingPid(Binder.getCallingPid())
6458 .setCallingUid(Binder.getCallingUid())
6459 .setMethod("requestNetworkScan")
6460 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6461 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6462 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6463 .build());
6464 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006465 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006466 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6467 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006468 if (e != null) {
6469 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6470 throw e;
6471 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006472 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006473 return TelephonyScanManager.INVALID_SCAN_ID;
6474 }
6475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006476 }
Hall Liu912dfd32019-04-25 14:02:26 -07006477 int callingUid = Binder.getCallingUid();
6478 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006479 final long identity = Binder.clearCallingIdentity();
6480 try {
6481 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006482 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006483 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
yinxu504e1392017-04-12 16:03:22 -07006487 }
6488
Hall Liub2ac8ef2019-02-28 15:56:23 -08006489 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006490 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006491 boolean hasCarrierPriv;
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6495 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Hall Liu558027f2019-05-15 19:14:05 -07006499 boolean hasNetworkScanPermission =
6500 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6501 == PERMISSION_GRANTED;
6502
6503 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6504 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6505 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006506 }
6507
6508 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6509 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6511 return new SecurityException("Specific channels must not be"
6512 + " scanned without location access.");
6513 }
6514 }
6515 }
6516
Hall Liub2ac8ef2019-02-28 15:56:23 -08006517 return null;
6518 }
6519
yinxu504e1392017-04-12 16:03:22 -07006520 /**
6521 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006522 *
6523 * @param subId id of the subscription
6524 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006525 */
6526 @Override
6527 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6529 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006530
Hall Liu912dfd32019-04-25 14:02:26 -07006531 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 final long identity = Binder.clearCallingIdentity();
6533 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006534 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
yinxu504e1392017-04-12 16:03:22 -07006538 }
6539
6540 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006542 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006544 */
6545 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006547 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006548 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 if (DBG) log("getAllowedNetworkTypesBitmask");
6554 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6555 int networkTypesBitmask = (result != null ? result[0] : -1);
6556 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6557 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006561 }
6562
6563 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006564 * Get the allowed network types for certain reason.
6565 *
6566 * @param subId the id of the subscription.
6567 * @param reason the reason the allowed network type change is taking place
6568 * @return the allowed network types.
6569 */
6570 @Override
6571 public long getAllowedNetworkTypesForReason(int subId,
6572 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006573 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006574 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 }
6582
6583 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006584 * Enable/Disable E-UTRA-NR Dual Connectivity
6585 * @param subId subscription id of the sim card
6586 * @param nrDualConnectivityState expected NR dual connectivity state
6587 * This can be passed following states
6588 * <ol>
6589 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6590 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6591 * <li>Disable NR dual connectivity and force secondary cell to be released
6592 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6593 * </ol>
6594 * @return operation result.
6595 */
6596 @Override
6597 public int setNrDualConnectivityState(int subId,
6598 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6600 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006601 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006602 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6603 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6604 }
6605
Sooraj Sasindran37444802020-08-11 10:40:43 -07006606 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6610 nrDualConnectivityState, subId,
6611 workSource);
6612 if (DBG) log("enableNRDualConnectivity result: " + result);
6613 return result;
6614 } finally {
6615 Binder.restoreCallingIdentity(identity);
6616 }
6617 }
6618
6619 /**
6620 * Is E-UTRA-NR Dual Connectivity enabled
6621 * @return true if dual connectivity is enabled else false
6622 */
6623 @Override
6624 public boolean isNrDualConnectivityEnabled(int subId) {
6625 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006626 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006627 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006628 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006629 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6630 return false;
6631 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006632 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6636 null, subId, workSource);
6637 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6638 return isEnabled;
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
6643
6644 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006645 * Set the allowed network types of the device and
6646 * provide the reason triggering the allowed network change.
6647 *
6648 * @param subId the id of the subscription.
6649 * @param reason the reason the allowed network type change is taking place
6650 * @param allowedNetworkTypes the allowed network types.
6651 * @return true on success; false on any failure.
6652 */
6653 @Override
6654 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006655 @TelephonyManager.AllowedNetworkTypesReason int reason,
6656 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6658 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006660 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6661 return false;
6662 }
6663 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6664 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006665 return false;
6666 }
6667
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006668 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6669 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6670
6671
6672 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6673 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6674 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006675 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006676
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006677 final long identity = Binder.clearCallingIdentity();
6678 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006679 Boolean success = (Boolean) sendRequest(
6680 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6681 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6682
6683 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6684 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
6689
6690 /**
Miaoa84611c2019-03-15 09:21:10 +08006691 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006692 *
Miaoa84611c2019-03-15 09:21:10 +08006693 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006694 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006695 * @hide
6696 */
6697 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006698 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006701 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 try {
Miaoa84611c2019-03-15 09:21:10 +08006703 if (phone != null) {
6704 return phone.hasMatchedTetherApnSetting();
6705 } else {
6706 return false;
6707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006710 }
Junda Liu475951f2014-11-07 16:45:03 -08006711 }
6712
6713 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006714 * Get the user enabled state of Mobile Data.
6715 *
6716 * TODO: remove and use isUserDataEnabled.
6717 * This can't be removed now because some vendor codes
6718 * calls through ITelephony directly while they should
6719 * use TelephonyManager.
6720 *
6721 * @return true on enabled
6722 */
6723 @Override
6724 public boolean getDataEnabled(int subId) {
6725 return isUserDataEnabled(subId);
6726 }
6727
6728 /**
6729 * Get whether mobile data is enabled per user setting.
6730 *
6731 * There are other factors deciding whether mobile data is actually enabled, but they are
6732 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006733 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006734 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6735 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006736 *
6737 * @return {@code true} if data is enabled else {@code false}
6738 */
6739 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006740 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006741 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006742 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006743 try {
6744 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6745 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006746 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6748 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006749 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006751 mApp, subId, functionName);
6752
Robert Greenwalt646120a2014-05-23 11:54:03 -07006753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754
6755 final long identity = Binder.clearCallingIdentity();
6756 try {
6757 int phoneId = mSubscriptionController.getPhoneId(subId);
6758 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6759 Phone phone = PhoneFactory.getPhone(phoneId);
6760 if (phone != null) {
6761 boolean retVal = phone.isUserDataEnabled();
6762 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6763 return retVal;
6764 } else {
6765 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6766 return false;
6767 }
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006770 }
6771 }
6772
6773 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006774 * Checks if the device is capable of mobile data by considering whether whether the
6775 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6776 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006777 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006778 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006779 */
6780 @Override
6781 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006782 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006783 try {
6784 try {
6785 mApp.enforceCallingOrSelfPermission(
6786 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006787 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006788 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006789 try {
6790 mApp.enforceCallingOrSelfPermission(
6791 android.Manifest.permission.READ_PHONE_STATE,
6792 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006793 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006794 mApp.enforceCallingOrSelfPermission(
6795 permission.READ_BASIC_PHONE_STATE, functionName);
6796 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006797 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006798 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006799 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801
6802 final long identity = Binder.clearCallingIdentity();
6803 try {
6804 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 Phone phone = PhoneFactory.getPhone(phoneId);
6806 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006807 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006808 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006809 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 return retVal;
6811 } else {
6812 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6813 return false;
6814 }
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006817 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006818 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006819
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006820 /**
6821 * Check if data is enabled for a specific reason
6822 * @param subId Subscription index
6823 * @param reason the reason the data enable change is taking place
6824 * @return {@code true} if the overall data is enabled; {@code false} if not.
6825 */
6826 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006827 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006828 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006829 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006830 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006831 try {
6832 mApp.enforceCallingOrSelfPermission(
6833 android.Manifest.permission.ACCESS_NETWORK_STATE,
6834 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006835 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006836 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6837 functionName);
6838 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006839 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006840 try {
6841 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006842 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006843 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006845 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006846 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006847 }
6848
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 int phoneId = mSubscriptionController.getPhoneId(subId);
6853 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006854 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006855 + " reason=" + reason);
6856 }
6857 Phone phone = PhoneFactory.getPhone(phoneId);
6858 if (phone != null) {
6859 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006860 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006861 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006862 return retVal;
6863 } else {
6864 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006865 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006866 + subId + " retVal=false");
6867 }
6868 return false;
6869 }
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
6873 }
6874
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006875 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006876 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006877 // No permission needed; this only lets the caller inspect their own status.
6878 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006879 }
Junda Liu29340342014-07-10 15:23:27 -07006880
6881 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006882 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006883 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006884 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6885 }
6886
6887 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6888 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006889 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006890 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006891 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6892 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006893 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6894 if (cpt == null) {
6895 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006896 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6897 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006898 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006899 }
6900
6901 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006902 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006903 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006904 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006905 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006906 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006907 Phone phone = getPhone(subId);
6908 if (phone == null) {
6909 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6910 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6911 }
6912 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6913 if (cpt == null) {
6914 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006915 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6916 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006917 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006918 }
6919
6920 @Override
6921 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006922 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006923 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6924 }
6925
6926 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006927 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006929 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006930 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006931 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6932 Phone phone = PhoneFactory.getPhone(phoneId);
6933 if (phone == null) {
6934 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006935 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006936 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6937 if (cpt == null) {
6938 continue;
6939 }
6940 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006941 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6942 break;
6943 }
6944 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006945 return result;
Junda Liu29340342014-07-10 15:23:27 -07006946 }
Derek Tan89e89d42014-07-08 17:00:10 -07006947
6948 @Override
Junda Liue64de782015-04-16 17:19:16 -07006949 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006950 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006951 Phone phone = PhoneFactory.getPhone(phoneId);
6952 if (phone == null) {
6953 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006954 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006955 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6956 if (cpt == null) {
6957 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006958 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006959 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006960 }
6961
Amith Yamasani6e118872016-02-19 12:53:51 -08006962 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006963 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006964 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006965 Phone phone = PhoneFactory.getPhone(phoneId);
6966 if (phone == null) {
6967 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006968 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006969 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6970 if (cpt == null) {
6971 return Collections.emptyList();
6972 }
6973 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006974 }
6975
chen xuf7e9fe82019-05-09 19:31:02 -07006976 @Override
6977 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006978 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006979 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006980 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006981 try {
6982 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6983 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6984 }
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006987 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006988 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006989 }
6990
Rambo Wang6812ffb2022-03-15 16:54:17 -07006991 @Override
6992 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6993 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6994
6995 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6996 if (phone == null) {
6997 return null;
6998 }
6999 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7000 if (cpt == null) {
7001 return null;
7002 }
7003 return cpt.getCarrierServicePackageName();
7004 }
7005
Wink Savilleb564aae2014-10-23 10:18:09 -07007006 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007007 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007008 UiccPort port = phone == null ? null : phone.getUiccPort();
7009 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007010 return null;
7011 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007012 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007013 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007014 return null;
7015 }
7016 return iccId;
7017 }
7018
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007019 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007020 public void setCallComposerStatus(int subId, int status) {
7021 enforceModifyPermission();
7022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 Phone phone = getPhone(subId);
7026 if (phone != null) {
7027 Phone defaultPhone = phone.getImsPhone();
7028 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7029 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7030 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007031 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7032 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007033 }
7034 }
Shuo Qian284ae752020-12-22 19:10:14 -08007035 } catch (ImsException e) {
7036 throw new ServiceSpecificException(e.getCode());
7037 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007038 Binder.restoreCallingIdentity(identity);
7039 }
7040 }
7041
7042 @Override
7043 public int getCallComposerStatus(int subId) {
7044 enforceReadPrivilegedPermission("getCallComposerStatus");
7045
7046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 Phone phone = getPhone(subId);
7049 if (phone != null) {
7050 Phone defaultPhone = phone.getImsPhone();
7051 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7052 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7053 return imsPhone.getCallComposerStatus();
7054 }
7055 }
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7060 }
7061
7062 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007063 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7064 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007065 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007066 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 final String iccId = getIccId(subId);
7071 final Phone phone = getPhone(subId);
7072 if (phone == null) {
7073 return false;
7074 }
7075 final String subscriberId = phone.getSubscriberId();
7076
7077 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007078 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 + subscriberId + " to " + number);
7080 }
7081
7082 if (TextUtils.isEmpty(iccId)) {
7083 return false;
7084 }
7085
7086 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7087
7088 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7089 if (alphaTag == null) {
7090 editor.remove(alphaTagPrefKey);
7091 } else {
7092 editor.putString(alphaTagPrefKey, alphaTag);
7093 }
7094
7095 // Record both the line number and IMSI for this ICCID, since we need to
7096 // track all merged IMSIs based on line number
7097 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7098 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7099 if (number == null) {
7100 editor.remove(numberPrefKey);
7101 editor.remove(subscriberPrefKey);
7102 } else {
7103 editor.putString(numberPrefKey, number);
7104 editor.putString(subscriberPrefKey, subscriberId);
7105 }
7106
7107 editor.commit();
7108 return true;
7109 } finally {
7110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007111 }
Derek Tan7226c842014-07-02 17:42:23 -07007112 }
7113
7114 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007115 public String getLine1NumberForDisplay(int subId, String callingPackage,
7116 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007117 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007120 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007121 return null;
7122 }
Derek Tan97ebb422014-09-05 16:55:38 -07007123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 String iccId = getIccId(subId);
7127 if (iccId != null) {
7128 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7129 if (DBG_MERGE) {
7130 log("getLine1NumberForDisplay returning "
7131 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7132 }
7133 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007134 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7136 return null;
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007139 }
Derek Tan7226c842014-07-02 17:42:23 -07007140 }
7141
7142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7144 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007146 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007147 return null;
7148 }
Derek Tan97ebb422014-09-05 16:55:38 -07007149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 String iccId = getIccId(subId);
7153 if (iccId != null) {
7154 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7155 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7156 }
7157 return null;
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007160 }
Derek Tan7226c842014-07-02 17:42:23 -07007161 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007162
7163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007164 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7165 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007166 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7167 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007170 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007171 return null;
7172 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007173
Jordan Liub49b04b2019-05-06 14:45:15 -07007174 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7175 // the process, where TelephonyManager was instantiated.
7176 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007177 final long identity = Binder.clearCallingIdentity();
7178 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007179 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 final TelephonyManager tele = TelephonyManager.from(context);
7181 final SubscriptionManager sub = SubscriptionManager.from(context);
7182
7183 // Figure out what subscribers are currently active
7184 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185
Jordan Liub49b04b2019-05-06 14:45:15 -07007186 // Only consider subs which match the current subId
7187 // This logic can be simplified. See b/131189269 for progress.
7188 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007189 activeSubscriberIds.add(tele.getSubscriberId(subId));
7190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191
7192 // First pass, find a number override for an active subscriber
7193 String mergeNumber = null;
7194 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7195 for (String key : prefs.keySet()) {
7196 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7197 final String subscriberId = (String) prefs.get(key);
7198 if (activeSubscriberIds.contains(subscriberId)) {
7199 final String iccId = key.substring(
7200 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7201 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7202 mergeNumber = (String) prefs.get(numberKey);
7203 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007204 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 + " for active subscriber " + subscriberId);
7206 }
7207 if (!TextUtils.isEmpty(mergeNumber)) {
7208 break;
7209 }
7210 }
7211 }
7212 }
7213
7214 // Shortcut when no active merged subscribers
7215 if (TextUtils.isEmpty(mergeNumber)) {
7216 return null;
7217 }
7218
7219 // Second pass, find all subscribers under that line override
7220 final ArraySet<String> result = new ArraySet<>();
7221 for (String key : prefs.keySet()) {
7222 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7223 final String number = (String) prefs.get(key);
7224 if (mergeNumber.equals(number)) {
7225 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7226 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7227 final String subscriberId = (String) prefs.get(subscriberKey);
7228 if (!TextUtils.isEmpty(subscriberId)) {
7229 result.add(subscriberId);
7230 }
7231 }
7232 }
7233 }
7234
7235 final String[] resultArray = result.toArray(new String[result.size()]);
7236 Arrays.sort(resultArray);
7237 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007238 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7240 }
7241 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007242 } finally {
7243 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007244 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007245 }
7246
7247 @Override
zoey chen38003472019-12-13 17:16:31 +08007248 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7249 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 final TelephonyManager telephonyManager = mApp.getSystemService(
7254 TelephonyManager.class);
7255 String subscriberId = telephonyManager.getSubscriberId(subId);
7256 if (subscriberId == null) {
7257 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007258 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007259 + subId);
7260 }
7261 return null;
7262 }
7263
7264 final SubscriptionInfo info = SubscriptionController.getInstance()
7265 .getSubscriptionInfo(subId);
7266 final ParcelUuid groupUuid = info.getGroupUuid();
7267 // If it doesn't belong to any group, return just subscriberId of itself.
7268 if (groupUuid == null) {
7269 return new String[]{subscriberId};
7270 }
7271
7272 // Get all subscriberIds from the group.
7273 final List<String> mergedSubscriberIds = new ArrayList<>();
7274 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007275 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007276 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007277 for (SubscriptionInfo subInfo : groupInfos) {
7278 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7279 if (subscriberId != null) {
7280 mergedSubscriberIds.add(subscriberId);
7281 }
7282 }
7283
7284 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
7287
7288 }
7289 }
7290
7291 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007292 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007293 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007294 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 final Phone phone = getPhone(subId);
7299 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007303 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007304
7305 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007306 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007307 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7308 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007309 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7310 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 final Phone phone = getPhone(subId);
7315 if (phone == null) {
7316 return false;
7317 }
7318 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7319 cdmaNonRoamingList);
7320 } finally {
7321 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007322 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007323 }
7324
7325 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007326 @Deprecated
7327 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7328 enforceModifyPermission();
7329
7330 int returnValue = 0;
7331 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007332 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007333 if(result.exception == null) {
7334 if (result.result != null) {
7335 byte[] responseData = (byte[])(result.result);
7336 if(responseData.length > oemResp.length) {
7337 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7338 responseData.length + "bytes. Buffer Size is " +
7339 oemResp.length + "bytes.");
7340 }
7341 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7342 returnValue = responseData.length;
7343 }
7344 } else {
7345 CommandException ex = (CommandException) result.exception;
7346 returnValue = ex.getCommandError().ordinal();
7347 if(returnValue > 0) returnValue *= -1;
7348 }
7349 } catch (RuntimeException e) {
7350 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7351 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7352 if(returnValue > 0) returnValue *= -1;
7353 }
7354
7355 return returnValue;
7356 }
7357
7358 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007359 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007360 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007361 try {
7362 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007363 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007364 mApp, phone.getSubId(), "getRadioAccessFamily");
7365 } catch (SecurityException e) {
7366 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7367 throw e;
7368 }
chen xub97461a2018-10-26 14:17:57 -07007369 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007370 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007371 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 final long identity = Binder.clearCallingIdentity();
7374 try {
chen xub97461a2018-10-26 14:17:57 -07007375 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007376 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007377 mApp, phone.getSubId(), "getRadioAccessFamily");
7378 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 } finally {
7380 Binder.restoreCallingIdentity(identity);
7381 }
chen xub97461a2018-10-26 14:17:57 -07007382 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007383 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007384
7385 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007386 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007387 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007388 try {
7389 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7390 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007391 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007392 }
7393 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007394 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007395 }
7396 RoleManager rm = mApp.getSystemService(RoleManager.class);
7397 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7398 if (!dialerRoleHolders.contains(callingPackage)) {
7399 throw new SecurityException("App must be the dialer role holder to"
7400 + " upload a call composer pic");
7401 }
7402
7403 Executors.newSingleThreadExecutor().execute(() -> {
7404 ByteArrayOutputStream output = new ByteArrayOutputStream(
7405 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7406 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7407 boolean readUntilEnd = false;
7408 int totalBytesRead = 0;
7409 byte[] buffer = new byte[16 * 1024];
7410 while (true) {
7411 int numRead;
7412 try {
7413 numRead = input.read(buffer);
7414 } catch (IOException e) {
7415 try {
7416 fd.checkError();
7417 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7418 null);
7419 } catch (IOException e1) {
7420 // This means that the other side closed explicitly with an error. If this
7421 // happens, log and ignore.
7422 loge("Remote end of call composer picture pipe closed: " + e1);
7423 }
7424 break;
7425 }
7426 if (numRead == -1) {
7427 readUntilEnd = true;
7428 break;
7429 }
7430 totalBytesRead += numRead;
7431 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7432 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7433 try {
7434 input.close();
7435 } catch (IOException e) {
7436 // ignore
7437 }
7438 break;
7439 }
7440 output.write(buffer, 0, numRead);
7441 }
7442 // Generally, the remote end will close the file descriptors. The only case where we
7443 // close is above, where the picture size is too big.
7444
7445 try {
7446 fd.checkError();
7447 } catch (IOException e) {
7448 loge("Remote end for call composer closed with an error: " + e);
7449 return;
7450 }
7451
Hall Liuaa4211e2021-01-20 15:43:39 -08007452 if (!readUntilEnd) {
7453 loge("Did not finish reading entire image; aborting");
7454 return;
7455 }
Hall Liu82694d52020-12-11 18:22:04 -08007456
Hall Liuaa4211e2021-01-20 15:43:39 -08007457 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7458 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7459 new CallComposerPictureTransfer.Factory() {},
7460 imageData,
7461 (result) -> {
7462 if (result.first != null) {
7463 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7464 Bundle outputResult = new Bundle();
7465 outputResult.putParcelable(
7466 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7467 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7468 outputResult);
7469 } else {
7470 callback.send(result.second, null);
7471 }
7472 }
7473 );
Hall Liu82694d52020-12-11 18:22:04 -08007474 });
7475 }
7476
7477 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007478 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 ImsManager.getInstance(defaultPhone.getContext(),
7485 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007489 }
7490
7491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007493 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7495 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007496 return false;
7497 }
Svet Ganovb320e182015-04-16 12:30:10 -07007498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 // Check the user preference and the system-level IMS setting. Even if the user has
7502 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7503 // In the long run, we may instead need to check if there exists a connection service
7504 // which can support video calling.
7505 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007506 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 return imsManager.isVtEnabledByPlatform()
7508 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7509 && imsManager.isVtEnabledByUser();
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007513 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007514
Andrew Leea1239f22015-03-02 17:44:07 -08007515 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007516 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7517 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 mApp, subId, callingPackage, callingFeatureId,
7520 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 return false;
7522 }
7523
7524 final long identity = Binder.clearCallingIdentity();
7525 try {
7526 CarrierConfigManager configManager =
7527 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007528 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
Andrew Leea1239f22015-03-02 17:44:07 -08007533 }
7534
7535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007536 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 return false;
7540 }
7541
7542 final long identity = Binder.clearCallingIdentity();
7543 try {
7544 CarrierConfigManager configManager =
7545 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007546 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
Andrew Leea1239f22015-03-02 17:44:07 -08007551 }
7552
Andrew Lee9431b832015-03-09 18:46:45 -07007553 @Override
7554 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007555 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007556 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007557 }
7558
7559 @Override
7560 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Andrew Lee9431b832015-03-09 18:46:45 -07007567 }
7568
Hall Liuf6668912018-10-31 17:05:23 -07007569 /**
7570 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7571 * support for the feature and device firmware support.
7572 *
7573 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7574 */
7575 @Override
7576 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 final Phone phone = getPhone(subscriptionId);
7579 if (phone == null) {
7580 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7581 return false;
7582 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007584 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7586 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 return isCarrierSupported && isDeviceSupported;
7589 } finally {
7590 Binder.restoreCallingIdentity(identity);
7591 }
Hall Liu98187582018-01-22 19:15:32 -08007592 }
7593
Hall Liuf6668912018-10-31 17:05:23 -07007594 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007595 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7596 * RTT setting, will return true if the device and carrier both support RTT.
7597 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007598 */
7599 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007602 boolean isRttSupported = isRttSupported(subscriptionId);
7603 boolean isUserRttSettingOn = Settings.Secure.getInt(
7604 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7605 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7606 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7607 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007611 }
7612
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007613 @Deprecated
7614 @Override
7615 public String getDeviceId(String callingPackage) {
7616 return getDeviceIdWithFeature(callingPackage, null);
7617 }
7618
Sanket Padawe7310cc72015-01-14 09:53:20 -08007619 /**
7620 * Returns the unique device ID of phone, for example, the IMEI for
7621 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7622 *
7623 * <p>Requires Permission:
7624 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7625 */
7626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007627 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007628 try {
7629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7630 } catch (SecurityException se) {
7631 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7632 throw new SecurityException("Package " + callingPackage + " does not belong to "
7633 + Binder.getCallingUid());
7634 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007635 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007636 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007637 return null;
7638 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007639 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007640 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007641 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007642 return null;
7643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 return phone.getDeviceId();
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007651 }
7652
Ping Sunc67b7c22016-03-02 19:16:45 +08007653 /**
7654 * {@hide}
7655 * Returns the IMS Registration Status on a particular subid
7656 *
7657 * @param subId
7658 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007660 Phone phone = getPhone(subId);
7661 if (phone != null) {
7662 return phone.isImsRegistered();
7663 } else {
7664 return false;
7665 }
7666 }
7667
Santos Cordon7a1885b2015-02-03 11:15:19 -08007668 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007669 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007670 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007673 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7674 }
7675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7678 } finally {
7679 Binder.restoreCallingIdentity(identity);
7680 }
7681 }
7682
7683 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007684 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007685 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007686 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007687 mApp,
7688 subscriptionId,
7689 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 Phone phone = getPhone(subscriptionId);
7693 if (phone == null) {
7694 return null;
7695 }
7696 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
7701
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007702 /**
7703 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007704 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 Phone phone = getPhone(subId);
7709 if (phone != null) {
7710 return phone.isWifiCallingEnabled();
7711 } else {
7712 return false;
7713 }
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007717 }
7718
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007719 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007720 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007721 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007722 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 Phone phone = getPhone(subId);
7726 if (phone != null) {
7727 return phone.isVideoEnabled();
7728 } else {
7729 return false;
7730 }
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007733 }
7734 }
7735
7736 /**
7737 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7738 * defined in {@link ImsRegistrationImplBase}.
7739 */
7740 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 final long identity = Binder.clearCallingIdentity();
7742 try {
7743 Phone phone = getPhone(subId);
7744 if (phone != null) {
7745 return phone.getImsRegistrationTech();
7746 } else {
7747 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7748 }
7749 } finally {
7750 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007751 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007752 }
7753
Stuart Scott8eef64f2015-04-08 15:13:54 -07007754 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007755 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007756 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007757 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7758 return;
7759 }
Kai Shif70f46f2021-03-03 13:59:46 -08007760 Phone defaultPhone = getDefaultPhone();
7761 if (defaultPhone != null) {
7762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7763 mApp, getDefaultPhone().getSubId(), "factoryReset");
7764 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007765 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007766
Svet Ganovcc087f82015-05-12 20:35:54 -07007767 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007768 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7769 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007770 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007771 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007772 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007773 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007774 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007775 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007776 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007777 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007778 // There has been issues when Sms raw table somehow stores orphan
7779 // fragments. They lead to garbled message when new fragments come
7780 // in and combined with those stale ones. In case this happens again,
7781 // user can reset all network settings which will clean up this table.
7782 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007783 // Clean up IMS settings as well here.
7784 int slotId = getSlotIndex(subId);
7785 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7786 ImsManager.getInstance(mApp, slotId).factoryReset();
7787 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007788
Kai Shif70f46f2021-03-03 13:59:46 -08007789 if (defaultPhone == null) {
7790 return;
7791 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007792 // Erase modem config if erase modem on network setting is enabled.
7793 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7794 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7795 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007796 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007797 }
Kai Shif70f46f2021-03-03 13:59:46 -08007798
7799 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007800 } finally {
7801 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007802 }
7803 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007804
SongFerngWangfd89b102021-05-27 22:44:54 +08007805 @VisibleForTesting
7806 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7807 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7808 return;
7809 }
7810 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7811 RILConstants.PREFERRED_NETWORK_MODE);
7812 SubscriptionManager.setSubscriptionProperty(subId,
7813 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7814 "user=" + defaultNetworkType);
7815 phone.loadAllowedNetworksFromSubscriptionDatabase();
7816 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7817 defaultNetworkType, null);
7818 }
7819
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007820 private void cleanUpSmsRawTable(Context context) {
7821 ContentResolver resolver = context.getContentResolver();
7822 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7823 resolver.delete(uri, null, null);
7824 }
7825
Narayan Kamath1c496c22015-04-16 14:40:19 +01007826 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007827 public String getSimLocaleForSubscriber(int subId) {
7828 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7829 final Phone phone = getPhone(subId);
7830 if (phone == null) {
7831 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007832 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 final long identity = Binder.clearCallingIdentity();
7835 try {
chen xu5d3637b2019-01-21 23:31:38 -08007836 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007837 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007838 if (info == null) {
7839 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7840 return null;
7841 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842 // Try and fetch the locale from the carrier properties or from the SIM language
7843 // preferences (EF-PL and EF-LI)...
7844 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007846 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7847 if (localeFromDefaultSim != null) {
7848 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7849 if (DBG) log("Using locale from subId: " + subId + " locale: "
7850 + localeFromDefaultSim);
tom hsu0b59d292022-09-29 23:49:21 +08007851 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007852 } else {
7853 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 }
7855 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 // The SIM language preferences only store a language (e.g. fr = French), not an
7858 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7859 // the SIM and carrier preferences does not include a country we add the country
7860 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007861 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007863 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu0b59d292022-09-29 23:49:21 +08007864 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 }
7866
7867 if (DBG) log("No locale found - returning null");
7868 return null;
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007872 }
7873
tom hsu0b59d292022-09-29 23:49:21 +08007874 @VisibleForTesting
7875 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
7876 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
7877 getDefaultPhone().getContext());
7878 for (String localeTag : supportedLocale) {
7879 if (LocaleList.matchesLanguageAndScript(
7880 inputLocale, Locale.forLanguageTag(localeTag))
7881 && inputLocale.getCountry().equals(
7882 Locale.forLanguageTag(localeTag).getCountry())) {
7883 return localeTag;
7884 }
7885 }
7886 return inputLocale.toLanguageTag();
7887 }
7888
Narayan Kamath1c496c22015-04-16 14:40:19 +01007889 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007890 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007891 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007892 }
7893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 /**
7895 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7896 */
7897 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007898 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007899 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007900 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007901
Gary Jian3aa9a762022-01-24 16:41:19 +08007902 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7903 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007904
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007905 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007906 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7907 * representing the state of the modem.
7908 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007909 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7910 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007911 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007912 */
7913 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007914 public void requestModemActivityInfo(ResultReceiver result) {
7915 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
7918 final long identity = Binder.clearCallingIdentity();
7919 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007920 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 } finally {
7922 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007923 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007924 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007925
Siddharth Rayb8114062018-06-17 15:02:38 -07007926 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7927 // less than total activity duration.
7928 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7929 if (info == null) {
7930 return false;
7931 }
7932 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007933 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7934 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7935
Siddharth Rayb8114062018-06-17 15:02:38 -07007936 return (info.isValid()
7937 && (info.getSleepTimeMillis() <= activityDurationMs)
7938 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007939 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007940 && (totalTxTimeMs <= activityDurationMs));
7941 }
7942
Gary Jian3aa9a762022-01-24 16:41:19 +08007943 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7944 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7945 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7946 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7947
7948 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7949 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7950 }
7951
7952 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7953 mLastModemActivityInfo.setReceiveTimeMillis(
7954 rat,
7955 freq,
7956 info.getReceiveTimeMillis(rat, freq)
7957 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7958 }
7959
7960 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7961 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7962 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7963 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7964
7965 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7966 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7967 }
7968 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7969 mLastModemActivityInfo.setReceiveTimeMillis(
7970 rat,
7971 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7972 }
7973
7974 /**
7975 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7976 * @param info recent ModemActivityInfo
7977 */
7978 private void mergeModemActivityInfo(ModemActivityInfo info) {
7979 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7980 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7981 boolean matched;
7982 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7983 matched = false;
7984 int rat = info.getSpecificInfoRat(i);
7985 int freq = info.getSpecificInfoFrequencyRange(i);
7986 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7987 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7988 //if it already exists
7989 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7990 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7991 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7992 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7993 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7994 updateLastModemActivityInfo(info, rat, freq);
7995 matched = true;
7996 }
7997 } else {
7998 updateLastModemActivityInfo(info, rat);
7999 matched = true;
8000 }
8001 }
8002 }
8003
8004 if (!matched) {
8005 mDeltaSpecificInfo =
8006 new ActivityStatsTechSpecificInfo(
8007 rat,
8008 freq,
8009 info.getTransmitTimeMillis(rat, freq),
8010 (int) info.getReceiveTimeMillis(rat, freq));
8011 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8012 }
8013 }
8014 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8015 mLastModemActivitySpecificInfo =
8016 new ActivityStatsTechSpecificInfo[merged.size()];
8017 merged.toArray(mLastModemActivitySpecificInfo);
8018
8019 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8020 mLastModemActivityInfo.setSleepTimeMillis(
8021 info.getSleepTimeMillis()
8022 + mLastModemActivityInfo.getSleepTimeMillis());
8023 mLastModemActivityInfo.setIdleTimeMillis(
8024 info.getIdleTimeMillis()
8025 + mLastModemActivityInfo.getIdleTimeMillis());
8026 }
8027
Jack Yu85bd38a2015-11-09 11:34:32 -08008028 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008029 * Returns the service state information on specified subscription.
8030 */
8031 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008032 public ServiceState getServiceStateForSubscriber(int subId,
8033 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8034 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008036 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008037 return null;
8038 }
8039
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008040 boolean hasFinePermission = false;
8041 boolean hasCoarsePermission = false;
8042 if (!renounceFineLocationAccess) {
8043 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8044 LocationAccessPolicy.checkLocationPermission(mApp,
8045 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8046 .setCallingPackage(callingPackage)
8047 .setCallingFeatureId(callingFeatureId)
8048 .setCallingPid(Binder.getCallingPid())
8049 .setCallingUid(Binder.getCallingUid())
8050 .setMethod("getServiceStateForSubscriber")
8051 .setLogAsInfo(true)
8052 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8053 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8054 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8055 .build());
8056 hasFinePermission =
8057 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8058 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008059
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008060 if (!renounceCoarseLocationAccess) {
8061 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8062 LocationAccessPolicy.checkLocationPermission(mApp,
8063 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8064 .setCallingPackage(callingPackage)
8065 .setCallingFeatureId(callingFeatureId)
8066 .setCallingPid(Binder.getCallingPid())
8067 .setCallingUid(Binder.getCallingUid())
8068 .setMethod("getServiceStateForSubscriber")
8069 .setLogAsInfo(true)
8070 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8071 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8072 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8073 .build());
8074 hasCoarsePermission =
8075 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8076 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008077
Jack Yu479f40e2020-10-27 21:29:25 -07008078 final Phone phone = getPhone(subId);
8079 if (phone == null) {
8080 return null;
8081 }
8082
Jordan Liu0f2bc442020-11-18 16:47:37 -08008083 final long identity = Binder.clearCallingIdentity();
8084
Jack Yu479f40e2020-10-27 21:29:25 -07008085 boolean isCallingPackageDataService = phone.getDataServicePackages()
8086 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008088 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8089 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8090 Rlog.d(LOG_TAG,
8091 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8092 return null;
8093 }
8094
Hall Liuf19c44f2018-11-27 14:38:17 -08008095 ServiceState ss = phone.getServiceState();
8096
8097 // Scrub out the location info in ServiceState depending on what level of access
8098 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008099 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008100 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8101 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008105 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008106
8107 /**
8108 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8109 *
8110 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8111 * voicemail ringtone.
8112 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8113 * PhoneAccount.
8114 */
8115 @Override
8116 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8120 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008121 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
8127 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008128 }
8129
8130 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008131 * Sets the per-account voicemail ringtone.
8132 *
8133 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8134 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8135 *
8136 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8137 * voicemail ringtone.
8138 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8139 * PhoneAccount.
8140 */
8141 @Override
8142 public void setVoicemailRingtoneUri(String callingPackage,
8143 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008144 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008146 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8147 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8149 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8150 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8156 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008157 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 }
8159 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008162 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008163 }
8164
8165 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008166 * Returns whether vibration is set for voicemail notification in Phone settings.
8167 *
8168 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8169 * voicemail vibration setting.
8170 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8171 */
8172 @Override
8173 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008174 final long identity = Binder.clearCallingIdentity();
8175 try {
8176 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8177 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008178 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008181 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008185 }
8186
Youhan Wange64578a2016-05-02 15:32:42 -07008187 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008188 * Sets the per-account voicemail vibration.
8189 *
8190 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8191 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8192 *
8193 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8194 * voicemail vibration setting.
8195 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8196 * specific PhoneAccount.
8197 */
8198 @Override
8199 public void setVoicemailVibrationEnabled(String callingPackage,
8200 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008201 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008202 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008203 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8204 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8206 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8207 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008208 }
8209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8213 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008214 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 }
8216 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008219 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008220 }
8221
8222 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008223 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8224 *
8225 * @throws SecurityException if the caller does not have the required permission
8226 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008227 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008228 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008229 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008230 }
8231
8232 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008233 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8234 * permission.
8235 *
8236 * @throws SecurityException if the caller does not have the required permission
8237 */
8238 private void enforceSendSmsPermission() {
8239 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8240 }
8241
8242 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008243 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008244 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008245 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008246 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008247 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 final long identity = Binder.clearCallingIdentity();
8249 try {
8250 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008251 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 if (componentName == null) {
8253 throw new SecurityException(
8254 "Caller not current active visual voicemail package[null]");
8255 }
8256 String vvmPackage = componentName.getPackageName();
8257 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008258 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008259 }
8260 } finally {
8261 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008262 }
8263 }
8264
8265 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008266 * Return the application ID for the app type.
8267 *
8268 * @param subId the subscription ID that this request applies to.
8269 * @param appType the uicc app type.
8270 * @return Application ID for specificied app type, or null if no uicc.
8271 */
8272 @Override
8273 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008274 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008275 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008278 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 if (phone == null) {
8280 return null;
8281 }
8282 String aid = null;
8283 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008284 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008285 .getApplicationByType(appType).getAid();
8286 } catch (Exception e) {
8287 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8288 }
8289 return aid;
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008292 }
Youhan Wange64578a2016-05-02 15:32:42 -07008293 }
8294
Youhan Wang4001d252016-05-11 10:29:41 -07008295 /**
8296 * Return the Electronic Serial Number.
8297 *
8298 * @param subId the subscription ID that this request applies to.
8299 * @return ESN or null if error.
8300 */
8301 @Override
8302 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008303 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008304 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305
8306 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008307 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 if (phone == null) {
8309 return null;
8310 }
8311 String esn = null;
8312 try {
8313 esn = phone.getEsn();
8314 } catch (Exception e) {
8315 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8316 }
8317 return esn;
8318 } finally {
8319 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008320 }
Youhan Wang4001d252016-05-11 10:29:41 -07008321 }
8322
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008323 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008324 * Return the Preferred Roaming List Version.
8325 *
8326 * @param subId the subscription ID that this request applies to.
8327 * @return PRLVersion or null if error.
8328 */
8329 @Override
8330 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008331 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008332 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008333
8334 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008335 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336 if (phone == null) {
8337 return null;
8338 }
8339 String cdmaPrlVersion = null;
8340 try {
8341 cdmaPrlVersion = phone.getCdmaPrlVersion();
8342 } catch (Exception e) {
8343 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8344 }
8345 return cdmaPrlVersion;
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008348 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008349 }
8350
8351 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008352 * Get snapshot of Telephony histograms
8353 * @return List of Telephony histograms
8354 * @hide
8355 */
8356 @Override
8357 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8359 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008360
8361 final long identity = Binder.clearCallingIdentity();
8362 try {
8363 return RIL.getTelephonyRILTimingHistograms();
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008367 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008368
8369 /**
8370 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008371 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8372 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008373 * Require system privileges. In the future we may add this to carrier APIs.
8374 *
Michele Berionne482f8202018-11-27 18:57:59 -08008375 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008376 */
8377 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008378 @TelephonyManager.SetCarrierRestrictionResult
8379 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008380 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008382
Michele Berionne482f8202018-11-27 18:57:59 -08008383 if (carrierRestrictionRules == null) {
8384 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008385 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 final long identity = Binder.clearCallingIdentity();
8388 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008389 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008390 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 } finally {
8392 Binder.restoreCallingIdentity(identity);
8393 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008394 }
8395
8396 /**
8397 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008398 * Get the allowed carrier list and the excluded carrier list, including the priority between
8399 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008400 * Require system privileges. In the future we may add this to carrier APIs.
8401 *
Michele Berionne482f8202018-11-27 18:57:59 -08008402 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008403 */
8404 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008405 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008406 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008407 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008411 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8412 if (response instanceof CarrierRestrictionRules) {
8413 return (CarrierRestrictionRules) response;
8414 }
8415 // Response is an Exception of some kind,
8416 // which is signalled to the user as a NULL retval
8417 return null;
8418 } catch (Exception e) {
8419 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8420 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008424 }
8425
fionaxu59545b42016-05-25 15:53:37 -07008426 /**
fionaxu59545b42016-05-25 15:53:37 -07008427 * Action set from carrier signalling broadcast receivers to enable/disable radio
8428 * @param subId the subscription ID that this action applies to.
8429 * @param enabled control enable or disable radio.
8430 * {@hide}
8431 */
8432 @Override
8433 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8434 enforceModifyPermission();
8435 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436
8437 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008438 if (phone == null) {
8439 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8440 return;
8441 }
8442 try {
8443 phone.carrierActionSetRadioEnabled(enabled);
8444 } catch (Exception e) {
8445 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 } finally {
8447 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008448 }
8449 }
8450
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008451 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008452 * Enable or disable Voice over NR (VoNR)
8453 * @param subId the subscription ID that this action applies to.
8454 * @param enabled enable or disable VoNR.
8455 * @return operation result.
8456 */
8457 @Override
8458 public int setVoNrEnabled(int subId, boolean enabled) {
8459 enforceModifyPermission();
8460 final Phone phone = getPhone(subId);
8461
8462 final long identity = Binder.clearCallingIdentity();
8463 if (phone == null) {
8464 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8465 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8466 }
8467
8468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8469 try {
8470 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8471 workSource);
8472 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008473
8474 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8475 if (DBG) {
8476 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8477 }
8478 SubscriptionManager.setSubscriptionProperty(
8479 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8480 (enabled ? "1" : "0"));
8481 }
8482
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008483 return result;
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
8487 }
8488
8489 /**
8490 * Is voice over NR enabled
8491 * @return true if VoNR is enabled else false
8492 */
8493 @Override
8494 public boolean isVoNrEnabled(int subId) {
8495 enforceReadPrivilegedPermission("isVoNrEnabled");
8496 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
8499 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8500 null, subId, workSource);
8501 if (DBG) log("isVoNrEnabled: " + isEnabled);
8502 return isEnabled;
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
8507
8508 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008509 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8510 * network status based on which carrier apps could apply actions accordingly,
8511 * enable/disable default url handler for example.
8512 *
8513 * @param subId the subscription ID that this action applies to.
8514 * @param report control start/stop reporting the default network status.
8515 * {@hide}
8516 */
8517 @Override
8518 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8519 enforceModifyPermission();
8520 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521
8522 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008523 if (phone == null) {
8524 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8525 return;
8526 }
8527 try {
8528 phone.carrierActionReportDefaultNetworkStatus(report);
8529 } catch (Exception e) {
8530 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531 } finally {
8532 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008533 }
8534 }
8535
8536 /**
fionaxud9622282017-07-17 17:51:30 -07008537 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8538 * @param subId the subscription ID that this action applies to.
8539 * {@hide}
8540 */
8541 @Override
8542 public void carrierActionResetAll(int subId) {
8543 enforceModifyPermission();
8544 final Phone phone = getPhone(subId);
8545 if (phone == null) {
8546 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8547 return;
8548 }
8549 try {
8550 phone.carrierActionResetAll();
8551 } catch (Exception e) {
8552 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8553 }
8554 }
8555
8556 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008557 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8558 * bug report is being generated.
8559 */
8560 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008561 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008562 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8563 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008564 writer.println("Permission Denial: can't dump Phone from pid="
8565 + Binder.getCallingPid()
8566 + ", uid=" + Binder.getCallingUid()
8567 + "without permission "
8568 + android.Manifest.permission.DUMP);
8569 return;
8570 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008571 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008572 }
Jack Yueb89b242016-06-22 13:27:47 -07008573
Brad Ebingerdac2f002018-04-03 15:17:52 -07008574 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008575 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8576 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8577 @NonNull String[] args) {
8578 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8579 this, in.getFileDescriptor(), out.getFileDescriptor(),
8580 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008581 }
8582
Jack Yueb89b242016-06-22 13:27:47 -07008583 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008584 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008585 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008586 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008587 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008588 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008589 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008590 */
8591 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008592 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008593 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008594 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8595 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8596 try {
8597 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008598 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008599 } catch (SecurityException se) {
8600 enforceModifyPermission();
8601 }
8602 } else {
8603 enforceModifyPermission();
8604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605
8606 final long identity = Binder.clearCallingIdentity();
8607 try {
8608 Phone phone = getPhone(subId);
8609 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008610 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8611 phone.carrierActionSetMeteredApnsEnabled(enabled);
8612 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008613 phone.getDataSettingsManager().setDataEnabled(
8614 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008616 }
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008619 }
8620 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008621
8622 /**
8623 * Get Client request stats
8624 * @return List of Client Request Stats
8625 * @hide
8626 */
8627 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008628 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8629 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008632 return null;
8633 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008634 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008636 final long identity = Binder.clearCallingIdentity();
8637 try {
8638 if (phone != null) {
8639 return phone.getClientRequestStats();
8640 }
8641
8642 return null;
8643 } finally {
8644 Binder.restoreCallingIdentity(identity);
8645 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008646 }
8647
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008648 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008649 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008650 if (uid == Process.ROOT_UID && packageName == null) {
8651 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8652 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8653 // exception. ROOT_UID seems not to have a valid package name returned by
8654 // PackageManager, so just fake it here to avoid issues when running telephony shell
8655 // commands that plumb through the RIL as root, like so:
8656 // $ adb root
8657 // $ adb shell cmd phone ...
8658 packageName = "root";
8659 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008660 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008661 }
Jack Yueb4124c2017-02-16 15:32:43 -08008662
8663 /**
Grace Chen70990072017-03-24 17:21:30 -07008664 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008665 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008666 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008667 * @param state State of SIM (power down, power up, pass through)
8668 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8669 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8670 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008671 *
8672 **/
8673 @Override
Grace Chen70990072017-03-24 17:21:30 -07008674 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008675 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008676 Phone phone = PhoneFactory.getPhone(slotIndex);
8677
vagdeviaf9a5b92018-08-15 16:01:53 -07008678 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008680 final long identity = Binder.clearCallingIdentity();
8681 try {
8682 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008683 phone.setSimPowerState(state, null, workSource);
8684 }
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
8688 }
8689
8690 /**
8691 * Set SIM card power state.
8692 *
8693 * @param slotIndex SIM slot id.
8694 * @param state State of SIM (power down, power up, pass through)
8695 * @param callback callback to trigger after success or failure
8696 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8697 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8698 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8699 *
8700 **/
8701 @Override
8702 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8703 IIntegerConsumer callback) {
8704 enforceModifyPermission();
8705 Phone phone = PhoneFactory.getPhone(slotIndex);
8706
8707 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8708
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
8711 if (phone != null) {
8712 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8713 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008714 }
8715 } finally {
8716 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008717 }
8718 }
Shuo Qiandd210312017-04-12 22:11:33 +00008719
Tyler Gunn65d45c22017-06-05 11:22:26 -07008720 private boolean isUssdApiAllowed(int subId) {
8721 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008722 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008723 if (configManager == null) {
8724 return false;
8725 }
8726 PersistableBundle pb = configManager.getConfigForSubId(subId);
8727 if (pb == null) {
8728 return false;
8729 }
8730 return pb.getBoolean(
8731 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8732 }
8733
Shuo Qiandd210312017-04-12 22:11:33 +00008734 /**
8735 * Check if phone is in emergency callback mode
8736 * @return true if phone is in emergency callback mode
8737 * @param subId sub id
8738 */
goneil9c5f4872017-12-05 14:07:56 -08008739 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008740 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008741 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008742 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 if (phone != null) {
8747 return phone.isInEcm();
8748 } else {
8749 return false;
8750 }
8751 } finally {
8752 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008753 }
8754 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008755
8756 /**
8757 * Get the current signal strength information for the given subscription.
8758 * Because this information is not updated when the device is in a low power state
8759 * it should not be relied-upon to be current.
8760 * @param subId Subscription index
8761 * @return the most recent cached signal strength info from the modem
8762 */
8763 @Override
8764 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008765 final long identity = Binder.clearCallingIdentity();
8766 try {
8767 Phone p = getPhone(subId);
8768 if (p == null) {
8769 return null;
8770 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008772 return p.getSignalStrength();
8773 } finally {
8774 Binder.restoreCallingIdentity(identity);
8775 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008776 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008777
Pengquan Meng77b7f132018-08-22 14:49:57 -07008778 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008779 * Get the current modem radio state for the given slot.
8780 * @param slotIndex slot index.
8781 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008782 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008783 * @return the current radio power state from the modem
8784 */
8785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008786 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008787 Phone phone = PhoneFactory.getPhone(slotIndex);
8788 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8790 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008791 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8792 }
8793
8794 final long identity = Binder.clearCallingIdentity();
8795 try {
8796 return phone.getRadioPowerState();
8797 } finally {
8798 Binder.restoreCallingIdentity(identity);
8799 }
8800 }
8801 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8802 }
8803
8804 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008805 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8806 *
8807 * <p>Requires one of the following permissions:
8808 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008809 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008810 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8811 * privileges.
8812 *
8813 * @param subId subscription id
8814 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8815 * {@code false}.
8816 */
8817 @Override
8818 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008819 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008820 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008821 try {
8822 mApp.enforceCallingOrSelfPermission(
8823 android.Manifest.permission.ACCESS_NETWORK_STATE,
8824 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008825 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008826 mApp.enforceCallingOrSelfPermission(
8827 permission.READ_BASIC_PHONE_STATE, functionName);
8828 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008829 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008830 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008831 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008832 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008833
Pengquan Menga1bb6272018-09-06 09:59:22 -07008834 boolean isEnabled = false;
8835 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008836 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008837 Phone phone = getPhone(subId);
8838 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008839 } finally {
8840 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008841 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008842 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008843 }
8844
8845
8846 /**
8847 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8848 *
8849 * <p> Requires permission:
8850 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8851 * privileges.
8852 *
8853 * @param subId subscription id
8854 * @param isEnabled {@code true} means enable, {@code false} means disable.
8855 */
8856 @Override
8857 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8859 mApp, subId, "setDataRoamingEnabled");
8860
Pengquan Menga1bb6272018-09-06 09:59:22 -07008861 final long identity = Binder.clearCallingIdentity();
8862 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008863 Phone phone = getPhone(subId);
8864 if (phone != null) {
8865 phone.setDataRoamingEnabled(isEnabled);
8866 }
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008869 }
8870 }
8871
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008872 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008873 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008874 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008875 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008876 mApp, subId, "isManualNetworkSelectionAllowed");
8877
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008878 boolean isAllowed = true;
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008881 Phone phone = getPhone(subId);
8882 if (phone != null) {
8883 isAllowed = phone.isCspPlmnEnabled();
8884 }
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 return isAllowed;
8889 }
8890
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008891 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8892 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008893 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008894 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008895 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008896 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8897 if (phone == null) {
8898 return false;
8899 }
8900 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8901 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8902 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008903 }
8904
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008905 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008906 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008907 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008908 mApp.getSystemService(AppOpsManager.class)
8909 .checkPackage(Binder.getCallingUid(), callingPackage);
8910
Jordan Liu1e142fc2019-04-22 15:10:43 -07008911 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008912 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008913 try {
8914 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008915 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008916 } catch (SecurityException e) {
8917 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8918 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008919 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008920 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008921 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008922 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008923 }
sandeepjsb6c87872021-09-27 15:34:44 +00008924 // checking compatibility, if calling app's target SDK is T and beyond.
8925 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8926 Binder.getCallingUid())) {
8927 isIccIdAccessRestricted = true;
8928 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008929 final long identity = Binder.clearCallingIdentity();
8930 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008931 UiccController uiccController = UiccController.getInstance();
8932 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008933 if (hasReadPermission) {
8934 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008935 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008936
8937 // Remove private info if the caller doesn't have access
8938 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8939 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008940 //setting the value after compatibility check
8941 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008942 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8943 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008944 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008945 if (card == null) {
8946 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008947 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008948 continue;
8949 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008950 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8951 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008952 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008953 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008954 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008955 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8956 for (UiccPortInfo portInfo : portInfos) {
8957 UiccPort port = uiccController.getUiccPortForSlot(
8958 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8959 if (port == null) {
8960 // assume no access if port is null
8961 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8962 continue;
8963 }
8964 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8965 uiccPortInfos.add(portInfo);
8966 } else {
8967 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8968 }
8969 }
8970 filteredInfos.add(new UiccCardInfo(
8971 cardInfo.isEuicc(),
8972 cardInfo.getCardId(),
8973 null,
8974 cardInfo.getPhysicalSlotIndex(),
8975 cardInfo.isRemovable(),
8976 cardInfo.isMultipleEnabledProfilesSupported(),
8977 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008978 }
8979 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
sandeepjsb6c87872021-09-27 15:34:44 +00008985 /**
8986 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8987 * generally private and require carrier privileges to view.
8988 *
8989 * @hide
8990 */
8991 @NonNull
8992 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8993 List<UiccPortInfo> portinfo = new ArrayList<>();
8994 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8995 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8996 }
8997 return new UiccCardInfo(
8998 cardInfo.isEuicc(),
8999 cardInfo.getCardId(),
9000 null,
9001 cardInfo.getPhysicalSlotIndex(),
9002 cardInfo.isRemovable(),
9003 cardInfo.isMultipleEnabledProfilesSupported(),
9004 portinfo
9005 );
9006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009007
sandeepjsb6c87872021-09-27 15:34:44 +00009008 /**
9009 * @hide
9010 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9011 * These values are generally private and require carrier privileges to view.
9012 */
9013 @NonNull
9014 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9015 return new UiccPortInfo(
9016 UiccPortInfo.ICCID_REDACTED,
9017 portInfo.getPortIndex(),
9018 portInfo.getLogicalSlotIndex(),
9019 portInfo.isActive()
9020 );
9021 }
9022 @Override
9023 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009024 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009025 mApp.getSystemService(AppOpsManager.class)
9026 .checkPackage(Binder.getCallingUid(), callingPackage);
9027
sandeepjsb6c87872021-09-27 15:34:44 +00009028 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009029
Aman Guptaf3c90b32022-03-17 04:54:16 +00009030 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9031 // we are reading iccId which is PII data.
9032 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009033
9034 // checking compatibility, if calling app's target SDK is T and beyond.
9035 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9036 Binder.getCallingUid())) {
9037 isLogicalSlotAccessRestricted = true;
9038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009042 if (slots == null || slots.length == 0) {
9043 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009044 return null;
9045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009046 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9047 for (int i = 0; i < slots.length; i++) {
9048 UiccSlot slot = slots[i];
9049 if (slot == null) {
9050 continue;
9051 }
9052
Jordan Liu7be7e652019-05-06 18:55:02 +00009053 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009054 UiccCard card = slot.getUiccCard();
9055 if (card != null) {
9056 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009057 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009058 cardId = slot.getEid();
9059 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009060 // If cardId is null, use iccId of default port as cardId.
9061 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009063 }
9064
Jordan Liu857451f2019-05-09 16:35:35 -07009065 if (cardId != null) {
9066 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9067 // if cardId is an EID, it's all digits so this is fine
9068 cardId = IccUtils.stripTrailingFs(cardId);
9069 }
9070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009071 int cardState = 0;
9072 switch (slot.getCardState()) {
9073 case CARDSTATE_ABSENT:
9074 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9075 break;
9076 case CARDSTATE_PRESENT:
9077 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9078 break;
9079 case CARDSTATE_ERROR:
9080 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9081 break;
9082 case CARDSTATE_RESTRICTED:
9083 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9084 break;
9085 default:
9086 break;
9087
9088 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009089 List<UiccPortInfo> portInfos = new ArrayList<>();
9090 int[] portIndexes = slot.getPortList();
9091 for (int portIdx : portIndexes) {
9092 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009093 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009094 portInfos.add(new UiccPortInfo(iccId, portIdx,
9095 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009097 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009098 slot.isEuicc(),
9099 cardId,
9100 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009101 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009102 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009103 //setting the value after compatibility check
9104 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009105 }
9106 return infos;
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009109 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009110 }
9111
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009112 /* Returns null if doesn't have read permission or carrier privilege access. */
9113 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9114 boolean hasReadPermission) {
9115 String iccId = slot.getIccId(portIndex);
9116 if (hasReadPermission) { // if has read permission
9117 return iccId;
9118 } else {
9119 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9120 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9121 // if no read permission, checking carrier privilege access
9122 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9123 return iccId;
9124 }
9125 }
9126 }
9127 // No read permission or carrier privilege access.
9128 return UiccPortInfo.ICCID_REDACTED;
9129 }
9130
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009131 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009132 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009133 public boolean switchSlots(int[] physicalSlots) {
9134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009135
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009138 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9139 for (int i = 0; i < physicalSlots.length; i++) {
9140 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9141 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9142 physicalSlots[i], i));
9143 }
9144 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009148 }
Jack Yu4c988042018-02-27 15:30:01 -08009149
9150 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009151 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9152 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9153 enforceModifyPermission();
9154
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009157 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009158 } finally {
9159 Binder.restoreCallingIdentity(identity);
9160 }
9161 }
9162
9163 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009164 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009165 final long identity = Binder.clearCallingIdentity();
9166 try {
9167 return UiccController.getInstance().getCardIdForDefaultEuicc();
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
9172
Pengquan Meng85728fb2018-03-12 16:31:21 -07009173 /**
goneil47ffb6e2018-04-06 15:40:58 -07009174 * A test API to reload the UICC profile.
9175 *
9176 * <p>Requires that the calling app has permission
9177 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9178 * @hide
9179 */
9180 @Override
9181 public void refreshUiccProfile(int subId) {
9182 enforceModifyPermission();
9183
9184 final long identity = Binder.clearCallingIdentity();
9185 try {
9186 Phone phone = getPhone(subId);
9187 if (phone == null) {
9188 return;
9189 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009190 UiccPort uiccPort = phone.getUiccPort();
9191 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009192 return;
9193 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009194 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009195 if (uiccProfile == null) {
9196 return;
9197 }
9198 uiccProfile.refresh();
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
9204 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009205 * Returns false if the mobile data is disabled by default, otherwise return true.
9206 */
9207 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009208 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009209 }
9210
9211 /**
9212 * Returns true if the data roaming is enabled by default, i.e the system property
9213 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9214 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9215 */
9216 private boolean getDefaultDataRoamingEnabled(int subId) {
9217 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009218 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009219 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009220 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9221 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9222 return isDataRoamingEnabled;
9223 }
9224
9225 /**
9226 * Returns the default network type for the given {@code subId}, if the default network type is
9227 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9228 */
9229 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009230 List<Integer> list = TelephonyProperties.default_network();
9231 int phoneId = mSubscriptionController.getPhoneId(subId);
9232 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9233 return list.get(phoneId);
9234 }
9235 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009236 }
fionaxua13278b2018-03-21 00:08:13 -07009237
9238 @Override
9239 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009240 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009242
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
9245 final Phone phone = getPhone(subId);
9246 if (phone == null) {
9247 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9248 return;
9249 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009250 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9251 if (cpt != null) {
9252 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9253 }
9254 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009255 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9256 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009257 if (carrierPrivilegeRules == null) {
9258 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9259 } else {
9260 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009262 } finally {
9263 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009264 }
fionaxua13278b2018-03-21 00:08:13 -07009265 }
9266
9267 @Override
9268 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009269 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009270
9271 final long identity = Binder.clearCallingIdentity();
9272 try {
9273 final Phone phone = getPhone(subId);
9274 if (phone == null) {
9275 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9276 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9277 }
9278 return phone.getCarrierIdListVersion();
9279 } finally {
9280 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009281 }
fionaxua13278b2018-03-21 00:08:13 -07009282 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009283
9284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009285 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9286 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 mApp, subId, callingPackage, callingFeatureId,
9289 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009290 return -1;
9291 }
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009300
9301 @Override
9302 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009303 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009304 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009305 mApp, subId, "getCdmaRoamingMode");
9306
9307 final long identity = Binder.clearCallingIdentity();
9308 try {
9309 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
9314
9315 @Override
9316 public boolean setCdmaRoamingMode(int subId, int mode) {
9317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9318 mApp, subId, "setCdmaRoamingMode");
9319
9320 final long identity = Binder.clearCallingIdentity();
9321 try {
9322 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
9327
9328 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009329 public int getCdmaSubscriptionMode(int subId) {
9330 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009331 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009332 mApp, subId, "getCdmaSubscriptionMode");
9333
9334 final long identity = Binder.clearCallingIdentity();
9335 try {
9336 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9337 } finally {
9338 Binder.restoreCallingIdentity(identity);
9339 }
9340 }
9341
9342 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009343 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9345 mApp, subId, "setCdmaSubscriptionMode");
9346
9347 final long identity = Binder.clearCallingIdentity();
9348 try {
9349 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009354
sqianc5eccab2018-10-19 18:46:41 -07009355 @Override
sqian8c685422019-02-22 15:55:18 -08009356 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009357 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009359 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9360 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009361 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9362 }
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
sqian854d44b2018-12-12 16:48:18 -08009365 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9366 for (Phone phone: PhoneFactory.getPhones()) {
9367 if (phone.getEmergencyNumberTracker() != null
9368 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9369 emergencyNumberListInternal.put(
9370 phone.getSubId(),
9371 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9372 }
sqian11b7a0e2018-12-05 18:48:28 -08009373 }
sqian854d44b2018-12-12 16:48:18 -08009374 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009375 } finally {
9376 Binder.restoreCallingIdentity(identity);
9377 }
sqianc5eccab2018-10-19 18:46:41 -07009378 }
9379
9380 @Override
sqian8c685422019-02-22 15:55:18 -08009381 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009382 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009383 if (!exactMatch) {
9384 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009385 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009386 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009387 }
9388 final long identity = Binder.clearCallingIdentity();
9389 try {
sqian854d44b2018-12-12 16:48:18 -08009390 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009391 //Note: we ignore passed in param exactMatch. We can remove it once
9392 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009393 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009394 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009395 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009396 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009397 }
sqian11b7a0e2018-12-05 18:48:28 -08009398 }
9399 return false;
9400 } finally {
9401 Binder.restoreCallingIdentity(identity);
9402 }
9403 }
9404
sqianf4ca7ed2019-01-15 18:32:07 -08009405 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009406 * Start emergency callback mode for GsmCdmaPhone for testing.
9407 */
9408 @Override
9409 public void startEmergencyCallbackMode() {
9410 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9411 "startEmergencyCallbackMode");
9412 enforceModifyPermission();
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 for (Phone phone : PhoneFactory.getPhones()) {
9416 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9417 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9418 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9419 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9420 gsmCdmaPhone.obtainMessage(
9421 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9422 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9423 }
9424 }
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
9429
9430 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009431 * Update emergency number list for test mode.
9432 */
9433 @Override
9434 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9435 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9436 "updateEmergencyNumberListTestMode");
9437
9438 final long identity = Binder.clearCallingIdentity();
9439 try {
9440 for (Phone phone: PhoneFactory.getPhones()) {
9441 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9442 if (tracker != null) {
9443 tracker.executeEmergencyNumberTestModeCommand(action, num);
9444 }
9445 }
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 /**
9452 * Get the full emergency number list for test mode.
9453 */
9454 @Override
9455 public List<String> getEmergencyNumberListTestMode() {
9456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9457 "getEmergencyNumberListTestMode");
9458
9459 final long identity = Binder.clearCallingIdentity();
9460 try {
9461 Set<String> emergencyNumbers = new HashSet<>();
9462 for (Phone phone: PhoneFactory.getPhones()) {
9463 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9464 if (tracker != null) {
9465 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9466 emergencyNumbers.add(num.getNumber());
9467 }
9468 }
9469 }
9470 return new ArrayList<>(emergencyNumbers);
9471 } finally {
9472 Binder.restoreCallingIdentity(identity);
9473 }
9474 }
9475
chen xud6b45bd2018-10-30 22:27:10 -07009476 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009477 public int getEmergencyNumberDbVersion(int subId) {
9478 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9479
9480 final long identity = Binder.clearCallingIdentity();
9481 try {
9482 final Phone phone = getPhone(subId);
9483 if (phone == null) {
9484 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9485 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9486 }
9487 return phone.getEmergencyNumberDbVersion();
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
9493 @Override
9494 public void notifyOtaEmergencyNumberDbInstalled() {
9495 enforceModifyPermission();
9496
9497 final long identity = Binder.clearCallingIdentity();
9498 try {
9499 for (Phone phone: PhoneFactory.getPhones()) {
9500 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9501 if (tracker != null) {
9502 tracker.updateOtaEmergencyNumberDatabase();
9503 }
9504 }
9505 } finally {
9506 Binder.restoreCallingIdentity(identity);
9507 }
9508 }
9509
9510 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009511 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009512 enforceActiveEmergencySessionPermission();
9513
9514 final long identity = Binder.clearCallingIdentity();
9515 try {
9516 for (Phone phone: PhoneFactory.getPhones()) {
9517 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9518 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009519 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9520 }
9521 }
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
9527 @Override
9528 public void resetOtaEmergencyNumberDbFilePath() {
9529 enforceActiveEmergencySessionPermission();
9530
9531 final long identity = Binder.clearCallingIdentity();
9532 try {
9533 for (Phone phone: PhoneFactory.getPhones()) {
9534 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9535 if (tracker != null) {
9536 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009537 }
9538 }
9539 } finally {
9540 Binder.restoreCallingIdentity(identity);
9541 }
9542 }
9543
9544 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009545 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9546 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9547 Phone phone = getPhone(subId);
9548 if (phone == null) {
9549 return null;
9550 }
9551 final long identity = Binder.clearCallingIdentity();
9552 try {
9553 UiccProfile profile = UiccController.getInstance()
9554 .getUiccProfileForPhone(phone.getPhoneId());
9555 if (profile != null) {
9556 return profile.getCertsFromCarrierPrivilegeAccessRules();
9557 }
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 return null;
9562 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009563
9564 /**
9565 * Enable or disable a modem stack.
9566 */
9567 @Override
9568 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9569 enforceModifyPermission();
9570
9571 final long identity = Binder.clearCallingIdentity();
9572 try {
9573 Phone phone = PhoneFactory.getPhone(slotIndex);
9574 if (phone == null) {
9575 return false;
9576 } else {
9577 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9578 }
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
Michelecea4cf22018-12-21 15:00:11 -08009583
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009584 /**
9585 * Whether a modem stack is enabled or not.
9586 */
9587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009588 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9589 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009590 Phone phone = PhoneFactory.getPhone(slotIndex);
9591 if (phone == null) return false;
9592
9593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009594 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9595 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009596 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9597 }
9598
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009601 try {
9602 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9603 } catch (NoSuchElementException ex) {
9604 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9605 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009606 } finally {
9607 Binder.restoreCallingIdentity(identity);
9608 }
9609 }
9610
Michelecea4cf22018-12-21 15:00:11 -08009611 @Override
Michele0ea7d782019-03-19 14:58:42 -07009612 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009613 enforceModifyPermission();
9614
9615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009618 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009619 .commit();
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
9625 @Override
Michele0ea7d782019-03-19 14:58:42 -07009626 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009627 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009629 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9630 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009631 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009632 }
Michelecea4cf22018-12-21 15:00:11 -08009633
9634 final long identity = Binder.clearCallingIdentity();
9635 try {
Michele0ea7d782019-03-19 14:58:42 -07009636 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009637 } finally {
9638 Binder.restoreCallingIdentity(identity);
9639 }
9640 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009641
Michele0ea7d782019-03-19 14:58:42 -07009642 @TelephonyManager.IsMultiSimSupportedResult
9643 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009644 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9645 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9646 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009647 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9648 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009649 }
9650 // Check if the hardware supports multisim functionality. If usage of multisim is not
9651 // supported by the modem, indicate that it is restricted.
9652 PhoneCapability staticCapability =
9653 mPhoneConfigurationManager.getStaticPhoneCapability();
9654 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009655 loge("isMultiSimSupportedInternal: no static configuration available");
9656 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009657 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009658 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009659 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9660 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009661 }
9662 // Check if support of multiple SIMs is restricted by carrier
9663 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009664 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009665 }
9666
Michele0ea7d782019-03-19 14:58:42 -07009667 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009668 }
9669
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009670 /**
9671 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009672 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9673 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9674 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009675 * @param numOfSims number of active sims we want to switch to
9676 */
9677 @Override
9678 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009679 if (numOfSims == 1) {
9680 enforceModifyPermission();
9681 } else {
9682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9683 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9684 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009685 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009686
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009687 try {
Michele30b57b22019-03-01 12:01:14 -08009688 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009689 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009690 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9691 return;
9692 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009693 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9694 } finally {
9695 Binder.restoreCallingIdentity(identity);
9696 }
9697 }
9698
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009699 @Override
9700 public boolean isApplicationOnUicc(int subId, int appType) {
9701 enforceReadPrivilegedPermission("isApplicationOnUicc");
9702 Phone phone = getPhone(subId);
9703 if (phone == null) {
9704 return false;
9705 }
9706 final long identity = Binder.clearCallingIdentity();
9707 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009708 UiccPort uiccPort = phone.getUiccPort();
9709 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009710 return false;
9711 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009712 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009713 if (uiccProfile == null) {
9714 return false;
9715 }
9716 if (TelephonyManager.APPTYPE_SIM <= appType
9717 && appType <= TelephonyManager.APPTYPE_ISIM) {
9718 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9719 }
9720 return false;
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009726 /**
chen xub4baa772019-04-03 10:23:41 -07009727 * Get whether making changes to modem configurations will trigger reboot.
9728 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009729 */
9730 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009731 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9732 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009734 mApp, subId, callingPackage, callingFeatureId,
9735 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009736 return false;
9737 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9741 } finally {
9742 Binder.restoreCallingIdentity(identity);
9743 }
9744 }
9745
Nathan Harold29f5f052019-02-15 13:41:57 -08009746 private void updateModemStateMetrics() {
9747 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9748 // TODO: check the state for each modem if the api is ready.
9749 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9750 }
9751
Pengquan Meng3889a572019-01-23 11:16:29 -08009752 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009753 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009754 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009755 // Verify that the callingPackage belongs to the calling UID
9756 mApp.getSystemService(AppOpsManager.class)
9757 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009758 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009759 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009760 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009761 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9762 if (slotInfos != null) {
9763 for (int i = 0; i < slotInfos.length; i++) {
9764 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9765 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9766 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9767 portInfo.getLogicalSlotIndex()));
9768 }
9769 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009770 }
9771 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009772 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009773 } finally {
9774 Binder.restoreCallingIdentity(identity);
9775 }
9776 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009777
9778 /**
9779 * Get the IRadio HAL Version
9780 */
9781 @Override
9782 public int getRadioHalVersion() {
9783 Phone phone = getDefaultPhone();
9784 if (phone == null) return -1;
9785 HalVersion hv = phone.getHalVersion();
9786 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9787 return hv.major * 100 + hv.minor;
9788 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009789
9790 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009791 * Get the current calling package name.
9792 * @return the current calling package name
9793 */
9794 @Override
9795 public String getCurrentPackageName() {
9796 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9797 }
9798
9799 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009800 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9801 * corresponding network requests on a subId.
9802 *
9803 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009804 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009805 * 2) APN is un-metered for this subscription, or
9806 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009807 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009808 *
9809 * @return whether data is allowed for a apn type.
9810 *
9811 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009812 */
9813 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009814 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009815 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9816 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009817
9818 // Now that all security checks passes, perform the operation as ourselves.
9819 final long identity = Binder.clearCallingIdentity();
9820 try {
9821 Phone phone = getPhone(subId);
9822 if (phone == null) return false;
9823
Jack Yu27422a52022-03-21 10:38:05 -07009824 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009825 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009826 isMetered = phone.getDataNetworkController().getDataConfigManager()
9827 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9828 phone.getServiceState().getDataRoaming());
9829 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009830 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 }
9835
9836 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009837 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009838 enforceReadPrivilegedPermission("isApnMetered");
9839
9840 // Now that all security checks passes, perform the operation as ourselves.
9841 final long identity = Binder.clearCallingIdentity();
9842 try {
9843 Phone phone = getPhone(subId);
9844 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009845 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9846 DataUtils.apnTypeToNetworkCapability(apnType),
9847 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009848 } finally {
9849 Binder.restoreCallingIdentity(identity);
9850 }
9851 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009852
9853 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009854 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9855 int subscriptionId, IBooleanConsumer resultCallback) {
9856 enforceModifyPermission();
9857 long token = Binder.clearCallingIdentity();
9858 try {
9859 Phone phone = getPhone(subscriptionId);
9860 if (phone == null) {
9861 try {
9862 if (resultCallback != null) {
9863 resultCallback.accept(false);
9864 }
9865 } catch (RemoteException e) {
9866 // ignore
9867 }
9868 return;
9869 }
9870 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9871 Pair.create(specifiers, (x) -> {
9872 try {
9873 if (resultCallback != null) {
9874 resultCallback.accept(x);
9875 }
9876 } catch (RemoteException e) {
9877 // ignore
9878 }
9879 });
9880 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9881 } finally {
9882 Binder.restoreCallingIdentity(token);
9883 }
9884 }
9885
9886 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009887 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9888 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009889 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009890 mApp, subId, "getSystemSelectionChannels");
9891 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9892 final long identity = Binder.clearCallingIdentity();
9893 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009894 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9895 if (result instanceof IllegalStateException) {
9896 throw (IllegalStateException) result;
9897 }
9898 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009899 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9900 return specifiers;
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
9905
9906 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009907 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009908 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009909 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009910 }
9911
9912 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009913 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9914 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009915 if (callingPackage == null) {
9916 callingPackage = getCurrentPackageName();
9917 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009918 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9919 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009920 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9921 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009922 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9923 }
9924 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9925 Intent intent = new Intent();
9926 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9927 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9928 // Bring up choose default SMS subscription dialog right now
9929 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9930 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9931 mApp.startActivity(intent);
9932 }
chen xud5ca2d52019-05-28 15:20:57 -07009933
9934 @Override
9935 public String getMmsUAProfUrl(int subId) {
9936 //TODO investigate if this API should require proper permission check in R b/133791609
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009939 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9940 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9941 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9942 return carrierUAProfUrl;
9943 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009944 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9945 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009946 } finally {
9947 Binder.restoreCallingIdentity(identity);
9948 }
9949 }
9950
9951 @Override
9952 public String getMmsUserAgent(int subId) {
9953 //TODO investigate if this API should require proper permission check in R b/133791609
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009956 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9957 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9958 if (!TextUtils.isEmpty(carrierUserAgent)) {
9959 return carrierUserAgent;
9960 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009961 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9962 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009963 } finally {
9964 Binder.restoreCallingIdentity(identity);
9965 }
9966 }
Jack Yub07d4972019-05-28 16:12:25 -07009967
9968 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009969 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9970 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009971
Jack Yub07d4972019-05-28 16:12:25 -07009972 final long identity = Binder.clearCallingIdentity();
9973 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009974 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009975 if (phone == null) return false;
9976
Ling Maf188d502022-09-16 15:22:36 -07009977 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981 }
9982
9983 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009984 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009985 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009986 enforceModifyPermission();
9987
changbettyd5c246e2019-12-24 15:40:37 +08009988 final long identity = Binder.clearCallingIdentity();
9989 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009990 Phone phone = getPhone(subscriptionId);
9991 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009992
Ling Maf188d502022-09-16 15:22:36 -07009993 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009999 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010000 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010001 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10002 * otherwise.
10003 */
10004 @Override
10005 public void setCepEnabled(boolean isCepEnabled) {
10006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10007
10008 final long identity = Binder.clearCallingIdentity();
10009 try {
10010 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10011 for (Phone phone : PhoneFactory.getPhones()) {
10012 Phone defaultPhone = phone.getImsPhone();
10013 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10014 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10015 ImsPhoneCallTracker imsPhoneCallTracker =
10016 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10017 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10018 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10019 + imsPhone.getMsisdn());
10020 }
10021 }
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 }
allenwtsu46dcc572020-01-08 18:24:03 +080010026
10027 /**
10028 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10029 *
10030 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10031 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10032 * before being read.
10033 */
10034 @Override
10035 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10036 isCompressed) {
10037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10038 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010039 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10040 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10041 }
10042 if (!isImsAvailableOnDevice()) {
10043 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10044 "IMS not available on device.");
10045 }
10046
10047 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010048 try {
Hui Wang761a6682020-10-31 05:12:53 +000010049 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10050 } finally {
10051 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010052 }
10053 }
zoey chene02881a2019-12-30 16:11:23 +080010054
10055 @Override
10056 public boolean isIccLockEnabled(int subId) {
10057 enforceReadPrivilegedPermission("isIccLockEnabled");
10058
10059 // Now that all security checks passes, perform the operation as ourselves.
10060 final long identity = Binder.clearCallingIdentity();
10061 try {
10062 Phone phone = getPhone(subId);
10063 if (phone != null && phone.getIccCard() != null) {
10064 return phone.getIccCard().getIccLockEnabled();
10065 } else {
10066 return false;
10067 }
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
10072
10073 /**
10074 * Set the ICC pin lock enabled or disabled.
10075 *
10076 * @return an integer representing the status of IccLock enabled or disabled in the following
10077 * three cases:
10078 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10079 * successfully.
10080 * - Positive number and zero for remaining password attempts.
10081 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10082 *
10083 */
10084 @Override
10085 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10086 enforceModifyPermission();
10087
10088 Phone phone = getPhone(subId);
10089 if (phone == null) {
10090 return 0;
10091 }
10092 // Now that all security checks passes, perform the operation as ourselves.
10093 final long identity = Binder.clearCallingIdentity();
10094 try {
10095 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10096 new Pair<Boolean, String>(enabled, password), phone, null);
10097 return attemptsRemaining;
10098
10099 } catch (Exception e) {
10100 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10101 } finally {
10102 Binder.restoreCallingIdentity(identity);
10103 }
10104 return 0;
10105 }
10106
10107 /**
10108 * Change the ICC password used in ICC pin lock.
10109 *
10110 * @return an integer representing the status of IccLock changed in the following three cases:
10111 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10112 * - Positive number and zero for remaining password attempts.
10113 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10114 *
10115 */
10116 @Override
10117 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10118 enforceModifyPermission();
10119
10120 Phone phone = getPhone(subId);
10121 if (phone == null) {
10122 return 0;
10123 }
10124 // Now that all security checks passes, perform the operation as ourselves.
10125 final long identity = Binder.clearCallingIdentity();
10126 try {
10127 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10128 new Pair<String, String>(oldPassword, newPassword), phone, null);
10129 return attemptsRemaining;
10130
10131 } catch (Exception e) {
10132 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10133 } finally {
10134 Binder.restoreCallingIdentity(identity);
10135 }
10136 return 0;
10137 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010138
10139 /**
10140 * Request for receiving user activity notification
10141 */
10142 @Override
10143 public void requestUserActivityNotification() {
10144 if (!mNotifyUserActivity.get()
10145 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10146 mNotifyUserActivity.set(true);
10147 }
10148 }
10149
10150 /**
10151 * Called when userActivity is signalled in the power manager.
10152 * This is safe to call from any thread, with any window manager locks held or not.
10153 */
10154 @Override
10155 public void userActivity() {
10156 // ***************************************
10157 // * Inherited from PhoneWindowManager *
10158 // ***************************************
10159 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10160 // WITH ITS LOCKS HELD.
10161 //
10162 // This code must be VERY careful about the locks
10163 // it acquires.
10164 // In fact, the current code acquires way too many,
10165 // and probably has lurking deadlocks.
10166
10167 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10168 throw new SecurityException("Only the OS may call notifyUserActivity()");
10169 }
10170
10171 if (mNotifyUserActivity.getAndSet(false)) {
10172 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10173 USER_ACTIVITY_NOTIFICATION_DELAY);
10174 }
10175 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010176
10177 @Override
10178 public boolean canConnectTo5GInDsdsMode() {
10179 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10180 }
Jack Yud10cdd42020-09-28 20:28:01 -070010181
10182 @Override
10183 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10184 String callingFeatureId) {
10185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10186 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10187 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10188 }
10189
10190 Phone phone = getPhone(subId);
10191 if (phone == null) {
10192 throw new RuntimeException("phone is not available");
10193 }
10194 // Now that all security checks passes, perform the operation as ourselves.
10195 final long identity = Binder.clearCallingIdentity();
10196 try {
10197 return phone.getEquivalentHomePlmns();
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 }
Daniel Bright59e67312020-11-13 11:49:37 -080010202
10203 @Override
10204 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010205 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10206 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010207 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010208 if (radioInterfaceCapabilities == null) {
10209 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010210 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010211 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010212 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010213
Hui Wang641e81c2020-10-12 12:14:23 -070010214 @Override
10215 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10216 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010217 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10218 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10219 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10220 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10221 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010222 if (DBG) {
10223 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10224 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10225 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10226 }
10227
10228 if (!SubscriptionManager.isValidSubscriptionId(subId)
10229 || appType < TelephonyManager.APPTYPE_UNKNOWN
10230 || appType > TelephonyManager.APPTYPE_ISIM
10231 || nafUrl == null || securityProtocol == null || callback == null) {
10232 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10233 if (callback != null) {
10234 try {
10235 callback.onAuthenticationFailure(
10236 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10237 } catch (RemoteException exception) {
10238 log("Fail to notify onAuthenticationFailure due to " + exception);
10239 }
10240 return;
10241 }
10242 }
10243
10244 final long token = Binder.clearCallingIdentity();
10245 try {
10246 getGbaManager(subId).bootstrapAuthenticationRequest(
10247 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10248 forceBootStrapping, callback));
10249 } finally {
10250 Binder.restoreCallingIdentity(token);
10251 }
10252 }
10253
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010255 * Attempts to set the radio power state for all phones for thermal reason.
10256 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 * requested radio power state will actually be set. See {@link
10258 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10259 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010260 * @param enable {@code true} if trying to turn radio on.
10261 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10262 * false}.
10263 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010264 private boolean setRadioPowerForThermal(boolean enable) {
10265 boolean isPhoneAvailable = false;
10266 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10267 Phone phone = PhoneFactory.getPhone(i);
10268 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010269 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010270 isPhoneAvailable = true;
10271 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010272 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010273
10274 // return true if successfully informed the phone object about the thermal radio power
10275 // request.
10276 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010277 }
10278
10279 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010280 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010281 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10282 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10283 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10284 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10285 throw new IllegalArgumentException("modem does not support data throttling");
10286 }
10287
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010288 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10289 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010290 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10292 }
10293
Sarah Chinecc78c42022-03-31 21:16:48 -070010294 setDataEnabledForReason(
10295 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010296
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010297 if (isDataThrottlingSupported) {
10298 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010299 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010300 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10301 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10302 } else if (thermalMitigationResult
10303 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010304 log("Modem likely does not support data throttling on secondary carrier. Data " +
10305 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10306 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010307 }
10308 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010309 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010310
10311 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 }
10313
Jack Nudelman644b91a2021-03-12 14:09:48 -080010314 private static List<String> getThermalMitigationAllowlist(Context context) {
10315 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10316 for (String pckg : context.getResources()
10317 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10318 sThermalMitigationAllowlistedPackages.add(pckg);
10319 }
10320 }
10321
10322 return sThermalMitigationAllowlistedPackages;
10323 }
10324
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010325 private boolean isAnyPhoneInEmergencyState() {
10326 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10327 if (tm.isInEmergencyCall()) {
10328 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10329 return true;
10330 }
10331 for (Phone phone : PhoneFactory.getPhones()) {
10332 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10333 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10334 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10335 + phone.isInEcm());
10336 return true;
10337 }
10338 }
10339
10340 return false;
10341 }
10342
Jack Nudelman644b91a2021-03-12 14:09:48 -080010343 /**
10344 * Used by shell commands to add an authorized package name for thermal mitigation.
10345 * @param packageName name of package to be allowlisted
10346 * @param context
10347 */
10348 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10349 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10350 sThermalMitigationAllowlistedPackages.add(packageName);
10351 }
10352
10353 /**
10354 * Used by shell commands to remove an authorized package name for thermal mitigation.
10355 * @param packageName name of package to remove from allowlist
10356 * @param context
10357 */
10358 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10359 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10360 sThermalMitigationAllowlistedPackages.remove(packageName);
10361 }
10362
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010363 /**
10364 * Thermal mitigation request to control functionalities at modem.
10365 *
10366 * @param subId the id of the subscription.
10367 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010368 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010369 *
10370 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10371 */
10372 @Override
10373 @ThermalMitigationResult
10374 public int sendThermalMitigationRequest(
10375 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010376 ThermalMitigationRequest thermalMitigationRequest,
10377 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010378 enforceModifyPermission();
10379
Jack Nudelman644b91a2021-03-12 14:09:48 -080010380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10381 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10382 .contains(callingPackage)) {
10383 throw new SecurityException("Calling package must be configured in the device config. "
10384 + "calling package: " + callingPackage);
10385 }
10386
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010387 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10388 final long identity = Binder.clearCallingIdentity();
10389
10390 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10391 try {
10392 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10393 switch (thermalMitigationAction) {
10394 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10395 thermalMitigationResult =
10396 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010397 thermalMitigationRequest.getDataThrottlingRequest(),
10398 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010399 break;
10400 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10401 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10402 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10403 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10404 }
10405
10406 // Ensure that radio is on. If not able to power on due to phone being
10407 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010408 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010409 thermalMitigationResult =
10410 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10411 break;
10412 }
10413
10414 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010415 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010416 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10417 break;
10418 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10419 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10420 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10421 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10422 }
10423
10424 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10425 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010426 Phone phone = getPhone(subId);
10427 if (phone == null) {
10428 thermalMitigationResult =
10429 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10430 break;
10431 }
10432
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010433 TelephonyConnectionService service =
10434 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010435 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010436 Log.e(LOG_TAG, "An emergency call is pending");
10437 thermalMitigationResult =
10438 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10439 break;
10440 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010441 thermalMitigationResult =
10442 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10443 break;
10444 }
10445 } else {
10446 thermalMitigationResult =
10447 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10448 break;
10449 }
10450
10451 // Turn radio off. If not able to power off due to phone being unavailable,
10452 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010453 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010454 thermalMitigationResult =
10455 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10456 break;
10457 }
10458 thermalMitigationResult =
10459 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10460 break;
10461 default:
10462 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10463 + "not exist. Requested action: " + thermalMitigationAction);
10464 }
10465 } catch (IllegalArgumentException e) {
10466 throw e;
10467 } catch (Exception e) {
10468 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10469 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473
10474 if (DBG) {
10475 log("thermalMitigationRequest returning with thermalMitigationResult: "
10476 + thermalMitigationResult);
10477 }
10478
10479 return thermalMitigationResult;
10480 }
Hui Wang641e81c2020-10-12 12:14:23 -070010481
10482 /**
10483 * Set the GbaService Package Name that Telephony will bind to.
10484 *
10485 * @param subId The sim that the GbaService is associated with.
10486 * @param packageName The name of the package to be replaced with.
10487 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10488 */
10489 @Override
10490 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10491 enforceModifyPermission();
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
10495 return getGbaManager(subId).overrideServicePackage(packageName);
10496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 }
10500
10501 /**
10502 * Return the package name of the currently bound GbaService.
10503 *
10504 * @param subId The sim that the GbaService is associated with.
10505 * @return the package name of the GbaService configuration, null if GBA is not supported.
10506 */
10507 @Override
10508 public String getBoundGbaService(int subId) {
10509 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10510
10511 final long identity = Binder.clearCallingIdentity();
10512 try {
10513 return getGbaManager(subId).getServicePackage();
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
10519 /**
10520 * Set the release time for telephony to unbind GbaService.
10521 *
10522 * @param subId The sim that the GbaService is associated with.
10523 * @param interval The release time to unbind GbaService by millisecond.
10524 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10525 */
10526 @Override
10527 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10528 enforceModifyPermission();
10529
10530 final long identity = Binder.clearCallingIdentity();
10531 try {
10532 return getGbaManager(subId).overrideReleaseTime(interval);
10533 } finally {
10534 Binder.restoreCallingIdentity(identity);
10535 }
10536 }
10537
10538 /**
10539 * Return the release time for telephony to unbind GbaService.
10540 *
10541 * @param subId The sim that the GbaService is associated with.
10542 * @return The release time to unbind GbaService by millisecond.
10543 */
10544 @Override
10545 public int getGbaReleaseTime(int subId) {
10546 enforceReadPrivilegedPermission("getGbaReleaseTime");
10547
10548 final long identity = Binder.clearCallingIdentity();
10549 try {
10550 return getGbaManager(subId).getReleaseTime();
10551 } finally {
10552 Binder.restoreCallingIdentity(identity);
10553 }
10554 }
10555
10556 private GbaManager getGbaManager(int subId) {
10557 GbaManager instance = GbaManager.getInstance(subId);
10558 if (instance == null) {
10559 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10560 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10561 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10562 }
10563 return instance;
10564 }
Hui Wang761a6682020-10-31 05:12:53 +000010565
10566 /**
10567 * indicate whether the device and the carrier can support
10568 * RCS VoLTE single registration.
10569 */
10570 @Override
10571 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010572 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10573 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10574 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10575 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010576
10577 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10578 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10579 }
10580
10581 final long identity = Binder.clearCallingIdentity();
10582 try {
10583 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10584 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010585 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10586 if (isCapable != null) {
10587 return isCapable;
10588 }
Hui Wang761a6682020-10-31 05:12:53 +000010589 }
Hui Wang67af90e2021-06-04 16:57:15 -070010590 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10591 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 /**
10598 * Register RCS provisioning callback.
10599 */
10600 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010601 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010602 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010603 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010604 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010605 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10606 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010607
10608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10610 }
10611 if (!isImsAvailableOnDevice()) {
10612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10613 "IMS not available on device.");
10614 }
10615
10616 final long identity = Binder.clearCallingIdentity();
10617 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010618 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010619 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010620 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10621 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010622 }
Hui Wang761a6682020-10-31 05:12:53 +000010623 } finally {
10624 Binder.restoreCallingIdentity(identity);
10625 }
10626 }
10627
10628 /**
10629 * Unregister RCS provisioning callback.
10630 */
10631 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010632 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010633 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010634 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010635 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010636 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10637 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010638
10639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10640 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10641 }
10642 if (!isImsAvailableOnDevice()) {
10643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10644 "IMS not available on device.");
10645 }
10646
10647 final long identity = Binder.clearCallingIdentity();
10648 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010649 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010650 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
10655
10656 /**
10657 * trigger RCS reconfiguration.
10658 */
10659 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010660 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10661 "triggerRcsReconfiguration",
10662 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010663
10664 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10665 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10666 }
10667 if (!isImsAvailableOnDevice()) {
10668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10669 "IMS not available on device.");
10670 }
10671
10672 final long identity = Binder.clearCallingIdentity();
10673 try {
10674 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10675 } finally {
10676 Binder.restoreCallingIdentity(identity);
10677 }
10678 }
10679
10680 /**
10681 * Provide the client configuration parameters of the RCS application.
10682 */
10683 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010684 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10685 "setRcsClientConfiguration",
10686 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010687
10688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10690 }
10691 if (!isImsAvailableOnDevice()) {
10692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10693 "IMS not available on device.");
10694 }
10695
10696 final long identity = Binder.clearCallingIdentity();
10697
10698 try {
10699 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10700 if (configBinder == null) {
10701 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010702 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10703 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010704 } else {
10705 configBinder.setRcsClientConfiguration(rcc);
10706 }
joonhunshin3e154242021-09-17 06:33:39 +000010707
10708 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10709 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010710 } catch (RemoteException e) {
10711 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010712 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10713 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
10719 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010720 * Enables or disables the test mode for RCS VoLTE single registration.
10721 */
10722 @Override
10723 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10724 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10725 "setRcsSingleRegistrationTestModeEnabled");
10726
10727 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10728 }
10729
10730 /**
10731 * Gets the test mode for RCS VoLTE single registration.
10732 */
10733 @Override
10734 public boolean getRcsSingleRegistrationTestModeEnabled() {
10735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10736 "getRcsSingleRegistrationTestModeEnabled");
10737
10738 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10739 }
10740
10741 /**
Hui Wang761a6682020-10-31 05:12:53 +000010742 * Overrides the config of RCS VoLTE single registration enabled for the device.
10743 */
10744 @Override
10745 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10747 "setDeviceSingleRegistrationEnabledOverride");
10748 enforceModifyPermission();
10749
10750 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10751 : Boolean.parseBoolean(enabledStr);
10752 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010753 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010754 }
10755
10756 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010757 * Sends a device to device communication message. Only usable via shell.
10758 * @param message message to send.
10759 * @param value message value.
10760 */
10761 @Override
10762 public void sendDeviceToDeviceMessage(int message, int value) {
10763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010764 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010765 enforceModifyPermission();
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 TelephonyConnectionService service =
10770 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10771 if (service == null) {
10772 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10773 return;
10774 }
10775 service.sendTestDeviceToDeviceMessage(message, value);
10776 } finally {
10777 Binder.restoreCallingIdentity(identity);
10778 }
10779 }
10780
Tyler Gunnbabbda02021-02-10 11:05:02 -080010781 /**
10782 * Sets the specified device to device transport active.
10783 * @param transport The transport to set active.
10784 */
10785 @Override
10786 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10787 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10788 "setActiveDeviceToDeviceTransport");
10789 enforceModifyPermission();
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 TelephonyConnectionService service =
10794 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10795 if (service == null) {
10796 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10797 return;
10798 }
10799 service.setActiveDeviceToDeviceTransport(transport);
10800 } finally {
10801 Binder.restoreCallingIdentity(identity);
10802 }
10803 }
Tyler Gunn92479152021-01-20 16:30:10 -080010804
Tyler Gunnd4339262021-05-03 14:46:49 -070010805 @Override
10806 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10808 "setDeviceToDeviceForceEnabled");
10809
10810 final long identity = Binder.clearCallingIdentity();
10811 try {
10812 Arrays.stream(PhoneFactory.getPhones()).forEach(
10813 p -> {
10814 Phone thePhone = p.getImsPhone();
10815 if (thePhone != null && thePhone instanceof ImsPhone) {
10816 ImsPhone imsPhone = (ImsPhone) thePhone;
10817 CallTracker tracker = imsPhone.getCallTracker();
10818 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10819 ImsPhoneCallTracker imsPhoneCallTracker =
10820 (ImsPhoneCallTracker) tracker;
10821 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10822 }
10823 }
10824 }
10825 );
10826 } finally {
10827 Binder.restoreCallingIdentity(identity);
10828 }
10829 }
10830
Tyler Gunn92479152021-01-20 16:30:10 -080010831 /**
Hui Wang761a6682020-10-31 05:12:53 +000010832 * Gets the config of RCS VoLTE single registration enabled for the device.
10833 */
10834 @Override
10835 public boolean getDeviceSingleRegistrationEnabled() {
10836 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10837 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10838 }
10839
10840 /**
10841 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10842 */
10843 @Override
10844 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10846 "setCarrierSingleRegistrationEnabledOverride");
10847 enforceModifyPermission();
10848
10849 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10850 : Boolean.parseBoolean(enabledStr);
10851 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10852 subId, enabled);
10853 }
10854
10855 /**
10856 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10857 */
10858 @Override
10859 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10860 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10861 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10862 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010863
10864 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010865 * Overrides the ims feature validation result
10866 */
10867 @Override
10868 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10870 "setImsFeatureValidationOverride");
10871
10872 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10873 : Boolean.parseBoolean(enabledStr);
10874 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10875 subId, enabled);
10876 }
10877
10878 /**
10879 * Gets the ims feature validation override value
10880 */
10881 @Override
10882 public boolean getImsFeatureValidationOverride(int subId) {
10883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10884 "getImsFeatureValidationOverride");
10885 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10886 }
10887
10888 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010889 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10890 * their mobile plan.
10891 */
10892 @Override
10893 public String getMobileProvisioningUrl() {
10894 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
10897 return getDefaultPhone().getMobileProvisioningUrl();
10898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010902
James.cf Linbcdf8b32021-01-14 16:44:13 +080010903 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010904 * Get the EAB contact from the EAB database.
10905 */
10906 @Override
10907 public String getContactFromEab(String contact) {
10908 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10909 enforceModifyPermission();
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
10917
10918 /**
Calvin Pana1434322021-07-01 19:27:01 +080010919 * Get the EAB capability from the EAB database.
10920 */
10921 @Override
10922 public String getCapabilityFromEab(String contact) {
10923 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10924 enforceModifyPermission();
10925 final long identity = Binder.clearCallingIdentity();
10926 try {
10927 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
10932
10933 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010934 * Remove the EAB contacts from the EAB database.
10935 */
10936 @Override
10937 public int removeContactFromEab(int subId, String contacts) {
10938 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10939 enforceModifyPermission();
10940 final long identity = Binder.clearCallingIdentity();
10941 try {
10942 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10943 } finally {
10944 Binder.restoreCallingIdentity(identity);
10945 }
10946 }
10947
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010948 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010949 public boolean getDeviceUceEnabled() {
10950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10951 final long identity = Binder.clearCallingIdentity();
10952 try {
10953 return mApp.getDeviceUceEnabled();
10954 } finally {
10955 Binder.restoreCallingIdentity(identity);
10956 }
10957 }
10958
10959 @Override
10960 public void setDeviceUceEnabled(boolean isEnabled) {
10961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10962 final long identity = Binder.clearCallingIdentity();
10963 try {
10964 mApp.setDeviceUceEnabled(isEnabled);
10965 } finally {
10966 Binder.restoreCallingIdentity(identity);
10967 }
10968 }
10969
Brad Ebinger14d467f2021-02-12 06:18:28 +000010970 /**
10971 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10972 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10973 */
10974 // Used for SHELL command only right now.
10975 @Override
10976 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10977 List<String> featureTags) {
10978 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10979 "addUceRegistrationOverrideShell");
10980 final long identity = Binder.clearCallingIdentity();
10981 try {
10982 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10983 new ArraySet<>(featureTags));
10984 } catch (ImsException e) {
10985 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10986 } finally {
10987 Binder.restoreCallingIdentity(identity);
10988 }
10989 }
10990
10991 /**
10992 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10993 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10994 */
10995 // Used for SHELL command only right now.
10996 @Override
10997 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10998 List<String> featureTags) {
10999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11000 "removeUceRegistrationOverrideShell");
11001 final long identity = Binder.clearCallingIdentity();
11002 try {
11003 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11004 new ArraySet<>(featureTags));
11005 } catch (ImsException e) {
11006 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11007 } finally {
11008 Binder.restoreCallingIdentity(identity);
11009 }
11010 }
11011
11012 /**
11013 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11014 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11015 */
11016 // Used for SHELL command only right now.
11017 @Override
11018 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11019 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11020 "clearUceRegistrationOverrideShell");
11021 final long identity = Binder.clearCallingIdentity();
11022 try {
11023 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11024 } catch (ImsException e) {
11025 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11026 } finally {
11027 Binder.restoreCallingIdentity(identity);
11028 }
11029 }
11030
11031 /**
11032 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11033 */
11034 // Used for SHELL command only right now.
11035 @Override
11036 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11038 "getLatestRcsContactUceCapabilityShell");
11039 final long identity = Binder.clearCallingIdentity();
11040 try {
11041 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11042 } catch (ImsException e) {
11043 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11044 } finally {
11045 Binder.restoreCallingIdentity(identity);
11046 }
11047 }
11048
11049 /**
11050 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11051 * device does not have an active PUBLISH.
11052 */
11053 // Used for SHELL command only right now.
11054 @Override
11055 public String getLastUcePidfXmlShell(int subId) {
11056 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11057 final long identity = Binder.clearCallingIdentity();
11058 try {
11059 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11060 } catch (ImsException e) {
11061 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11062 } finally {
11063 Binder.restoreCallingIdentity(identity);
11064 }
11065 }
11066
James.cf Line8713a42021-04-29 16:04:26 +080011067 /**
11068 * Remove UCE requests cannot be sent to the network status.
11069 */
11070 // Used for SHELL command only right now.
11071 @Override
11072 public boolean removeUceRequestDisallowedStatus(int subId) {
11073 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11074 final long identity = Binder.clearCallingIdentity();
11075 try {
11076 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11077 } catch (ImsException e) {
11078 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11079 } finally {
11080 Binder.restoreCallingIdentity(identity);
11081 }
11082 }
11083
James.cf Lin18bb9002021-05-25 01:37:38 +080011084 /**
11085 * Remove UCE requests cannot be sent to the network status.
11086 */
11087 // Used for SHELL command only.
11088 @Override
11089 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11090 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11091 final long identity = Binder.clearCallingIdentity();
11092 try {
11093 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11094 } catch (ImsException e) {
11095 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11096 } finally {
11097 Binder.restoreCallingIdentity(identity);
11098 }
11099 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011100
James.cf Lin4b784aa2021-01-31 03:25:15 +080011101 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011102 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11103 String callingPackage) {
11104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11105 mApp, subId, "setSignalStrengthUpdateRequest");
11106
11107 final int callingUid = Binder.getCallingUid();
11108 // Verify that tha callingPackage belongs to the calling UID
11109 mApp.getSystemService(AppOpsManager.class)
11110 .checkPackage(callingUid, callingPackage);
11111
Rambo Wang3607f502021-02-01 21:51:40 -080011112 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011113
11114 final long identity = Binder.clearCallingIdentity();
11115 try {
11116 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11117 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11118
11119 if (result instanceof IllegalStateException) {
11120 throw (IllegalStateException) result;
11121 }
11122 } finally {
11123 Binder.restoreCallingIdentity(identity);
11124 }
11125 }
11126
11127 @Override
11128 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11129 String callingPackage) {
11130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11131 mApp, subId, "clearSignalStrengthUpdateRequest");
11132
11133 final int callingUid = Binder.getCallingUid();
11134 // Verify that tha callingPackage belongs to the calling UID
11135 mApp.getSystemService(AppOpsManager.class)
11136 .checkPackage(callingUid, callingPackage);
11137
11138 final long identity = Binder.clearCallingIdentity();
11139 try {
11140 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11141 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11142
11143 if (result instanceof IllegalStateException) {
11144 throw (IllegalStateException) result;
11145 }
11146 } finally {
11147 Binder.restoreCallingIdentity(identity);
11148 }
11149 }
11150
Rambo Wang3607f502021-02-01 21:51:40 -080011151 private static void validateSignalStrengthUpdateRequest(Context context,
11152 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011153 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11154 // phone/system process do not have further restriction on request
11155 return;
11156 }
11157
11158 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011159 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011160 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011161 context.enforceCallingOrSelfPermission(
11162 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11163 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011164 }
11165
11166 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11167 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11168 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11169 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11170 || info.isEnabled()) {
11171 throw new IllegalArgumentException(
11172 "Only system can set hide fields in SignalThresholdInfo");
11173 }
11174
11175 // Thresholds length for each RAN need in range. This has been validated in
11176 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11177 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11178 final int[] thresholds = info.getThresholds();
11179 Objects.requireNonNull(thresholds);
11180 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11181 || thresholds.length
11182 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11183 throw new IllegalArgumentException(
11184 "thresholds length is out of range: " + thresholds.length);
11185 }
11186 }
11187 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011188
11189 /**
11190 * Gets the current phone capability.
11191 *
11192 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11193 * @return the PhoneCapability which describes the data connection capability of modem.
11194 * It's used to evaluate possible phone config change, for example from single
11195 * SIM device to multi-SIM device.
11196 */
11197 @Override
11198 public PhoneCapability getPhoneCapability() {
11199 enforceReadPrivilegedPermission("getPhoneCapability");
11200 final long identity = Binder.clearCallingIdentity();
11201 try {
11202 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11203 } finally {
11204 Binder.restoreCallingIdentity(identity);
11205 }
11206 }
Michele Berionne5e411512020-11-13 02:36:59 +000011207
11208 /**
11209 * Prepare TelephonyManager for an unattended reboot. The reboot is
11210 * required to be done shortly after the API is invoked.
11211 */
11212 @Override
11213 @TelephonyManager.PrepareUnattendedRebootResult
11214 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011216 enforceRebootPermission();
11217
11218 final long identity = Binder.clearCallingIdentity();
11219 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011220 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011221 } finally {
11222 Binder.restoreCallingIdentity(identity);
11223 }
11224 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011225
11226 /**
11227 * Request to get the current slicing configuration including URSP rules and
11228 * NSSAIs (configured, allowed and rejected).
11229 *
11230 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11231 */
11232 @Override
11233 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011234 TelephonyPermissions
11235 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11236 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011237
11238 final long identity = Binder.clearCallingIdentity();
11239 try {
11240 Phone phone = getDefaultPhone();
11241 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11242 } finally {
11243 Binder.restoreCallingIdentity(identity);
11244 }
11245 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011246
11247 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011248 * Check whether the given premium capability is available for purchase from the carrier.
11249 *
11250 * @param capability The premium capability to check.
11251 * @param subId The subId to check the premium capability for.
11252 *
11253 * @return Whether the given premium capability is available to purchase.
11254 */
11255 @Override
11256 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11257 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11258 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11259 log("Premium capability "
11260 + TelephonyManager.convertPremiumCapabilityToString(capability)
11261 + " is not available for purchase due to missing permissions.");
11262 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11263 + "permission READ_BASIC_PHONE_STATE.");
11264 }
11265
11266 Phone phone = getPhone(subId);
11267 final long identity = Binder.clearCallingIdentity();
11268 try {
11269 return SliceStore.getInstance(phone)
11270 .isPremiumCapabilityAvailableForPurchase(capability);
11271 } finally {
11272 Binder.restoreCallingIdentity(identity);
11273 }
11274 }
11275
11276 /**
11277 * Purchase the given premium capability from the carrier.
11278 *
11279 * @param capability The premium capability to purchase.
11280 * @param callback The result of the purchase request.
11281 * @param subId The subId to purchase the premium capability for.
11282 */
11283 @Override
11284 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11285 log("purchasePremiumCapability: capability="
11286 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11287 + getCurrentPackageName());
11288
11289 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11290 mApp, "purchasePremiumCapability")) {
11291 log("purchasePremiumCapability "
11292 + TelephonyManager.convertPremiumCapabilityToString(capability)
11293 + " failed due to missing permissions.");
11294 throw new SecurityException("purchasePremiumCapability requires permission "
11295 + "READ_BASIC_PHONE_STATE.");
11296 }
11297
11298 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011299 String appName;
11300 try {
11301 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11302 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11303 } catch (PackageManager.NameNotFoundException e) {
11304 appName = "An application";
11305 }
11306 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11307 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011308 }
11309
11310 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011311 * Register an IMS connection state callback
11312 */
11313 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011314 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11315 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011316 if (feature == ImsFeature.FEATURE_MMTEL) {
11317 // ImsMmTelManager
11318 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11319 TelephonyPermissions
11320 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11321 mApp, subId, "registerImsStateCallback");
11322 } else if (feature == ImsFeature.FEATURE_RCS) {
11323 // ImsRcsManager or SipDelegateManager
11324 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11325 Binder.getCallingUid(), "registerImsStateCallback",
11326 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11327 Manifest.permission.READ_PRECISE_PHONE_STATE,
11328 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11329 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11330 }
11331
11332 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11334 "IMS not available on device.");
11335 }
11336
11337 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11338 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11339 }
11340
11341 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11342 if (controller == null) {
11343 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11344 "IMS not available on device.");
11345 }
11346
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011347 if (callingPackage == null) {
11348 callingPackage = getCurrentPackageName();
11349 }
11350
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011351 final long token = Binder.clearCallingIdentity();
11352 try {
11353 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011354 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011355 } catch (ImsException e) {
11356 throw new ServiceSpecificException(e.getCode());
11357 } finally {
11358 Binder.restoreCallingIdentity(token);
11359 }
11360 }
11361
11362 /**
11363 * Unregister an IMS connection state callback
11364 */
11365 @Override
11366 public void unregisterImsStateCallback(IImsStateCallback cb) {
11367 final long token = Binder.clearCallingIdentity();
11368 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11369 if (controller == null) {
11370 return;
11371 }
11372 try {
11373 controller.unregisterImsStateCallback(cb);
11374 } finally {
11375 Binder.restoreCallingIdentity(token);
11376 }
11377 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011378
11379 /**
11380 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11381 *
11382 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11383 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11384 * SecurityException.
11385 * If there is current registered network this value will be same as the registered cell
11386 * identity. If the device goes out of service the previous cell identity is cached and
11387 * will be returned. If the cache age of the Cell identity is more than 24 hours
11388 * it will be cleared and null will be returned.
11389 *
11390 */
11391 @Override
11392 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11393 String callingFeatureId) {
11394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11395 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11396 LocationAccessPolicy.checkLocationPermission(mApp,
11397 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11398 .setCallingPackage(callingPackage)
11399 .setCallingFeatureId(callingFeatureId)
11400 .setCallingPid(Binder.getCallingPid())
11401 .setCallingUid(Binder.getCallingUid())
11402 .setMethod("getLastKnownCellIdentity")
11403 .setLogAsInfo(true)
11404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11405 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11406 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11407 .build());
11408
11409 boolean hasFinePermission =
11410 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11411 if (!hasFinePermission
11412 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11413 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011414 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011415 }
11416
11417 final long identity = Binder.clearCallingIdentity();
11418 try {
11419 Phone phone = getPhone(subId);
11420 if (phone == null) return null;
11421 ServiceStateTracker sst = phone.getServiceStateTracker();
11422 if (sst == null) return null;
11423 return sst.getLastKnownCellIdentity();
11424 } finally {
11425 Binder.restoreCallingIdentity(identity);
11426 }
11427 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011428
jimsun3b9ccac2021-10-26 15:01:23 +080011429 /**
11430 * Sets the modem service class Name that Telephony will bind to.
11431 *
11432 * @param serviceName The class name of the modem service.
11433 * @return true if the operation is succeed, otherwise false.
11434 */
11435 public boolean setModemService(String serviceName) {
11436 Log.d(LOG_TAG, "setModemService - " + serviceName);
11437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11439 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11440 "setModemService");
11441 return mPhoneConfigurationManager.setModemService(serviceName);
11442 }
11443
11444 /**
11445 * Return the class name of the currently bounded modem service.
11446 *
11447 * @return the class name of the modem service.
11448 */
11449 public String getModemService() {
11450 String result;
11451 Log.d(LOG_TAG, "getModemService");
11452 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11453 TelephonyPermissions
11454 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11455 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11456 "getModemService");
11457 result = mPhoneConfigurationManager.getModemService();
11458 Log.d(LOG_TAG, "result = " + result);
11459 return result;
11460 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011461
11462 @Override
11463 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11464 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11465 mApp.enforceCallingOrSelfPermission(
11466 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11468
11469 final long identity = Binder.clearCallingIdentity();
11470 try {
11471 Phone phone = getPhone(subId);
11472 if (phone == null) return;
11473 phone.setVoiceServiceStateOverride(hasService);
11474 } finally {
11475 Binder.restoreCallingIdentity(identity);
11476 }
11477 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011478
11479 /**
11480 * set removable eSIM as default eUICC.
11481 *
11482 * @hide
11483 */
11484 @Override
11485 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11486 enforceModifyPermission();
11487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11488
11489 final long identity = Binder.clearCallingIdentity();
11490 try {
11491 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11492 } finally {
11493 Binder.restoreCallingIdentity(identity);
11494 }
11495 }
11496
11497 /**
11498 * Returns whether the removable eSIM is default eUICC or not.
11499 *
11500 * @hide
11501 */
11502 @Override
11503 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11504 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11506
11507 final long identity = Binder.clearCallingIdentity();
11508 try {
11509 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11510 } finally {
11511 Binder.restoreCallingIdentity(identity);
11512 }
11513 }
11514
11515
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011516}