blob: bd2be12b0eed8d84616cf8d290f315b1320852a5 [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) {
6491 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006492 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6493 boolean hasNetworkScanPermission =
6494 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6495 == PERMISSION_GRANTED;
6496
6497 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6498 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6499 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006500 }
6501
6502 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6503 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006504 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6505 return new SecurityException("Specific channels must not be"
6506 + " scanned without location access.");
6507 }
6508 }
6509 }
6510
Hall Liub2ac8ef2019-02-28 15:56:23 -08006511 return null;
6512 }
6513
yinxu504e1392017-04-12 16:03:22 -07006514 /**
6515 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006516 *
6517 * @param subId id of the subscription
6518 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006519 */
6520 @Override
6521 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6523 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006524
Hall Liu912dfd32019-04-25 14:02:26 -07006525 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 final long identity = Binder.clearCallingIdentity();
6527 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006528 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
yinxu504e1392017-04-12 16:03:22 -07006532 }
6533
6534 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006535 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006536 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006537 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006538 */
6539 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006540 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006541 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006542 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006543 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544
6545 final long identity = Binder.clearCallingIdentity();
6546 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 if (DBG) log("getAllowedNetworkTypesBitmask");
6548 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6549 int networkTypesBitmask = (result != null ? result[0] : -1);
6550 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6551 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006555 }
6556
6557 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006558 * Get the allowed network types for certain reason.
6559 *
6560 * @param subId the id of the subscription.
6561 * @param reason the reason the allowed network type change is taking place
6562 * @return the allowed network types.
6563 */
6564 @Override
6565 public long getAllowedNetworkTypesForReason(int subId,
6566 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006567 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006568 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
6574 }
6575 }
6576
6577 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006578 * Enable/Disable E-UTRA-NR Dual Connectivity
6579 * @param subId subscription id of the sim card
6580 * @param nrDualConnectivityState expected NR dual connectivity state
6581 * This can be passed following states
6582 * <ol>
6583 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6584 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6585 * <li>Disable NR dual connectivity and force secondary cell to be released
6586 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6587 * </ol>
6588 * @return operation result.
6589 */
6590 @Override
6591 public int setNrDualConnectivityState(int subId,
6592 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6594 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006595 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006596 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6597 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6598 }
6599
Sooraj Sasindran37444802020-08-11 10:40:43 -07006600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6604 nrDualConnectivityState, subId,
6605 workSource);
6606 if (DBG) log("enableNRDualConnectivity result: " + result);
6607 return result;
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
6610 }
6611 }
6612
6613 /**
6614 * Is E-UTRA-NR Dual Connectivity enabled
6615 * @return true if dual connectivity is enabled else false
6616 */
6617 @Override
6618 public boolean isNrDualConnectivityEnabled(int subId) {
6619 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006620 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006621 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006622 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006623 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6624 return false;
6625 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006626 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6630 null, subId, workSource);
6631 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6632 return isEnabled;
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
6636 }
6637
6638 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006639 * Set the allowed network types of the device and
6640 * provide the reason triggering the allowed network change.
6641 *
6642 * @param subId the id of the subscription.
6643 * @param reason the reason the allowed network type change is taking place
6644 * @param allowedNetworkTypes the allowed network types.
6645 * @return true on success; false on any failure.
6646 */
6647 @Override
6648 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006649 @TelephonyManager.AllowedNetworkTypesReason int reason,
6650 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6652 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006653 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006654 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6655 return false;
6656 }
6657 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6658 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 return false;
6660 }
6661
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006662 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6663 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6664
6665
6666 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6667 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6668 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006669 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006670
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006671 final long identity = Binder.clearCallingIdentity();
6672 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006673 Boolean success = (Boolean) sendRequest(
6674 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6675 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6676
6677 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6678 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
6684 /**
Miaoa84611c2019-03-15 09:21:10 +08006685 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006686 *
Miaoa84611c2019-03-15 09:21:10 +08006687 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006688 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006689 * @hide
6690 */
6691 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006692 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006693 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006695 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 try {
Miaoa84611c2019-03-15 09:21:10 +08006697 if (phone != null) {
6698 return phone.hasMatchedTetherApnSetting();
6699 } else {
6700 return false;
6701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 } finally {
6703 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006704 }
Junda Liu475951f2014-11-07 16:45:03 -08006705 }
6706
6707 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006708 * Get the user enabled state of Mobile Data.
6709 *
6710 * TODO: remove and use isUserDataEnabled.
6711 * This can't be removed now because some vendor codes
6712 * calls through ITelephony directly while they should
6713 * use TelephonyManager.
6714 *
6715 * @return true on enabled
6716 */
6717 @Override
6718 public boolean getDataEnabled(int subId) {
6719 return isUserDataEnabled(subId);
6720 }
6721
6722 /**
6723 * Get whether mobile data is enabled per user setting.
6724 *
6725 * There are other factors deciding whether mobile data is actually enabled, but they are
6726 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006727 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006728 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6729 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006730 *
6731 * @return {@code true} if data is enabled else {@code false}
6732 */
6733 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006734 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006735 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006736 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006737 try {
6738 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6739 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006740 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006741 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6742 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006743 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 mApp, subId, functionName);
6746
Robert Greenwalt646120a2014-05-23 11:54:03 -07006747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
6751 int phoneId = mSubscriptionController.getPhoneId(subId);
6752 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6753 Phone phone = PhoneFactory.getPhone(phoneId);
6754 if (phone != null) {
6755 boolean retVal = phone.isUserDataEnabled();
6756 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6757 return retVal;
6758 } else {
6759 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6760 return false;
6761 }
6762 } finally {
6763 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006764 }
6765 }
6766
6767 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006768 * Checks if the device is capable of mobile data by considering whether whether the
6769 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6770 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006771 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006772 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006773 */
6774 @Override
6775 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006776 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006777 try {
6778 try {
6779 mApp.enforceCallingOrSelfPermission(
6780 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006781 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006782 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006783 try {
6784 mApp.enforceCallingOrSelfPermission(
6785 android.Manifest.permission.READ_PHONE_STATE,
6786 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006787 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006788 mApp.enforceCallingOrSelfPermission(
6789 permission.READ_BASIC_PHONE_STATE, functionName);
6790 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006791 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006792 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006799 Phone phone = PhoneFactory.getPhone(phoneId);
6800 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006801 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006802 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006803 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 return retVal;
6805 } else {
6806 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6807 return false;
6808 }
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006811 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006812 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006813
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006814 /**
6815 * Check if data is enabled for a specific reason
6816 * @param subId Subscription index
6817 * @param reason the reason the data enable change is taking place
6818 * @return {@code true} if the overall data is enabled; {@code false} if not.
6819 */
6820 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006821 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006822 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006823 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006824 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006825 try {
6826 mApp.enforceCallingOrSelfPermission(
6827 android.Manifest.permission.ACCESS_NETWORK_STATE,
6828 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006829 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006830 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6831 functionName);
6832 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006833 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006834 try {
6835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006836 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006837 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006839 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006840 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006841 }
6842
6843
6844 final long identity = Binder.clearCallingIdentity();
6845 try {
6846 int phoneId = mSubscriptionController.getPhoneId(subId);
6847 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006848 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006849 + " reason=" + reason);
6850 }
6851 Phone phone = PhoneFactory.getPhone(phoneId);
6852 if (phone != null) {
6853 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006854 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006855 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006856 return retVal;
6857 } else {
6858 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006859 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006860 + subId + " retVal=false");
6861 }
6862 return false;
6863 }
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006869 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006870 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006871 // No permission needed; this only lets the caller inspect their own status.
6872 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006873 }
Junda Liu29340342014-07-10 15:23:27 -07006874
6875 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006876 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006877 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006878 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6879 }
6880
6881 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6882 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006883 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006884 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6886 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006887 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6888 if (cpt == null) {
6889 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006890 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6891 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006892 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 }
6894
6895 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006896 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006897 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006898 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006900 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006901 Phone phone = getPhone(subId);
6902 if (phone == null) {
6903 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6905 }
6906 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6907 if (cpt == null) {
6908 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6910 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006911 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006912 }
6913
6914 @Override
6915 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006916 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006917 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6918 }
6919
6920 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006921 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006922 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006923 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006924 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006925 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6926 Phone phone = PhoneFactory.getPhone(phoneId);
6927 if (phone == null) {
6928 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006929 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6931 if (cpt == null) {
6932 continue;
6933 }
6934 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006935 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6936 break;
6937 }
6938 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006939 return result;
Junda Liu29340342014-07-10 15:23:27 -07006940 }
Derek Tan89e89d42014-07-08 17:00:10 -07006941
6942 @Override
Junda Liue64de782015-04-16 17:19:16 -07006943 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006944 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006945 Phone phone = PhoneFactory.getPhone(phoneId);
6946 if (phone == null) {
6947 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006948 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006949 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6950 if (cpt == null) {
6951 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006952 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006953 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006954 }
6955
Amith Yamasani6e118872016-02-19 12:53:51 -08006956 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006957 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006958 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006959 Phone phone = PhoneFactory.getPhone(phoneId);
6960 if (phone == null) {
6961 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006962 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006963 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6964 if (cpt == null) {
6965 return Collections.emptyList();
6966 }
6967 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006968 }
6969
chen xuf7e9fe82019-05-09 19:31:02 -07006970 @Override
6971 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006972 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006973 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006974 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006975 try {
6976 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6977 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6978 }
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006981 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006982 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006983 }
6984
Rambo Wang6812ffb2022-03-15 16:54:17 -07006985 @Override
6986 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6987 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6988
6989 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6990 if (phone == null) {
6991 return null;
6992 }
6993 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6994 if (cpt == null) {
6995 return null;
6996 }
6997 return cpt.getCarrierServicePackageName();
6998 }
6999
Wink Savilleb564aae2014-10-23 10:18:09 -07007000 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007001 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007002 UiccPort port = phone == null ? null : phone.getUiccPort();
7003 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007004 return null;
7005 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007006 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007007 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007008 return null;
7009 }
7010 return iccId;
7011 }
7012
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007013 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007014 public void setCallComposerStatus(int subId, int status) {
7015 enforceModifyPermission();
7016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 Phone phone = getPhone(subId);
7020 if (phone != null) {
7021 Phone defaultPhone = phone.getImsPhone();
7022 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7023 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7024 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007025 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7026 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007027 }
7028 }
Shuo Qian284ae752020-12-22 19:10:14 -08007029 } catch (ImsException e) {
7030 throw new ServiceSpecificException(e.getCode());
7031 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
7036 @Override
7037 public int getCallComposerStatus(int subId) {
7038 enforceReadPrivilegedPermission("getCallComposerStatus");
7039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 Phone phone = getPhone(subId);
7043 if (phone != null) {
7044 Phone defaultPhone = phone.getImsPhone();
7045 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7046 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7047 return imsPhone.getCallComposerStatus();
7048 }
7049 }
7050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
7053 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7054 }
7055
7056 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007057 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7058 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007059 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007060 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 final long identity = Binder.clearCallingIdentity();
7063 try {
7064 final String iccId = getIccId(subId);
7065 final Phone phone = getPhone(subId);
7066 if (phone == null) {
7067 return false;
7068 }
7069 final String subscriberId = phone.getSubscriberId();
7070
7071 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007072 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 + subscriberId + " to " + number);
7074 }
7075
7076 if (TextUtils.isEmpty(iccId)) {
7077 return false;
7078 }
7079
7080 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7081
7082 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7083 if (alphaTag == null) {
7084 editor.remove(alphaTagPrefKey);
7085 } else {
7086 editor.putString(alphaTagPrefKey, alphaTag);
7087 }
7088
7089 // Record both the line number and IMSI for this ICCID, since we need to
7090 // track all merged IMSIs based on line number
7091 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7092 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7093 if (number == null) {
7094 editor.remove(numberPrefKey);
7095 editor.remove(subscriberPrefKey);
7096 } else {
7097 editor.putString(numberPrefKey, number);
7098 editor.putString(subscriberPrefKey, subscriberId);
7099 }
7100
7101 editor.commit();
7102 return true;
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007105 }
Derek Tan7226c842014-07-02 17:42:23 -07007106 }
7107
7108 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007109 public String getLine1NumberForDisplay(int subId, String callingPackage,
7110 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007111 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007113 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007114 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007115 return null;
7116 }
Derek Tan97ebb422014-09-05 16:55:38 -07007117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 final long identity = Binder.clearCallingIdentity();
7119 try {
7120 String iccId = getIccId(subId);
7121 if (iccId != null) {
7122 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7123 if (DBG_MERGE) {
7124 log("getLine1NumberForDisplay returning "
7125 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7126 }
7127 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007128 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7130 return null;
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007133 }
Derek Tan7226c842014-07-02 17:42:23 -07007134 }
7135
7136 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007137 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7138 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007140 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007141 return null;
7142 }
Derek Tan97ebb422014-09-05 16:55:38 -07007143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 String iccId = getIccId(subId);
7147 if (iccId != null) {
7148 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7149 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7150 }
7151 return null;
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007154 }
Derek Tan7226c842014-07-02 17:42:23 -07007155 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007156
7157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7159 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007160 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7161 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007163 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007164 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007165 return null;
7166 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007167
Jordan Liub49b04b2019-05-06 14:45:15 -07007168 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7169 // the process, where TelephonyManager was instantiated.
7170 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007171 final long identity = Binder.clearCallingIdentity();
7172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007173 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 final TelephonyManager tele = TelephonyManager.from(context);
7175 final SubscriptionManager sub = SubscriptionManager.from(context);
7176
7177 // Figure out what subscribers are currently active
7178 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
Jordan Liub49b04b2019-05-06 14:45:15 -07007180 // Only consider subs which match the current subId
7181 // This logic can be simplified. See b/131189269 for progress.
7182 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007183 activeSubscriberIds.add(tele.getSubscriberId(subId));
7184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185
7186 // First pass, find a number override for an active subscriber
7187 String mergeNumber = null;
7188 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7189 for (String key : prefs.keySet()) {
7190 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7191 final String subscriberId = (String) prefs.get(key);
7192 if (activeSubscriberIds.contains(subscriberId)) {
7193 final String iccId = key.substring(
7194 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7195 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7196 mergeNumber = (String) prefs.get(numberKey);
7197 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007198 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 + " for active subscriber " + subscriberId);
7200 }
7201 if (!TextUtils.isEmpty(mergeNumber)) {
7202 break;
7203 }
7204 }
7205 }
7206 }
7207
7208 // Shortcut when no active merged subscribers
7209 if (TextUtils.isEmpty(mergeNumber)) {
7210 return null;
7211 }
7212
7213 // Second pass, find all subscribers under that line override
7214 final ArraySet<String> result = new ArraySet<>();
7215 for (String key : prefs.keySet()) {
7216 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7217 final String number = (String) prefs.get(key);
7218 if (mergeNumber.equals(number)) {
7219 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7220 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7221 final String subscriberId = (String) prefs.get(subscriberKey);
7222 if (!TextUtils.isEmpty(subscriberId)) {
7223 result.add(subscriberId);
7224 }
7225 }
7226 }
7227 }
7228
7229 final String[] resultArray = result.toArray(new String[result.size()]);
7230 Arrays.sort(resultArray);
7231 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007232 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7234 }
7235 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007238 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007239 }
7240
7241 @Override
zoey chen38003472019-12-13 17:16:31 +08007242 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7243 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007244
7245 final long identity = Binder.clearCallingIdentity();
7246 try {
7247 final TelephonyManager telephonyManager = mApp.getSystemService(
7248 TelephonyManager.class);
7249 String subscriberId = telephonyManager.getSubscriberId(subId);
7250 if (subscriberId == null) {
7251 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007252 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007253 + subId);
7254 }
7255 return null;
7256 }
7257
7258 final SubscriptionInfo info = SubscriptionController.getInstance()
7259 .getSubscriptionInfo(subId);
7260 final ParcelUuid groupUuid = info.getGroupUuid();
7261 // If it doesn't belong to any group, return just subscriberId of itself.
7262 if (groupUuid == null) {
7263 return new String[]{subscriberId};
7264 }
7265
7266 // Get all subscriberIds from the group.
7267 final List<String> mergedSubscriberIds = new ArrayList<>();
7268 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007269 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007270 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007271 for (SubscriptionInfo subInfo : groupInfos) {
7272 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7273 if (subscriberId != null) {
7274 mergedSubscriberIds.add(subscriberId);
7275 }
7276 }
7277
7278 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281
7282 }
7283 }
7284
7285 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007286 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007288 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289
7290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 final Phone phone = getPhone(subId);
7293 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007297 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007298
7299 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007300 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007301 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7302 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007303 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7304 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305
7306 final long identity = Binder.clearCallingIdentity();
7307 try {
7308 final Phone phone = getPhone(subId);
7309 if (phone == null) {
7310 return false;
7311 }
7312 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7313 cdmaNonRoamingList);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007316 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007317 }
7318
7319 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007320 @Deprecated
7321 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7322 enforceModifyPermission();
7323
7324 int returnValue = 0;
7325 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007326 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007327 if(result.exception == null) {
7328 if (result.result != null) {
7329 byte[] responseData = (byte[])(result.result);
7330 if(responseData.length > oemResp.length) {
7331 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7332 responseData.length + "bytes. Buffer Size is " +
7333 oemResp.length + "bytes.");
7334 }
7335 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7336 returnValue = responseData.length;
7337 }
7338 } else {
7339 CommandException ex = (CommandException) result.exception;
7340 returnValue = ex.getCommandError().ordinal();
7341 if(returnValue > 0) returnValue *= -1;
7342 }
7343 } catch (RuntimeException e) {
7344 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7345 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7346 if(returnValue > 0) returnValue *= -1;
7347 }
7348
7349 return returnValue;
7350 }
7351
7352 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007353 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007354 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007355 try {
7356 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007357 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007358 mApp, phone.getSubId(), "getRadioAccessFamily");
7359 } catch (SecurityException e) {
7360 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7361 throw e;
7362 }
chen xub97461a2018-10-26 14:17:57 -07007363 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007364 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007365 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 final long identity = Binder.clearCallingIdentity();
7368 try {
chen xub97461a2018-10-26 14:17:57 -07007369 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007370 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007371 mApp, phone.getSubId(), "getRadioAccessFamily");
7372 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
chen xub97461a2018-10-26 14:17:57 -07007376 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007377 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007378
7379 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007380 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007381 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007382 try {
7383 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7384 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007385 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007386 }
7387 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007388 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007389 }
7390 RoleManager rm = mApp.getSystemService(RoleManager.class);
7391 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7392 if (!dialerRoleHolders.contains(callingPackage)) {
7393 throw new SecurityException("App must be the dialer role holder to"
7394 + " upload a call composer pic");
7395 }
7396
7397 Executors.newSingleThreadExecutor().execute(() -> {
7398 ByteArrayOutputStream output = new ByteArrayOutputStream(
7399 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7400 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7401 boolean readUntilEnd = false;
7402 int totalBytesRead = 0;
7403 byte[] buffer = new byte[16 * 1024];
7404 while (true) {
7405 int numRead;
7406 try {
7407 numRead = input.read(buffer);
7408 } catch (IOException e) {
7409 try {
7410 fd.checkError();
7411 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7412 null);
7413 } catch (IOException e1) {
7414 // This means that the other side closed explicitly with an error. If this
7415 // happens, log and ignore.
7416 loge("Remote end of call composer picture pipe closed: " + e1);
7417 }
7418 break;
7419 }
7420 if (numRead == -1) {
7421 readUntilEnd = true;
7422 break;
7423 }
7424 totalBytesRead += numRead;
7425 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7426 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7427 try {
7428 input.close();
7429 } catch (IOException e) {
7430 // ignore
7431 }
7432 break;
7433 }
7434 output.write(buffer, 0, numRead);
7435 }
7436 // Generally, the remote end will close the file descriptors. The only case where we
7437 // close is above, where the picture size is too big.
7438
7439 try {
7440 fd.checkError();
7441 } catch (IOException e) {
7442 loge("Remote end for call composer closed with an error: " + e);
7443 return;
7444 }
7445
Hall Liuaa4211e2021-01-20 15:43:39 -08007446 if (!readUntilEnd) {
7447 loge("Did not finish reading entire image; aborting");
7448 return;
7449 }
Hall Liu82694d52020-12-11 18:22:04 -08007450
Hall Liuaa4211e2021-01-20 15:43:39 -08007451 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7452 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7453 new CallComposerPictureTransfer.Factory() {},
7454 imageData,
7455 (result) -> {
7456 if (result.first != null) {
7457 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7458 Bundle outputResult = new Bundle();
7459 outputResult.putParcelable(
7460 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7461 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7462 outputResult);
7463 } else {
7464 callback.send(result.second, null);
7465 }
7466 }
7467 );
Hall Liu82694d52020-12-11 18:22:04 -08007468 });
7469 }
7470
7471 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007472 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007473 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475
7476 final long identity = Binder.clearCallingIdentity();
7477 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 ImsManager.getInstance(defaultPhone.getContext(),
7479 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007483 }
7484
7485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007486 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7489 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007490 return false;
7491 }
Svet Ganovb320e182015-04-16 12:30:10 -07007492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 final long identity = Binder.clearCallingIdentity();
7494 try {
7495 // Check the user preference and the system-level IMS setting. Even if the user has
7496 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7497 // In the long run, we may instead need to check if there exists a connection service
7498 // which can support video calling.
7499 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 return imsManager.isVtEnabledByPlatform()
7502 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7503 && imsManager.isVtEnabledByUser();
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007507 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007508
Andrew Leea1239f22015-03-02 17:44:07 -08007509 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007510 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7511 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007513 mApp, subId, callingPackage, callingFeatureId,
7514 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 return false;
7516 }
7517
7518 final long identity = Binder.clearCallingIdentity();
7519 try {
7520 CarrierConfigManager configManager =
7521 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007522 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Andrew Leea1239f22015-03-02 17:44:07 -08007527 }
7528
7529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007532 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 return false;
7534 }
7535
7536 final long identity = Binder.clearCallingIdentity();
7537 try {
7538 CarrierConfigManager configManager =
7539 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
Andrew Leea1239f22015-03-02 17:44:07 -08007545 }
7546
Andrew Lee9431b832015-03-09 18:46:45 -07007547 @Override
7548 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007549 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007550 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007551 }
7552
7553 @Override
7554 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007555 final long identity = Binder.clearCallingIdentity();
7556 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
Andrew Lee9431b832015-03-09 18:46:45 -07007561 }
7562
Hall Liuf6668912018-10-31 17:05:23 -07007563 /**
7564 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7565 * support for the feature and device firmware support.
7566 *
7567 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7568 */
7569 @Override
7570 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007572 final Phone phone = getPhone(subscriptionId);
7573 if (phone == null) {
7574 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7575 return false;
7576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7580 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 return isCarrierSupported && isDeviceSupported;
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
Hall Liu98187582018-01-22 19:15:32 -08007586 }
7587
Hall Liuf6668912018-10-31 17:05:23 -07007588 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007589 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7590 * RTT setting, will return true if the device and carrier both support RTT.
7591 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007592 */
7593 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 final long identity = Binder.clearCallingIdentity();
7595 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007596 boolean isRttSupported = isRttSupported(subscriptionId);
7597 boolean isUserRttSettingOn = Settings.Secure.getInt(
7598 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7599 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7600 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7601 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 } finally {
7603 Binder.restoreCallingIdentity(identity);
7604 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007605 }
7606
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007607 @Deprecated
7608 @Override
7609 public String getDeviceId(String callingPackage) {
7610 return getDeviceIdWithFeature(callingPackage, null);
7611 }
7612
Sanket Padawe7310cc72015-01-14 09:53:20 -08007613 /**
7614 * Returns the unique device ID of phone, for example, the IMEI for
7615 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7616 *
7617 * <p>Requires Permission:
7618 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7619 */
7620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007621 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007622 try {
7623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7624 } catch (SecurityException se) {
7625 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7626 throw new SecurityException("Package " + callingPackage + " does not belong to "
7627 + Binder.getCallingUid());
7628 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007629 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007630 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007631 return null;
7632 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007633 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007634 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007635 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007636 return null;
7637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638
7639 final long identity = Binder.clearCallingIdentity();
7640 try {
7641 return phone.getDeviceId();
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007645 }
7646
Ping Sunc67b7c22016-03-02 19:16:45 +08007647 /**
7648 * {@hide}
7649 * Returns the IMS Registration Status on a particular subid
7650 *
7651 * @param subId
7652 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007653 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007654 Phone phone = getPhone(subId);
7655 if (phone != null) {
7656 return phone.isImsRegistered();
7657 } else {
7658 return false;
7659 }
7660 }
7661
Santos Cordon7a1885b2015-02-03 11:15:19 -08007662 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007663 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007664 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007666 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007667 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7668 }
7669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
7675 }
7676
7677 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007678 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007679 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007680 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007681 mApp,
7682 subscriptionId,
7683 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 Phone phone = getPhone(subscriptionId);
7687 if (phone == null) {
7688 return null;
7689 }
7690 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
7695
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007696 /**
7697 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007698 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007699 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 final long identity = Binder.clearCallingIdentity();
7701 try {
7702 Phone phone = getPhone(subId);
7703 if (phone != null) {
7704 return phone.isWifiCallingEnabled();
7705 } else {
7706 return false;
7707 }
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007710 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007711 }
7712
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007713 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007714 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007715 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007716 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 Phone phone = getPhone(subId);
7720 if (phone != null) {
7721 return phone.isVideoEnabled();
7722 } else {
7723 return false;
7724 }
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007727 }
7728 }
7729
7730 /**
7731 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7732 * defined in {@link ImsRegistrationImplBase}.
7733 */
7734 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 Phone phone = getPhone(subId);
7738 if (phone != null) {
7739 return phone.getImsRegistrationTech();
7740 } else {
7741 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7742 }
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007745 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007746 }
7747
Stuart Scott8eef64f2015-04-08 15:13:54 -07007748 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007749 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007750 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007751 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7752 return;
7753 }
Kai Shif70f46f2021-03-03 13:59:46 -08007754 Phone defaultPhone = getDefaultPhone();
7755 if (defaultPhone != null) {
7756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7757 mApp, getDefaultPhone().getSubId(), "factoryReset");
7758 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007759 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007760
Svet Ganovcc087f82015-05-12 20:35:54 -07007761 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007762 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7763 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007764 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007765 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007766 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007767 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007768 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007769 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007770 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007771 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007772 // There has been issues when Sms raw table somehow stores orphan
7773 // fragments. They lead to garbled message when new fragments come
7774 // in and combined with those stale ones. In case this happens again,
7775 // user can reset all network settings which will clean up this table.
7776 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007777 // Clean up IMS settings as well here.
7778 int slotId = getSlotIndex(subId);
7779 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7780 ImsManager.getInstance(mApp, slotId).factoryReset();
7781 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007782
Kai Shif70f46f2021-03-03 13:59:46 -08007783 if (defaultPhone == null) {
7784 return;
7785 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007786 // Erase modem config if erase modem on network setting is enabled.
7787 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7788 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7789 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007790 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007791 }
Kai Shif70f46f2021-03-03 13:59:46 -08007792
7793 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007794 } finally {
7795 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007796 }
7797 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007798
SongFerngWangfd89b102021-05-27 22:44:54 +08007799 @VisibleForTesting
7800 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7801 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7802 return;
7803 }
7804 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7805 RILConstants.PREFERRED_NETWORK_MODE);
7806 SubscriptionManager.setSubscriptionProperty(subId,
7807 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7808 "user=" + defaultNetworkType);
7809 phone.loadAllowedNetworksFromSubscriptionDatabase();
7810 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7811 defaultNetworkType, null);
7812 }
7813
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007814 private void cleanUpSmsRawTable(Context context) {
7815 ContentResolver resolver = context.getContentResolver();
7816 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7817 resolver.delete(uri, null, null);
7818 }
7819
Narayan Kamath1c496c22015-04-16 14:40:19 +01007820 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007821 public String getSimLocaleForSubscriber(int subId) {
7822 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7823 final Phone phone = getPhone(subId);
7824 if (phone == null) {
7825 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007826 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 final long identity = Binder.clearCallingIdentity();
7829 try {
chen xu5d3637b2019-01-21 23:31:38 -08007830 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007831 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007832 if (info == null) {
7833 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7834 return null;
7835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 // Try and fetch the locale from the carrier properties or from the SIM language
7837 // preferences (EF-PL and EF-LI)...
7838 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007840 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7841 if (localeFromDefaultSim != null) {
7842 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7843 if (DBG) log("Using locale from subId: " + subId + " locale: "
7844 + localeFromDefaultSim);
tom hsu0b59d292022-09-29 23:49:21 +08007845 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007846 } else {
7847 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 }
7849 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851 // The SIM language preferences only store a language (e.g. fr = French), not an
7852 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7853 // the SIM and carrier preferences does not include a country we add the country
7854 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007855 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007857 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu0b59d292022-09-29 23:49:21 +08007858 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 }
7860
7861 if (DBG) log("No locale found - returning null");
7862 return null;
7863 } finally {
7864 Binder.restoreCallingIdentity(identity);
7865 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007866 }
7867
tom hsu0b59d292022-09-29 23:49:21 +08007868 @VisibleForTesting
7869 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
7870 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
7871 getDefaultPhone().getContext());
7872 for (String localeTag : supportedLocale) {
7873 if (LocaleList.matchesLanguageAndScript(
7874 inputLocale, Locale.forLanguageTag(localeTag))
7875 && inputLocale.getCountry().equals(
7876 Locale.forLanguageTag(localeTag).getCountry())) {
7877 return localeTag;
7878 }
7879 }
7880 return inputLocale.toLanguageTag();
7881 }
7882
Narayan Kamath1c496c22015-04-16 14:40:19 +01007883 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007884 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007885 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007886 }
7887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 /**
7889 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7890 */
7891 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007892 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007893 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007894 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007895
Gary Jian3aa9a762022-01-24 16:41:19 +08007896 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7897 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007898
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007899 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007900 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7901 * representing the state of the modem.
7902 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007903 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7904 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007905 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007906 */
7907 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007908 public void requestModemActivityInfo(ResultReceiver result) {
7909 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007914 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 } finally {
7916 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007917 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007918 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007919
Siddharth Rayb8114062018-06-17 15:02:38 -07007920 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7921 // less than total activity duration.
7922 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7923 if (info == null) {
7924 return false;
7925 }
7926 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007927 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7928 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7929
Siddharth Rayb8114062018-06-17 15:02:38 -07007930 return (info.isValid()
7931 && (info.getSleepTimeMillis() <= activityDurationMs)
7932 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007933 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007934 && (totalTxTimeMs <= activityDurationMs));
7935 }
7936
Gary Jian3aa9a762022-01-24 16:41:19 +08007937 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7938 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7939 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7940 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7941
7942 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7943 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7944 }
7945
7946 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7947 mLastModemActivityInfo.setReceiveTimeMillis(
7948 rat,
7949 freq,
7950 info.getReceiveTimeMillis(rat, freq)
7951 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7952 }
7953
7954 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7955 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7956 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7957 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7958
7959 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7960 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7961 }
7962 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7963 mLastModemActivityInfo.setReceiveTimeMillis(
7964 rat,
7965 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7966 }
7967
7968 /**
7969 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7970 * @param info recent ModemActivityInfo
7971 */
7972 private void mergeModemActivityInfo(ModemActivityInfo info) {
7973 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7974 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7975 boolean matched;
7976 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7977 matched = false;
7978 int rat = info.getSpecificInfoRat(i);
7979 int freq = info.getSpecificInfoFrequencyRange(i);
7980 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7981 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7982 //if it already exists
7983 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7984 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7985 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7986 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7987 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7988 updateLastModemActivityInfo(info, rat, freq);
7989 matched = true;
7990 }
7991 } else {
7992 updateLastModemActivityInfo(info, rat);
7993 matched = true;
7994 }
7995 }
7996 }
7997
7998 if (!matched) {
7999 mDeltaSpecificInfo =
8000 new ActivityStatsTechSpecificInfo(
8001 rat,
8002 freq,
8003 info.getTransmitTimeMillis(rat, freq),
8004 (int) info.getReceiveTimeMillis(rat, freq));
8005 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8006 }
8007 }
8008 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8009 mLastModemActivitySpecificInfo =
8010 new ActivityStatsTechSpecificInfo[merged.size()];
8011 merged.toArray(mLastModemActivitySpecificInfo);
8012
8013 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8014 mLastModemActivityInfo.setSleepTimeMillis(
8015 info.getSleepTimeMillis()
8016 + mLastModemActivityInfo.getSleepTimeMillis());
8017 mLastModemActivityInfo.setIdleTimeMillis(
8018 info.getIdleTimeMillis()
8019 + mLastModemActivityInfo.getIdleTimeMillis());
8020 }
8021
Jack Yu85bd38a2015-11-09 11:34:32 -08008022 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008023 * Returns the service state information on specified subscription.
8024 */
8025 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008026 public ServiceState getServiceStateForSubscriber(int subId,
8027 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8028 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008030 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008031 return null;
8032 }
8033
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008034 boolean hasFinePermission = false;
8035 boolean hasCoarsePermission = false;
8036 if (!renounceFineLocationAccess) {
8037 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8038 LocationAccessPolicy.checkLocationPermission(mApp,
8039 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8040 .setCallingPackage(callingPackage)
8041 .setCallingFeatureId(callingFeatureId)
8042 .setCallingPid(Binder.getCallingPid())
8043 .setCallingUid(Binder.getCallingUid())
8044 .setMethod("getServiceStateForSubscriber")
8045 .setLogAsInfo(true)
8046 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8047 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8048 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8049 .build());
8050 hasFinePermission =
8051 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8052 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008053
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008054 if (!renounceCoarseLocationAccess) {
8055 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8056 LocationAccessPolicy.checkLocationPermission(mApp,
8057 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8058 .setCallingPackage(callingPackage)
8059 .setCallingFeatureId(callingFeatureId)
8060 .setCallingPid(Binder.getCallingPid())
8061 .setCallingUid(Binder.getCallingUid())
8062 .setMethod("getServiceStateForSubscriber")
8063 .setLogAsInfo(true)
8064 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8065 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8066 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8067 .build());
8068 hasCoarsePermission =
8069 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8070 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008071
Jack Yu479f40e2020-10-27 21:29:25 -07008072 final Phone phone = getPhone(subId);
8073 if (phone == null) {
8074 return null;
8075 }
8076
Jordan Liu0f2bc442020-11-18 16:47:37 -08008077 final long identity = Binder.clearCallingIdentity();
8078
Jack Yu479f40e2020-10-27 21:29:25 -07008079 boolean isCallingPackageDataService = phone.getDataServicePackages()
8080 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008082 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8083 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8084 Rlog.d(LOG_TAG,
8085 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8086 return null;
8087 }
8088
Hall Liuf19c44f2018-11-27 14:38:17 -08008089 ServiceState ss = phone.getServiceState();
8090
8091 // Scrub out the location info in ServiceState depending on what level of access
8092 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008093 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008094 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8095 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008096 } finally {
8097 Binder.restoreCallingIdentity(identity);
8098 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008099 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008100
8101 /**
8102 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8103 *
8104 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8105 * voicemail ringtone.
8106 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8107 * PhoneAccount.
8108 */
8109 @Override
8110 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008111 final long identity = Binder.clearCallingIdentity();
8112 try {
8113 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8114 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008115 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8119 } finally {
8120 Binder.restoreCallingIdentity(identity);
8121 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008122 }
8123
8124 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008125 * Sets the per-account voicemail ringtone.
8126 *
8127 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8128 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8129 *
8130 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8131 * voicemail ringtone.
8132 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8133 * PhoneAccount.
8134 */
8135 @Override
8136 public void setVoicemailRingtoneUri(String callingPackage,
8137 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008138 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008139 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008140 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8141 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8143 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8144 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146
8147 final long identity = Binder.clearCallingIdentity();
8148 try {
8149 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8150 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008151 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008152 }
8153 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8154 } finally {
8155 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008156 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008157 }
8158
8159 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008160 * Returns whether vibration is set for voicemail notification in Phone settings.
8161 *
8162 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8163 * voicemail vibration setting.
8164 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8165 */
8166 @Override
8167 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8171 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008172 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008179 }
8180
Youhan Wange64578a2016-05-02 15:32:42 -07008181 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008182 * Sets the per-account voicemail vibration.
8183 *
8184 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8185 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8186 *
8187 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8188 * voicemail vibration setting.
8189 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8190 * specific PhoneAccount.
8191 */
8192 @Override
8193 public void setVoicemailVibrationEnabled(String callingPackage,
8194 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008195 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008196 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008197 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8198 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8200 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8201 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008202 }
8203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8207 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008208 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008209 }
8210 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8211 } finally {
8212 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008213 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008214 }
8215
8216 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008217 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8218 *
8219 * @throws SecurityException if the caller does not have the required permission
8220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008221 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008222 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008223 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008224 }
8225
8226 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008227 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8228 * permission.
8229 *
8230 * @throws SecurityException if the caller does not have the required permission
8231 */
8232 private void enforceSendSmsPermission() {
8233 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8234 }
8235
8236 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008237 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008238 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008239 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008240 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008241 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 final long identity = Binder.clearCallingIdentity();
8243 try {
8244 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008245 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 if (componentName == null) {
8247 throw new SecurityException(
8248 "Caller not current active visual voicemail package[null]");
8249 }
8250 String vvmPackage = componentName.getPackageName();
8251 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008252 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 }
8254 } finally {
8255 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008256 }
8257 }
8258
8259 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008260 * Return the application ID for the app type.
8261 *
8262 * @param subId the subscription ID that this request applies to.
8263 * @param appType the uicc app type.
8264 * @return Application ID for specificied app type, or null if no uicc.
8265 */
8266 @Override
8267 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008268 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008269 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
8271 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008272 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 if (phone == null) {
8274 return null;
8275 }
8276 String aid = null;
8277 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008278 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279 .getApplicationByType(appType).getAid();
8280 } catch (Exception e) {
8281 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8282 }
8283 return aid;
8284 } finally {
8285 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008286 }
Youhan Wange64578a2016-05-02 15:32:42 -07008287 }
8288
Youhan Wang4001d252016-05-11 10:29:41 -07008289 /**
8290 * Return the Electronic Serial Number.
8291 *
8292 * @param subId the subscription ID that this request applies to.
8293 * @return ESN or null if error.
8294 */
8295 @Override
8296 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008297 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008298 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299
8300 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008301 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008302 if (phone == null) {
8303 return null;
8304 }
8305 String esn = null;
8306 try {
8307 esn = phone.getEsn();
8308 } catch (Exception e) {
8309 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8310 }
8311 return esn;
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008314 }
Youhan Wang4001d252016-05-11 10:29:41 -07008315 }
8316
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008317 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008318 * Return the Preferred Roaming List Version.
8319 *
8320 * @param subId the subscription ID that this request applies to.
8321 * @return PRLVersion or null if error.
8322 */
8323 @Override
8324 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008325 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008326 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008327
8328 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008329 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 if (phone == null) {
8331 return null;
8332 }
8333 String cdmaPrlVersion = null;
8334 try {
8335 cdmaPrlVersion = phone.getCdmaPrlVersion();
8336 } catch (Exception e) {
8337 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8338 }
8339 return cdmaPrlVersion;
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008342 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008343 }
8344
8345 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008346 * Get snapshot of Telephony histograms
8347 * @return List of Telephony histograms
8348 * @hide
8349 */
8350 @Override
8351 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008352 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8353 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008354
8355 final long identity = Binder.clearCallingIdentity();
8356 try {
8357 return RIL.getTelephonyRILTimingHistograms();
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008361 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008362
8363 /**
8364 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008365 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8366 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008367 * Require system privileges. In the future we may add this to carrier APIs.
8368 *
Michele Berionne482f8202018-11-27 18:57:59 -08008369 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008370 */
8371 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008372 @TelephonyManager.SetCarrierRestrictionResult
8373 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008374 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008376
Michele Berionne482f8202018-11-27 18:57:59 -08008377 if (carrierRestrictionRules == null) {
8378 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008379 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008381 final long identity = Binder.clearCallingIdentity();
8382 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008383 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008384 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385 } finally {
8386 Binder.restoreCallingIdentity(identity);
8387 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008388 }
8389
8390 /**
8391 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008392 * Get the allowed carrier list and the excluded carrier list, including the priority between
8393 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008394 * Require system privileges. In the future we may add this to carrier APIs.
8395 *
Michele Berionne482f8202018-11-27 18:57:59 -08008396 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008397 */
8398 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008399 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008400 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008402
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008405 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8406 if (response instanceof CarrierRestrictionRules) {
8407 return (CarrierRestrictionRules) response;
8408 }
8409 // Response is an Exception of some kind,
8410 // which is signalled to the user as a NULL retval
8411 return null;
8412 } catch (Exception e) {
8413 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8414 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008418 }
8419
fionaxu59545b42016-05-25 15:53:37 -07008420 /**
fionaxu59545b42016-05-25 15:53:37 -07008421 * Action set from carrier signalling broadcast receivers to enable/disable radio
8422 * @param subId the subscription ID that this action applies to.
8423 * @param enabled control enable or disable radio.
8424 * {@hide}
8425 */
8426 @Override
8427 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8428 enforceModifyPermission();
8429 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430
8431 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008432 if (phone == null) {
8433 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8434 return;
8435 }
8436 try {
8437 phone.carrierActionSetRadioEnabled(enabled);
8438 } catch (Exception e) {
8439 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440 } finally {
8441 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008442 }
8443 }
8444
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008445 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008446 * Enable or disable Voice over NR (VoNR)
8447 * @param subId the subscription ID that this action applies to.
8448 * @param enabled enable or disable VoNR.
8449 * @return operation result.
8450 */
8451 @Override
8452 public int setVoNrEnabled(int subId, boolean enabled) {
8453 enforceModifyPermission();
8454 final Phone phone = getPhone(subId);
8455
8456 final long identity = Binder.clearCallingIdentity();
8457 if (phone == null) {
8458 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8459 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8460 }
8461
8462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8463 try {
8464 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8465 workSource);
8466 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008467
8468 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8469 if (DBG) {
8470 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8471 }
8472 SubscriptionManager.setSubscriptionProperty(
8473 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8474 (enabled ? "1" : "0"));
8475 }
8476
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008477 return result;
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
8481 }
8482
8483 /**
8484 * Is voice over NR enabled
8485 * @return true if VoNR is enabled else false
8486 */
8487 @Override
8488 public boolean isVoNrEnabled(int subId) {
8489 enforceReadPrivilegedPermission("isVoNrEnabled");
8490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8494 null, subId, workSource);
8495 if (DBG) log("isVoNrEnabled: " + isEnabled);
8496 return isEnabled;
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
8502 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008503 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8504 * network status based on which carrier apps could apply actions accordingly,
8505 * enable/disable default url handler for example.
8506 *
8507 * @param subId the subscription ID that this action applies to.
8508 * @param report control start/stop reporting the default network status.
8509 * {@hide}
8510 */
8511 @Override
8512 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8513 enforceModifyPermission();
8514 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515
8516 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008517 if (phone == null) {
8518 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8519 return;
8520 }
8521 try {
8522 phone.carrierActionReportDefaultNetworkStatus(report);
8523 } catch (Exception e) {
8524 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 } finally {
8526 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008527 }
8528 }
8529
8530 /**
fionaxud9622282017-07-17 17:51:30 -07008531 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8532 * @param subId the subscription ID that this action applies to.
8533 * {@hide}
8534 */
8535 @Override
8536 public void carrierActionResetAll(int subId) {
8537 enforceModifyPermission();
8538 final Phone phone = getPhone(subId);
8539 if (phone == null) {
8540 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8541 return;
8542 }
8543 try {
8544 phone.carrierActionResetAll();
8545 } catch (Exception e) {
8546 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8547 }
8548 }
8549
8550 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008551 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8552 * bug report is being generated.
8553 */
8554 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008555 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008556 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8557 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008558 writer.println("Permission Denial: can't dump Phone from pid="
8559 + Binder.getCallingPid()
8560 + ", uid=" + Binder.getCallingUid()
8561 + "without permission "
8562 + android.Manifest.permission.DUMP);
8563 return;
8564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008566 }
Jack Yueb89b242016-06-22 13:27:47 -07008567
Brad Ebingerdac2f002018-04-03 15:17:52 -07008568 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008569 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8570 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8571 @NonNull String[] args) {
8572 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8573 this, in.getFileDescriptor(), out.getFileDescriptor(),
8574 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008575 }
8576
Jack Yueb89b242016-06-22 13:27:47 -07008577 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008578 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008579 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008580 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008581 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008582 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008583 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008584 */
8585 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008586 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008587 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008588 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8589 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8590 try {
8591 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008592 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008593 } catch (SecurityException se) {
8594 enforceModifyPermission();
8595 }
8596 } else {
8597 enforceModifyPermission();
8598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008599
8600 final long identity = Binder.clearCallingIdentity();
8601 try {
8602 Phone phone = getPhone(subId);
8603 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008604 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8605 phone.carrierActionSetMeteredApnsEnabled(enabled);
8606 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008607 phone.getDataSettingsManager().setDataEnabled(
8608 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008610 }
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008613 }
8614 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008615
8616 /**
8617 * Get Client request stats
8618 * @return List of Client Request Stats
8619 * @hide
8620 */
8621 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8623 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008625 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008626 return null;
8627 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008628 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 if (phone != null) {
8633 return phone.getClientRequestStats();
8634 }
8635
8636 return null;
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008640 }
8641
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008642 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008643 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008644 if (uid == Process.ROOT_UID && packageName == null) {
8645 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8646 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8647 // exception. ROOT_UID seems not to have a valid package name returned by
8648 // PackageManager, so just fake it here to avoid issues when running telephony shell
8649 // commands that plumb through the RIL as root, like so:
8650 // $ adb root
8651 // $ adb shell cmd phone ...
8652 packageName = "root";
8653 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008654 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008655 }
Jack Yueb4124c2017-02-16 15:32:43 -08008656
8657 /**
Grace Chen70990072017-03-24 17:21:30 -07008658 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008659 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008660 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008661 * @param state State of SIM (power down, power up, pass through)
8662 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8663 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8664 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008665 *
8666 **/
8667 @Override
Grace Chen70990072017-03-24 17:21:30 -07008668 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008669 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008670 Phone phone = PhoneFactory.getPhone(slotIndex);
8671
vagdeviaf9a5b92018-08-15 16:01:53 -07008672 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008674 final long identity = Binder.clearCallingIdentity();
8675 try {
8676 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008677 phone.setSimPowerState(state, null, workSource);
8678 }
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
8682 }
8683
8684 /**
8685 * Set SIM card power state.
8686 *
8687 * @param slotIndex SIM slot id.
8688 * @param state State of SIM (power down, power up, pass through)
8689 * @param callback callback to trigger after success or failure
8690 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8691 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8692 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8693 *
8694 **/
8695 @Override
8696 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8697 IIntegerConsumer callback) {
8698 enforceModifyPermission();
8699 Phone phone = PhoneFactory.getPhone(slotIndex);
8700
8701 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8702
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
8705 if (phone != null) {
8706 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8707 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008708 }
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008711 }
8712 }
Shuo Qiandd210312017-04-12 22:11:33 +00008713
Tyler Gunn65d45c22017-06-05 11:22:26 -07008714 private boolean isUssdApiAllowed(int subId) {
8715 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008716 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008717 if (configManager == null) {
8718 return false;
8719 }
8720 PersistableBundle pb = configManager.getConfigForSubId(subId);
8721 if (pb == null) {
8722 return false;
8723 }
8724 return pb.getBoolean(
8725 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8726 }
8727
Shuo Qiandd210312017-04-12 22:11:33 +00008728 /**
8729 * Check if phone is in emergency callback mode
8730 * @return true if phone is in emergency callback mode
8731 * @param subId sub id
8732 */
goneil9c5f4872017-12-05 14:07:56 -08008733 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008734 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008735 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008737
8738 final long identity = Binder.clearCallingIdentity();
8739 try {
8740 if (phone != null) {
8741 return phone.isInEcm();
8742 } else {
8743 return false;
8744 }
8745 } finally {
8746 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008747 }
8748 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008749
8750 /**
8751 * Get the current signal strength information for the given subscription.
8752 * Because this information is not updated when the device is in a low power state
8753 * it should not be relied-upon to be current.
8754 * @param subId Subscription index
8755 * @return the most recent cached signal strength info from the modem
8756 */
8757 @Override
8758 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008759 final long identity = Binder.clearCallingIdentity();
8760 try {
8761 Phone p = getPhone(subId);
8762 if (p == null) {
8763 return null;
8764 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008766 return p.getSignalStrength();
8767 } finally {
8768 Binder.restoreCallingIdentity(identity);
8769 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008770 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008771
Pengquan Meng77b7f132018-08-22 14:49:57 -07008772 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008773 * Get the current modem radio state for the given slot.
8774 * @param slotIndex slot index.
8775 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008776 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008777 * @return the current radio power state from the modem
8778 */
8779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008780 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008781 Phone phone = PhoneFactory.getPhone(slotIndex);
8782 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8784 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008785 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8786 }
8787
8788 final long identity = Binder.clearCallingIdentity();
8789 try {
8790 return phone.getRadioPowerState();
8791 } finally {
8792 Binder.restoreCallingIdentity(identity);
8793 }
8794 }
8795 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8796 }
8797
8798 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008799 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8800 *
8801 * <p>Requires one of the following permissions:
8802 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008803 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008804 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8805 * privileges.
8806 *
8807 * @param subId subscription id
8808 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8809 * {@code false}.
8810 */
8811 @Override
8812 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008813 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008814 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008815 try {
8816 mApp.enforceCallingOrSelfPermission(
8817 android.Manifest.permission.ACCESS_NETWORK_STATE,
8818 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008819 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008820 mApp.enforceCallingOrSelfPermission(
8821 permission.READ_BASIC_PHONE_STATE, functionName);
8822 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008823 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008824 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008825 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008826 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008827
Pengquan Menga1bb6272018-09-06 09:59:22 -07008828 boolean isEnabled = false;
8829 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008830 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008831 Phone phone = getPhone(subId);
8832 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008833 } finally {
8834 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008835 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008836 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008837 }
8838
8839
8840 /**
8841 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8842 *
8843 * <p> Requires permission:
8844 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8845 * privileges.
8846 *
8847 * @param subId subscription id
8848 * @param isEnabled {@code true} means enable, {@code false} means disable.
8849 */
8850 @Override
8851 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8853 mApp, subId, "setDataRoamingEnabled");
8854
Pengquan Menga1bb6272018-09-06 09:59:22 -07008855 final long identity = Binder.clearCallingIdentity();
8856 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008857 Phone phone = getPhone(subId);
8858 if (phone != null) {
8859 phone.setDataRoamingEnabled(isEnabled);
8860 }
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008863 }
8864 }
8865
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008866 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008867 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008868 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008869 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008870 mApp, subId, "isManualNetworkSelectionAllowed");
8871
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008872 boolean isAllowed = true;
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008875 Phone phone = getPhone(subId);
8876 if (phone != null) {
8877 isAllowed = phone.isCspPlmnEnabled();
8878 }
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 return isAllowed;
8883 }
8884
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008885 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8886 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008887 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008888 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008889 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008890 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8891 if (phone == null) {
8892 return false;
8893 }
8894 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8895 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8896 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008897 }
8898
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008899 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008900 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008901 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008902 mApp.getSystemService(AppOpsManager.class)
8903 .checkPackage(Binder.getCallingUid(), callingPackage);
8904
Jordan Liu1e142fc2019-04-22 15:10:43 -07008905 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008906 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008907 try {
8908 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008909 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008910 } catch (SecurityException e) {
8911 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8912 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008913 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008914 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008915 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008916 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008917 }
sandeepjsb6c87872021-09-27 15:34:44 +00008918 // checking compatibility, if calling app's target SDK is T and beyond.
8919 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8920 Binder.getCallingUid())) {
8921 isIccIdAccessRestricted = true;
8922 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008923 final long identity = Binder.clearCallingIdentity();
8924 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008925 UiccController uiccController = UiccController.getInstance();
8926 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008927 if (hasReadPermission) {
8928 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008929 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008930
8931 // Remove private info if the caller doesn't have access
8932 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8933 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008934 //setting the value after compatibility check
8935 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008936 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8937 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008938 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008939 if (card == null) {
8940 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008941 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008942 continue;
8943 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008944 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8945 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008946 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008947 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008948 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008949 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8950 for (UiccPortInfo portInfo : portInfos) {
8951 UiccPort port = uiccController.getUiccPortForSlot(
8952 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8953 if (port == null) {
8954 // assume no access if port is null
8955 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8956 continue;
8957 }
8958 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8959 uiccPortInfos.add(portInfo);
8960 } else {
8961 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8962 }
8963 }
8964 filteredInfos.add(new UiccCardInfo(
8965 cardInfo.isEuicc(),
8966 cardInfo.getCardId(),
8967 null,
8968 cardInfo.getPhysicalSlotIndex(),
8969 cardInfo.isRemovable(),
8970 cardInfo.isMultipleEnabledProfilesSupported(),
8971 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008972 }
8973 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
8978
sandeepjsb6c87872021-09-27 15:34:44 +00008979 /**
8980 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8981 * generally private and require carrier privileges to view.
8982 *
8983 * @hide
8984 */
8985 @NonNull
8986 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8987 List<UiccPortInfo> portinfo = new ArrayList<>();
8988 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8989 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8990 }
8991 return new UiccCardInfo(
8992 cardInfo.isEuicc(),
8993 cardInfo.getCardId(),
8994 null,
8995 cardInfo.getPhysicalSlotIndex(),
8996 cardInfo.isRemovable(),
8997 cardInfo.isMultipleEnabledProfilesSupported(),
8998 portinfo
8999 );
9000 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009001
sandeepjsb6c87872021-09-27 15:34:44 +00009002 /**
9003 * @hide
9004 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9005 * These values are generally private and require carrier privileges to view.
9006 */
9007 @NonNull
9008 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9009 return new UiccPortInfo(
9010 UiccPortInfo.ICCID_REDACTED,
9011 portInfo.getPortIndex(),
9012 portInfo.getLogicalSlotIndex(),
9013 portInfo.isActive()
9014 );
9015 }
9016 @Override
9017 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009018 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009019 mApp.getSystemService(AppOpsManager.class)
9020 .checkPackage(Binder.getCallingUid(), callingPackage);
9021
sandeepjsb6c87872021-09-27 15:34:44 +00009022 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009023
Aman Guptaf3c90b32022-03-17 04:54:16 +00009024 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9025 // we are reading iccId which is PII data.
9026 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009027
9028 // checking compatibility, if calling app's target SDK is T and beyond.
9029 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9030 Binder.getCallingUid())) {
9031 isLogicalSlotAccessRestricted = true;
9032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009036 if (slots == null || slots.length == 0) {
9037 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009038 return null;
9039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009040 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9041 for (int i = 0; i < slots.length; i++) {
9042 UiccSlot slot = slots[i];
9043 if (slot == null) {
9044 continue;
9045 }
9046
Jordan Liu7be7e652019-05-06 18:55:02 +00009047 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009048 UiccCard card = slot.getUiccCard();
9049 if (card != null) {
9050 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009051 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009052 cardId = slot.getEid();
9053 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009054 // If cardId is null, use iccId of default port as cardId.
9055 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 }
9058
Jordan Liu857451f2019-05-09 16:35:35 -07009059 if (cardId != null) {
9060 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9061 // if cardId is an EID, it's all digits so this is fine
9062 cardId = IccUtils.stripTrailingFs(cardId);
9063 }
9064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009065 int cardState = 0;
9066 switch (slot.getCardState()) {
9067 case CARDSTATE_ABSENT:
9068 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9069 break;
9070 case CARDSTATE_PRESENT:
9071 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9072 break;
9073 case CARDSTATE_ERROR:
9074 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9075 break;
9076 case CARDSTATE_RESTRICTED:
9077 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9078 break;
9079 default:
9080 break;
9081
9082 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009083 List<UiccPortInfo> portInfos = new ArrayList<>();
9084 int[] portIndexes = slot.getPortList();
9085 for (int portIdx : portIndexes) {
9086 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009087 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009088 portInfos.add(new UiccPortInfo(iccId, portIdx,
9089 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009091 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009092 slot.isEuicc(),
9093 cardId,
9094 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009095 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009096 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009097 //setting the value after compatibility check
9098 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009099 }
9100 return infos;
9101 } finally {
9102 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009103 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009104 }
9105
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009106 /* Returns null if doesn't have read permission or carrier privilege access. */
9107 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9108 boolean hasReadPermission) {
9109 String iccId = slot.getIccId(portIndex);
9110 if (hasReadPermission) { // if has read permission
9111 return iccId;
9112 } else {
9113 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9114 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9115 // if no read permission, checking carrier privilege access
9116 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9117 return iccId;
9118 }
9119 }
9120 }
9121 // No read permission or carrier privilege access.
9122 return UiccPortInfo.ICCID_REDACTED;
9123 }
9124
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009125 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009126 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009127 public boolean switchSlots(int[] physicalSlots) {
9128 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009132 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9133 for (int i = 0; i < physicalSlots.length; i++) {
9134 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9135 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9136 physicalSlots[i], i));
9137 }
9138 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009139 } finally {
9140 Binder.restoreCallingIdentity(identity);
9141 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009142 }
Jack Yu4c988042018-02-27 15:30:01 -08009143
9144 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009145 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9146 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9147 enforceModifyPermission();
9148
9149 final long identity = Binder.clearCallingIdentity();
9150 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009151 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009152 } finally {
9153 Binder.restoreCallingIdentity(identity);
9154 }
9155 }
9156
9157 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009158 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 return UiccController.getInstance().getCardIdForDefaultEuicc();
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 }
9166
Pengquan Meng85728fb2018-03-12 16:31:21 -07009167 /**
goneil47ffb6e2018-04-06 15:40:58 -07009168 * A test API to reload the UICC profile.
9169 *
9170 * <p>Requires that the calling app has permission
9171 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9172 * @hide
9173 */
9174 @Override
9175 public void refreshUiccProfile(int subId) {
9176 enforceModifyPermission();
9177
9178 final long identity = Binder.clearCallingIdentity();
9179 try {
9180 Phone phone = getPhone(subId);
9181 if (phone == null) {
9182 return;
9183 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009184 UiccPort uiccPort = phone.getUiccPort();
9185 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009186 return;
9187 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009188 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009189 if (uiccProfile == null) {
9190 return;
9191 }
9192 uiccProfile.refresh();
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
9196 }
9197
9198 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009199 * Returns false if the mobile data is disabled by default, otherwise return true.
9200 */
9201 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009202 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009203 }
9204
9205 /**
9206 * Returns true if the data roaming is enabled by default, i.e the system property
9207 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9208 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9209 */
9210 private boolean getDefaultDataRoamingEnabled(int subId) {
9211 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009212 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009213 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009214 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9215 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9216 return isDataRoamingEnabled;
9217 }
9218
9219 /**
9220 * Returns the default network type for the given {@code subId}, if the default network type is
9221 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9222 */
9223 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009224 List<Integer> list = TelephonyProperties.default_network();
9225 int phoneId = mSubscriptionController.getPhoneId(subId);
9226 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9227 return list.get(phoneId);
9228 }
9229 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009230 }
fionaxua13278b2018-03-21 00:08:13 -07009231
9232 @Override
9233 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009234 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009235 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009236
9237 final long identity = Binder.clearCallingIdentity();
9238 try {
9239 final Phone phone = getPhone(subId);
9240 if (phone == null) {
9241 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9242 return;
9243 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009244 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9245 if (cpt != null) {
9246 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9247 }
9248 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009249 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9250 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009251 if (carrierPrivilegeRules == null) {
9252 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9253 } else {
9254 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009256 } finally {
9257 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009258 }
fionaxua13278b2018-03-21 00:08:13 -07009259 }
9260
9261 @Override
9262 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009263 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009264
9265 final long identity = Binder.clearCallingIdentity();
9266 try {
9267 final Phone phone = getPhone(subId);
9268 if (phone == null) {
9269 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9270 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9271 }
9272 return phone.getCarrierIdListVersion();
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009275 }
fionaxua13278b2018-03-21 00:08:13 -07009276 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009277
9278 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009279 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9280 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009282 mApp, subId, callingPackage, callingFeatureId,
9283 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009284 return -1;
9285 }
9286
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
9289 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9290 } finally {
9291 Binder.restoreCallingIdentity(identity);
9292 }
9293 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009294
9295 @Override
9296 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009297 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009298 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009299 mApp, subId, "getCdmaRoamingMode");
9300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
9308
9309 @Override
9310 public boolean setCdmaRoamingMode(int subId, int mode) {
9311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9312 mApp, subId, "setCdmaRoamingMode");
9313
9314 final long identity = Binder.clearCallingIdentity();
9315 try {
9316 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 }
9321
9322 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009323 public int getCdmaSubscriptionMode(int subId) {
9324 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009325 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009326 mApp, subId, "getCdmaSubscriptionMode");
9327
9328 final long identity = Binder.clearCallingIdentity();
9329 try {
9330 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
9336 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009337 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9339 mApp, subId, "setCdmaSubscriptionMode");
9340
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9344 } finally {
9345 Binder.restoreCallingIdentity(identity);
9346 }
9347 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009348
sqianc5eccab2018-10-19 18:46:41 -07009349 @Override
sqian8c685422019-02-22 15:55:18 -08009350 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009351 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009353 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9354 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009355 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9356 }
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
sqian854d44b2018-12-12 16:48:18 -08009359 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9360 for (Phone phone: PhoneFactory.getPhones()) {
9361 if (phone.getEmergencyNumberTracker() != null
9362 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9363 emergencyNumberListInternal.put(
9364 phone.getSubId(),
9365 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9366 }
sqian11b7a0e2018-12-05 18:48:28 -08009367 }
sqian854d44b2018-12-12 16:48:18 -08009368 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009369 } finally {
9370 Binder.restoreCallingIdentity(identity);
9371 }
sqianc5eccab2018-10-19 18:46:41 -07009372 }
9373
9374 @Override
sqian8c685422019-02-22 15:55:18 -08009375 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009376 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009377 if (!exactMatch) {
9378 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009379 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009380 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009381 }
9382 final long identity = Binder.clearCallingIdentity();
9383 try {
sqian854d44b2018-12-12 16:48:18 -08009384 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009385 //Note: we ignore passed in param exactMatch. We can remove it once
9386 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009387 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009388 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009389 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009390 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009391 }
sqian11b7a0e2018-12-05 18:48:28 -08009392 }
9393 return false;
9394 } finally {
9395 Binder.restoreCallingIdentity(identity);
9396 }
9397 }
9398
sqianf4ca7ed2019-01-15 18:32:07 -08009399 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009400 * Start emergency callback mode for GsmCdmaPhone for testing.
9401 */
9402 @Override
9403 public void startEmergencyCallbackMode() {
9404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9405 "startEmergencyCallbackMode");
9406 enforceModifyPermission();
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
9409 for (Phone phone : PhoneFactory.getPhones()) {
9410 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9411 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9412 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9413 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9414 gsmCdmaPhone.obtainMessage(
9415 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9416 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9417 }
9418 }
9419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
9424 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009425 * Update emergency number list for test mode.
9426 */
9427 @Override
9428 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9429 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9430 "updateEmergencyNumberListTestMode");
9431
9432 final long identity = Binder.clearCallingIdentity();
9433 try {
9434 for (Phone phone: PhoneFactory.getPhones()) {
9435 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9436 if (tracker != null) {
9437 tracker.executeEmergencyNumberTestModeCommand(action, num);
9438 }
9439 }
9440 } finally {
9441 Binder.restoreCallingIdentity(identity);
9442 }
9443 }
9444
9445 /**
9446 * Get the full emergency number list for test mode.
9447 */
9448 @Override
9449 public List<String> getEmergencyNumberListTestMode() {
9450 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9451 "getEmergencyNumberListTestMode");
9452
9453 final long identity = Binder.clearCallingIdentity();
9454 try {
9455 Set<String> emergencyNumbers = new HashSet<>();
9456 for (Phone phone: PhoneFactory.getPhones()) {
9457 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9458 if (tracker != null) {
9459 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9460 emergencyNumbers.add(num.getNumber());
9461 }
9462 }
9463 }
9464 return new ArrayList<>(emergencyNumbers);
9465 } finally {
9466 Binder.restoreCallingIdentity(identity);
9467 }
9468 }
9469
chen xud6b45bd2018-10-30 22:27:10 -07009470 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009471 public int getEmergencyNumberDbVersion(int subId) {
9472 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9473
9474 final long identity = Binder.clearCallingIdentity();
9475 try {
9476 final Phone phone = getPhone(subId);
9477 if (phone == null) {
9478 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9479 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9480 }
9481 return phone.getEmergencyNumberDbVersion();
9482 } finally {
9483 Binder.restoreCallingIdentity(identity);
9484 }
9485 }
9486
9487 @Override
9488 public void notifyOtaEmergencyNumberDbInstalled() {
9489 enforceModifyPermission();
9490
9491 final long identity = Binder.clearCallingIdentity();
9492 try {
9493 for (Phone phone: PhoneFactory.getPhones()) {
9494 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9495 if (tracker != null) {
9496 tracker.updateOtaEmergencyNumberDatabase();
9497 }
9498 }
9499 } finally {
9500 Binder.restoreCallingIdentity(identity);
9501 }
9502 }
9503
9504 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009505 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009506 enforceActiveEmergencySessionPermission();
9507
9508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 for (Phone phone: PhoneFactory.getPhones()) {
9511 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9512 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009513 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9514 }
9515 }
9516 } finally {
9517 Binder.restoreCallingIdentity(identity);
9518 }
9519 }
9520
9521 @Override
9522 public void resetOtaEmergencyNumberDbFilePath() {
9523 enforceActiveEmergencySessionPermission();
9524
9525 final long identity = Binder.clearCallingIdentity();
9526 try {
9527 for (Phone phone: PhoneFactory.getPhones()) {
9528 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9529 if (tracker != null) {
9530 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009531 }
9532 }
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009539 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9540 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9541 Phone phone = getPhone(subId);
9542 if (phone == null) {
9543 return null;
9544 }
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 UiccProfile profile = UiccController.getInstance()
9548 .getUiccProfileForPhone(phone.getPhoneId());
9549 if (profile != null) {
9550 return profile.getCertsFromCarrierPrivilegeAccessRules();
9551 }
9552 } finally {
9553 Binder.restoreCallingIdentity(identity);
9554 }
9555 return null;
9556 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009557
9558 /**
9559 * Enable or disable a modem stack.
9560 */
9561 @Override
9562 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9563 enforceModifyPermission();
9564
9565 final long identity = Binder.clearCallingIdentity();
9566 try {
9567 Phone phone = PhoneFactory.getPhone(slotIndex);
9568 if (phone == null) {
9569 return false;
9570 } else {
9571 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9572 }
9573 } finally {
9574 Binder.restoreCallingIdentity(identity);
9575 }
9576 }
Michelecea4cf22018-12-21 15:00:11 -08009577
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009578 /**
9579 * Whether a modem stack is enabled or not.
9580 */
9581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009582 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9583 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009584 Phone phone = PhoneFactory.getPhone(slotIndex);
9585 if (phone == null) return false;
9586
9587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009588 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9589 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009590 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9591 }
9592
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009595 try {
9596 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9597 } catch (NoSuchElementException ex) {
9598 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9599 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
9604
Michelecea4cf22018-12-21 15:00:11 -08009605 @Override
Michele0ea7d782019-03-19 14:58:42 -07009606 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009607 enforceModifyPermission();
9608
9609 final long identity = Binder.clearCallingIdentity();
9610 try {
9611 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009612 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009613 .commit();
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 @Override
Michele0ea7d782019-03-19 14:58:42 -07009620 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009621 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009623 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9624 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009625 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009626 }
Michelecea4cf22018-12-21 15:00:11 -08009627
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
Michele0ea7d782019-03-19 14:58:42 -07009630 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009631 } finally {
9632 Binder.restoreCallingIdentity(identity);
9633 }
9634 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009635
Michele0ea7d782019-03-19 14:58:42 -07009636 @TelephonyManager.IsMultiSimSupportedResult
9637 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009638 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9639 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9640 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009641 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9642 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009643 }
9644 // Check if the hardware supports multisim functionality. If usage of multisim is not
9645 // supported by the modem, indicate that it is restricted.
9646 PhoneCapability staticCapability =
9647 mPhoneConfigurationManager.getStaticPhoneCapability();
9648 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009649 loge("isMultiSimSupportedInternal: no static configuration available");
9650 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009651 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009652 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009653 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9654 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009655 }
9656 // Check if support of multiple SIMs is restricted by carrier
9657 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009658 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009659 }
9660
Michele0ea7d782019-03-19 14:58:42 -07009661 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009662 }
9663
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009664 /**
9665 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009666 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9667 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9668 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009669 * @param numOfSims number of active sims we want to switch to
9670 */
9671 @Override
9672 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009673 if (numOfSims == 1) {
9674 enforceModifyPermission();
9675 } else {
9676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9677 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9678 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009679 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009680
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009681 try {
Michele30b57b22019-03-01 12:01:14 -08009682 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009683 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009684 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9685 return;
9686 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009687 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9688 } finally {
9689 Binder.restoreCallingIdentity(identity);
9690 }
9691 }
9692
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009693 @Override
9694 public boolean isApplicationOnUicc(int subId, int appType) {
9695 enforceReadPrivilegedPermission("isApplicationOnUicc");
9696 Phone phone = getPhone(subId);
9697 if (phone == null) {
9698 return false;
9699 }
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009702 UiccPort uiccPort = phone.getUiccPort();
9703 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009704 return false;
9705 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009706 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009707 if (uiccProfile == null) {
9708 return false;
9709 }
9710 if (TelephonyManager.APPTYPE_SIM <= appType
9711 && appType <= TelephonyManager.APPTYPE_ISIM) {
9712 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9713 }
9714 return false;
9715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
9719
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009720 /**
chen xub4baa772019-04-03 10:23:41 -07009721 * Get whether making changes to modem configurations will trigger reboot.
9722 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009723 */
9724 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009725 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9726 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009728 mApp, subId, callingPackage, callingFeatureId,
9729 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009730 return false;
9731 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009732 final long identity = Binder.clearCallingIdentity();
9733 try {
9734 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
9739
Nathan Harold29f5f052019-02-15 13:41:57 -08009740 private void updateModemStateMetrics() {
9741 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9742 // TODO: check the state for each modem if the api is ready.
9743 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9744 }
9745
Pengquan Meng3889a572019-01-23 11:16:29 -08009746 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009747 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009748 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009749 // Verify that the callingPackage belongs to the calling UID
9750 mApp.getSystemService(AppOpsManager.class)
9751 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009752 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009753 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009754 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009755 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9756 if (slotInfos != null) {
9757 for (int i = 0; i < slotInfos.length; i++) {
9758 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9759 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9760 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9761 portInfo.getLogicalSlotIndex()));
9762 }
9763 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009764 }
9765 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009766 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009771
9772 /**
9773 * Get the IRadio HAL Version
9774 */
9775 @Override
9776 public int getRadioHalVersion() {
9777 Phone phone = getDefaultPhone();
9778 if (phone == null) return -1;
9779 HalVersion hv = phone.getHalVersion();
9780 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9781 return hv.major * 100 + hv.minor;
9782 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009783
9784 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009785 * Get the current calling package name.
9786 * @return the current calling package name
9787 */
9788 @Override
9789 public String getCurrentPackageName() {
9790 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9791 }
9792
9793 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009794 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9795 * corresponding network requests on a subId.
9796 *
9797 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009798 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009799 * 2) APN is un-metered for this subscription, or
9800 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009801 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009802 *
9803 * @return whether data is allowed for a apn type.
9804 *
9805 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009806 */
9807 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009808 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009809 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9810 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009811
9812 // Now that all security checks passes, perform the operation as ourselves.
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
9815 Phone phone = getPhone(subId);
9816 if (phone == null) return false;
9817
Jack Yu27422a52022-03-21 10:38:05 -07009818 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009819 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009820 isMetered = phone.getDataNetworkController().getDataConfigManager()
9821 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9822 phone.getServiceState().getDataRoaming());
9823 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009824 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009825 } finally {
9826 Binder.restoreCallingIdentity(identity);
9827 }
9828 }
9829
9830 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009831 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009832 enforceReadPrivilegedPermission("isApnMetered");
9833
9834 // Now that all security checks passes, perform the operation as ourselves.
9835 final long identity = Binder.clearCallingIdentity();
9836 try {
9837 Phone phone = getPhone(subId);
9838 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009839 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9840 DataUtils.apnTypeToNetworkCapability(apnType),
9841 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009846
9847 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009848 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9849 int subscriptionId, IBooleanConsumer resultCallback) {
9850 enforceModifyPermission();
9851 long token = Binder.clearCallingIdentity();
9852 try {
9853 Phone phone = getPhone(subscriptionId);
9854 if (phone == null) {
9855 try {
9856 if (resultCallback != null) {
9857 resultCallback.accept(false);
9858 }
9859 } catch (RemoteException e) {
9860 // ignore
9861 }
9862 return;
9863 }
9864 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9865 Pair.create(specifiers, (x) -> {
9866 try {
9867 if (resultCallback != null) {
9868 resultCallback.accept(x);
9869 }
9870 } catch (RemoteException e) {
9871 // ignore
9872 }
9873 });
9874 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9875 } finally {
9876 Binder.restoreCallingIdentity(token);
9877 }
9878 }
9879
9880 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009881 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9882 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009883 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009884 mApp, subId, "getSystemSelectionChannels");
9885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009888 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9889 if (result instanceof IllegalStateException) {
9890 throw (IllegalStateException) result;
9891 }
9892 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009893 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9894 return specifiers;
9895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
9900 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009901 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009902 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009903 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009904 }
9905
9906 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009907 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9908 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009909 if (callingPackage == null) {
9910 callingPackage = getCurrentPackageName();
9911 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009912 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9913 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009914 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9915 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009916 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9917 }
9918 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9919 Intent intent = new Intent();
9920 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9921 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9922 // Bring up choose default SMS subscription dialog right now
9923 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9924 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9925 mApp.startActivity(intent);
9926 }
chen xud5ca2d52019-05-28 15:20:57 -07009927
9928 @Override
9929 public String getMmsUAProfUrl(int subId) {
9930 //TODO investigate if this API should require proper permission check in R b/133791609
9931 final long identity = Binder.clearCallingIdentity();
9932 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009933 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9934 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9935 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9936 return carrierUAProfUrl;
9937 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009938 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9939 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009940 } finally {
9941 Binder.restoreCallingIdentity(identity);
9942 }
9943 }
9944
9945 @Override
9946 public String getMmsUserAgent(int subId) {
9947 //TODO investigate if this API should require proper permission check in R b/133791609
9948 final long identity = Binder.clearCallingIdentity();
9949 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009950 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9951 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9952 if (!TextUtils.isEmpty(carrierUserAgent)) {
9953 return carrierUserAgent;
9954 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009955 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9956 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
Jack Yub07d4972019-05-28 16:12:25 -07009961
9962 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009963 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9964 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009965
Jack Yub07d4972019-05-28 16:12:25 -07009966 final long identity = Binder.clearCallingIdentity();
9967 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009968 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009969 if (phone == null) return false;
9970
Ling Maf188d502022-09-16 15:22:36 -07009971 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
9977 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009978 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009979 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009980 enforceModifyPermission();
9981
changbettyd5c246e2019-12-24 15:40:37 +08009982 final long identity = Binder.clearCallingIdentity();
9983 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009984 Phone phone = getPhone(subscriptionId);
9985 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009986
Ling Maf188d502022-09-16 15:22:36 -07009987 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009988 } finally {
9989 Binder.restoreCallingIdentity(identity);
9990 }
9991 }
9992
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009993 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009994 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009995 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9996 * otherwise.
9997 */
9998 @Override
9999 public void setCepEnabled(boolean isCepEnabled) {
10000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10001
10002 final long identity = Binder.clearCallingIdentity();
10003 try {
10004 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10005 for (Phone phone : PhoneFactory.getPhones()) {
10006 Phone defaultPhone = phone.getImsPhone();
10007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10009 ImsPhoneCallTracker imsPhoneCallTracker =
10010 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10011 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10012 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10013 + imsPhone.getMsisdn());
10014 }
10015 }
10016 } finally {
10017 Binder.restoreCallingIdentity(identity);
10018 }
10019 }
allenwtsu46dcc572020-01-08 18:24:03 +080010020
10021 /**
10022 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10023 *
10024 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10025 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10026 * before being read.
10027 */
10028 @Override
10029 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10030 isCompressed) {
10031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10032 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010033 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10034 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10035 }
10036 if (!isImsAvailableOnDevice()) {
10037 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10038 "IMS not available on device.");
10039 }
10040
10041 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010042 try {
Hui Wang761a6682020-10-31 05:12:53 +000010043 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10044 } finally {
10045 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010046 }
10047 }
zoey chene02881a2019-12-30 16:11:23 +080010048
10049 @Override
10050 public boolean isIccLockEnabled(int subId) {
10051 enforceReadPrivilegedPermission("isIccLockEnabled");
10052
10053 // Now that all security checks passes, perform the operation as ourselves.
10054 final long identity = Binder.clearCallingIdentity();
10055 try {
10056 Phone phone = getPhone(subId);
10057 if (phone != null && phone.getIccCard() != null) {
10058 return phone.getIccCard().getIccLockEnabled();
10059 } else {
10060 return false;
10061 }
10062 } finally {
10063 Binder.restoreCallingIdentity(identity);
10064 }
10065 }
10066
10067 /**
10068 * Set the ICC pin lock enabled or disabled.
10069 *
10070 * @return an integer representing the status of IccLock enabled or disabled in the following
10071 * three cases:
10072 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10073 * successfully.
10074 * - Positive number and zero for remaining password attempts.
10075 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10076 *
10077 */
10078 @Override
10079 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10080 enforceModifyPermission();
10081
10082 Phone phone = getPhone(subId);
10083 if (phone == null) {
10084 return 0;
10085 }
10086 // Now that all security checks passes, perform the operation as ourselves.
10087 final long identity = Binder.clearCallingIdentity();
10088 try {
10089 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10090 new Pair<Boolean, String>(enabled, password), phone, null);
10091 return attemptsRemaining;
10092
10093 } catch (Exception e) {
10094 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 return 0;
10099 }
10100
10101 /**
10102 * Change the ICC password used in ICC pin lock.
10103 *
10104 * @return an integer representing the status of IccLock changed in the following three cases:
10105 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10106 * - Positive number and zero for remaining password attempts.
10107 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10108 *
10109 */
10110 @Override
10111 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10112 enforceModifyPermission();
10113
10114 Phone phone = getPhone(subId);
10115 if (phone == null) {
10116 return 0;
10117 }
10118 // Now that all security checks passes, perform the operation as ourselves.
10119 final long identity = Binder.clearCallingIdentity();
10120 try {
10121 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10122 new Pair<String, String>(oldPassword, newPassword), phone, null);
10123 return attemptsRemaining;
10124
10125 } catch (Exception e) {
10126 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 return 0;
10131 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010132
10133 /**
10134 * Request for receiving user activity notification
10135 */
10136 @Override
10137 public void requestUserActivityNotification() {
10138 if (!mNotifyUserActivity.get()
10139 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10140 mNotifyUserActivity.set(true);
10141 }
10142 }
10143
10144 /**
10145 * Called when userActivity is signalled in the power manager.
10146 * This is safe to call from any thread, with any window manager locks held or not.
10147 */
10148 @Override
10149 public void userActivity() {
10150 // ***************************************
10151 // * Inherited from PhoneWindowManager *
10152 // ***************************************
10153 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10154 // WITH ITS LOCKS HELD.
10155 //
10156 // This code must be VERY careful about the locks
10157 // it acquires.
10158 // In fact, the current code acquires way too many,
10159 // and probably has lurking deadlocks.
10160
10161 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10162 throw new SecurityException("Only the OS may call notifyUserActivity()");
10163 }
10164
10165 if (mNotifyUserActivity.getAndSet(false)) {
10166 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10167 USER_ACTIVITY_NOTIFICATION_DELAY);
10168 }
10169 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010170
10171 @Override
10172 public boolean canConnectTo5GInDsdsMode() {
10173 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10174 }
Jack Yud10cdd42020-09-28 20:28:01 -070010175
10176 @Override
10177 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10178 String callingFeatureId) {
10179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10180 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10181 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10182 }
10183
10184 Phone phone = getPhone(subId);
10185 if (phone == null) {
10186 throw new RuntimeException("phone is not available");
10187 }
10188 // Now that all security checks passes, perform the operation as ourselves.
10189 final long identity = Binder.clearCallingIdentity();
10190 try {
10191 return phone.getEquivalentHomePlmns();
10192 } finally {
10193 Binder.restoreCallingIdentity(identity);
10194 }
10195 }
Daniel Bright59e67312020-11-13 11:49:37 -080010196
10197 @Override
10198 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010199 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10200 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010201 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010202 if (radioInterfaceCapabilities == null) {
10203 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010204 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010205 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010206 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010207
Hui Wang641e81c2020-10-12 12:14:23 -070010208 @Override
10209 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10210 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010211 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10212 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10213 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10214 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10215 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010216 if (DBG) {
10217 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10218 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10219 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10220 }
10221
10222 if (!SubscriptionManager.isValidSubscriptionId(subId)
10223 || appType < TelephonyManager.APPTYPE_UNKNOWN
10224 || appType > TelephonyManager.APPTYPE_ISIM
10225 || nafUrl == null || securityProtocol == null || callback == null) {
10226 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10227 if (callback != null) {
10228 try {
10229 callback.onAuthenticationFailure(
10230 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10231 } catch (RemoteException exception) {
10232 log("Fail to notify onAuthenticationFailure due to " + exception);
10233 }
10234 return;
10235 }
10236 }
10237
10238 final long token = Binder.clearCallingIdentity();
10239 try {
10240 getGbaManager(subId).bootstrapAuthenticationRequest(
10241 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10242 forceBootStrapping, callback));
10243 } finally {
10244 Binder.restoreCallingIdentity(token);
10245 }
10246 }
10247
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010248 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010249 * Attempts to set the radio power state for all phones for thermal reason.
10250 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010251 * requested radio power state will actually be set. See {@link
10252 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10253 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010254 * @param enable {@code true} if trying to turn radio on.
10255 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10256 * false}.
10257 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010258 private boolean setRadioPowerForThermal(boolean enable) {
10259 boolean isPhoneAvailable = false;
10260 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10261 Phone phone = PhoneFactory.getPhone(i);
10262 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010263 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010264 isPhoneAvailable = true;
10265 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010266 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010267
10268 // return true if successfully informed the phone object about the thermal radio power
10269 // request.
10270 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010271 }
10272
10273 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010274 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010275 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10276 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10277 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10278 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10279 throw new IllegalArgumentException("modem does not support data throttling");
10280 }
10281
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010282 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10283 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010284 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010285 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10286 }
10287
Sarah Chinecc78c42022-03-31 21:16:48 -070010288 setDataEnabledForReason(
10289 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010290
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010291 if (isDataThrottlingSupported) {
10292 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010293 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010294 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10295 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10296 } else if (thermalMitigationResult
10297 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010298 log("Modem likely does not support data throttling on secondary carrier. Data " +
10299 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10300 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010301 }
10302 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010303 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010304
10305 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010306 }
10307
Jack Nudelman644b91a2021-03-12 14:09:48 -080010308 private static List<String> getThermalMitigationAllowlist(Context context) {
10309 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10310 for (String pckg : context.getResources()
10311 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10312 sThermalMitigationAllowlistedPackages.add(pckg);
10313 }
10314 }
10315
10316 return sThermalMitigationAllowlistedPackages;
10317 }
10318
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010319 private boolean isAnyPhoneInEmergencyState() {
10320 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10321 if (tm.isInEmergencyCall()) {
10322 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10323 return true;
10324 }
10325 for (Phone phone : PhoneFactory.getPhones()) {
10326 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10327 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10328 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10329 + phone.isInEcm());
10330 return true;
10331 }
10332 }
10333
10334 return false;
10335 }
10336
Jack Nudelman644b91a2021-03-12 14:09:48 -080010337 /**
10338 * Used by shell commands to add an authorized package name for thermal mitigation.
10339 * @param packageName name of package to be allowlisted
10340 * @param context
10341 */
10342 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10343 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10344 sThermalMitigationAllowlistedPackages.add(packageName);
10345 }
10346
10347 /**
10348 * Used by shell commands to remove an authorized package name for thermal mitigation.
10349 * @param packageName name of package to remove from allowlist
10350 * @param context
10351 */
10352 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10353 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10354 sThermalMitigationAllowlistedPackages.remove(packageName);
10355 }
10356
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010357 /**
10358 * Thermal mitigation request to control functionalities at modem.
10359 *
10360 * @param subId the id of the subscription.
10361 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010362 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010363 *
10364 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10365 */
10366 @Override
10367 @ThermalMitigationResult
10368 public int sendThermalMitigationRequest(
10369 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010370 ThermalMitigationRequest thermalMitigationRequest,
10371 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 enforceModifyPermission();
10373
Jack Nudelman644b91a2021-03-12 14:09:48 -080010374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10375 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10376 .contains(callingPackage)) {
10377 throw new SecurityException("Calling package must be configured in the device config. "
10378 + "calling package: " + callingPackage);
10379 }
10380
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010381 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10382 final long identity = Binder.clearCallingIdentity();
10383
10384 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10385 try {
10386 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10387 switch (thermalMitigationAction) {
10388 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10389 thermalMitigationResult =
10390 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010391 thermalMitigationRequest.getDataThrottlingRequest(),
10392 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010393 break;
10394 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10395 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10396 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10397 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10398 }
10399
10400 // Ensure that radio is on. If not able to power on due to phone being
10401 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010402 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010403 thermalMitigationResult =
10404 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10405 break;
10406 }
10407
10408 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010409 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010410 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10411 break;
10412 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10413 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10414 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10415 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10416 }
10417
10418 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10419 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010420 Phone phone = getPhone(subId);
10421 if (phone == null) {
10422 thermalMitigationResult =
10423 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10424 break;
10425 }
10426
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010427 TelephonyConnectionService service =
10428 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010429 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010430 Log.e(LOG_TAG, "An emergency call is pending");
10431 thermalMitigationResult =
10432 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10433 break;
10434 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010435 thermalMitigationResult =
10436 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10437 break;
10438 }
10439 } else {
10440 thermalMitigationResult =
10441 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10442 break;
10443 }
10444
10445 // Turn radio off. If not able to power off due to phone being unavailable,
10446 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010447 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010448 thermalMitigationResult =
10449 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10450 break;
10451 }
10452 thermalMitigationResult =
10453 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10454 break;
10455 default:
10456 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10457 + "not exist. Requested action: " + thermalMitigationAction);
10458 }
10459 } catch (IllegalArgumentException e) {
10460 throw e;
10461 } catch (Exception e) {
10462 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10463 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467
10468 if (DBG) {
10469 log("thermalMitigationRequest returning with thermalMitigationResult: "
10470 + thermalMitigationResult);
10471 }
10472
10473 return thermalMitigationResult;
10474 }
Hui Wang641e81c2020-10-12 12:14:23 -070010475
10476 /**
10477 * Set the GbaService Package Name that Telephony will bind to.
10478 *
10479 * @param subId The sim that the GbaService is associated with.
10480 * @param packageName The name of the package to be replaced with.
10481 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10482 */
10483 @Override
10484 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10485 enforceModifyPermission();
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 return getGbaManager(subId).overrideServicePackage(packageName);
10490 } finally {
10491 Binder.restoreCallingIdentity(identity);
10492 }
10493 }
10494
10495 /**
10496 * Return the package name of the currently bound GbaService.
10497 *
10498 * @param subId The sim that the GbaService is associated with.
10499 * @return the package name of the GbaService configuration, null if GBA is not supported.
10500 */
10501 @Override
10502 public String getBoundGbaService(int subId) {
10503 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10504
10505 final long identity = Binder.clearCallingIdentity();
10506 try {
10507 return getGbaManager(subId).getServicePackage();
10508 } finally {
10509 Binder.restoreCallingIdentity(identity);
10510 }
10511 }
10512
10513 /**
10514 * Set the release time for telephony to unbind GbaService.
10515 *
10516 * @param subId The sim that the GbaService is associated with.
10517 * @param interval The release time to unbind GbaService by millisecond.
10518 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10519 */
10520 @Override
10521 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10522 enforceModifyPermission();
10523
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
10526 return getGbaManager(subId).overrideReleaseTime(interval);
10527 } finally {
10528 Binder.restoreCallingIdentity(identity);
10529 }
10530 }
10531
10532 /**
10533 * Return the release time for telephony to unbind GbaService.
10534 *
10535 * @param subId The sim that the GbaService is associated with.
10536 * @return The release time to unbind GbaService by millisecond.
10537 */
10538 @Override
10539 public int getGbaReleaseTime(int subId) {
10540 enforceReadPrivilegedPermission("getGbaReleaseTime");
10541
10542 final long identity = Binder.clearCallingIdentity();
10543 try {
10544 return getGbaManager(subId).getReleaseTime();
10545 } finally {
10546 Binder.restoreCallingIdentity(identity);
10547 }
10548 }
10549
10550 private GbaManager getGbaManager(int subId) {
10551 GbaManager instance = GbaManager.getInstance(subId);
10552 if (instance == null) {
10553 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10554 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10555 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10556 }
10557 return instance;
10558 }
Hui Wang761a6682020-10-31 05:12:53 +000010559
10560 /**
10561 * indicate whether the device and the carrier can support
10562 * RCS VoLTE single registration.
10563 */
10564 @Override
10565 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010566 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10567 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10568 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10569 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010570
10571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10572 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10573 }
10574
10575 final long identity = Binder.clearCallingIdentity();
10576 try {
10577 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10578 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010579 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10580 if (isCapable != null) {
10581 return isCapable;
10582 }
Hui Wang761a6682020-10-31 05:12:53 +000010583 }
Hui Wang67af90e2021-06-04 16:57:15 -070010584 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10585 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
10591 /**
10592 * Register RCS provisioning callback.
10593 */
10594 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010595 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010596 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010597 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010598 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010599 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10600 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010601
10602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10603 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10604 }
10605 if (!isImsAvailableOnDevice()) {
10606 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10607 "IMS not available on device.");
10608 }
10609
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010612 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010613 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010614 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10615 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010616 }
Hui Wang761a6682020-10-31 05:12:53 +000010617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 /**
10623 * Unregister RCS provisioning callback.
10624 */
10625 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010626 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010627 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010628 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010629 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010630 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10631 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010632
10633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10634 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10635 }
10636 if (!isImsAvailableOnDevice()) {
10637 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10638 "IMS not available on device.");
10639 }
10640
10641 final long identity = Binder.clearCallingIdentity();
10642 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010643 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010644 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010645 } finally {
10646 Binder.restoreCallingIdentity(identity);
10647 }
10648 }
10649
10650 /**
10651 * trigger RCS reconfiguration.
10652 */
10653 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010654 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10655 "triggerRcsReconfiguration",
10656 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010657
10658 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10659 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10660 }
10661 if (!isImsAvailableOnDevice()) {
10662 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10663 "IMS not available on device.");
10664 }
10665
10666 final long identity = Binder.clearCallingIdentity();
10667 try {
10668 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10669 } finally {
10670 Binder.restoreCallingIdentity(identity);
10671 }
10672 }
10673
10674 /**
10675 * Provide the client configuration parameters of the RCS application.
10676 */
10677 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010678 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10679 "setRcsClientConfiguration",
10680 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010681
10682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10683 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10684 }
10685 if (!isImsAvailableOnDevice()) {
10686 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10687 "IMS not available on device.");
10688 }
10689
10690 final long identity = Binder.clearCallingIdentity();
10691
10692 try {
10693 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10694 if (configBinder == null) {
10695 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010696 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10697 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010698 } else {
10699 configBinder.setRcsClientConfiguration(rcc);
10700 }
joonhunshin3e154242021-09-17 06:33:39 +000010701
10702 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10703 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010704 } catch (RemoteException e) {
10705 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010706 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10707 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
10712
10713 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010714 * Enables or disables the test mode for RCS VoLTE single registration.
10715 */
10716 @Override
10717 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10719 "setRcsSingleRegistrationTestModeEnabled");
10720
10721 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10722 }
10723
10724 /**
10725 * Gets the test mode for RCS VoLTE single registration.
10726 */
10727 @Override
10728 public boolean getRcsSingleRegistrationTestModeEnabled() {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10730 "getRcsSingleRegistrationTestModeEnabled");
10731
10732 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10733 }
10734
10735 /**
Hui Wang761a6682020-10-31 05:12:53 +000010736 * Overrides the config of RCS VoLTE single registration enabled for the device.
10737 */
10738 @Override
10739 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10741 "setDeviceSingleRegistrationEnabledOverride");
10742 enforceModifyPermission();
10743
10744 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10745 : Boolean.parseBoolean(enabledStr);
10746 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010747 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010748 }
10749
10750 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010751 * Sends a device to device communication message. Only usable via shell.
10752 * @param message message to send.
10753 * @param value message value.
10754 */
10755 @Override
10756 public void sendDeviceToDeviceMessage(int message, int value) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010758 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010759 enforceModifyPermission();
10760
10761 final long identity = Binder.clearCallingIdentity();
10762 try {
10763 TelephonyConnectionService service =
10764 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10765 if (service == null) {
10766 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10767 return;
10768 }
10769 service.sendTestDeviceToDeviceMessage(message, value);
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
Tyler Gunnbabbda02021-02-10 11:05:02 -080010775 /**
10776 * Sets the specified device to device transport active.
10777 * @param transport The transport to set active.
10778 */
10779 @Override
10780 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10781 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10782 "setActiveDeviceToDeviceTransport");
10783 enforceModifyPermission();
10784
10785 final long identity = Binder.clearCallingIdentity();
10786 try {
10787 TelephonyConnectionService service =
10788 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10789 if (service == null) {
10790 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10791 return;
10792 }
10793 service.setActiveDeviceToDeviceTransport(transport);
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
Tyler Gunn92479152021-01-20 16:30:10 -080010798
Tyler Gunnd4339262021-05-03 14:46:49 -070010799 @Override
10800 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10801 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10802 "setDeviceToDeviceForceEnabled");
10803
10804 final long identity = Binder.clearCallingIdentity();
10805 try {
10806 Arrays.stream(PhoneFactory.getPhones()).forEach(
10807 p -> {
10808 Phone thePhone = p.getImsPhone();
10809 if (thePhone != null && thePhone instanceof ImsPhone) {
10810 ImsPhone imsPhone = (ImsPhone) thePhone;
10811 CallTracker tracker = imsPhone.getCallTracker();
10812 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10813 ImsPhoneCallTracker imsPhoneCallTracker =
10814 (ImsPhoneCallTracker) tracker;
10815 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10816 }
10817 }
10818 }
10819 );
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
Tyler Gunn92479152021-01-20 16:30:10 -080010825 /**
Hui Wang761a6682020-10-31 05:12:53 +000010826 * Gets the config of RCS VoLTE single registration enabled for the device.
10827 */
10828 @Override
10829 public boolean getDeviceSingleRegistrationEnabled() {
10830 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10831 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10832 }
10833
10834 /**
10835 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10836 */
10837 @Override
10838 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10840 "setCarrierSingleRegistrationEnabledOverride");
10841 enforceModifyPermission();
10842
10843 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10844 : Boolean.parseBoolean(enabledStr);
10845 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10846 subId, enabled);
10847 }
10848
10849 /**
10850 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10851 */
10852 @Override
10853 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10854 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10855 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10856 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010857
10858 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010859 * Overrides the ims feature validation result
10860 */
10861 @Override
10862 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10864 "setImsFeatureValidationOverride");
10865
10866 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10867 : Boolean.parseBoolean(enabledStr);
10868 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10869 subId, enabled);
10870 }
10871
10872 /**
10873 * Gets the ims feature validation override value
10874 */
10875 @Override
10876 public boolean getImsFeatureValidationOverride(int subId) {
10877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10878 "getImsFeatureValidationOverride");
10879 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10880 }
10881
10882 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010883 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10884 * their mobile plan.
10885 */
10886 @Override
10887 public String getMobileProvisioningUrl() {
10888 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10889 final long identity = Binder.clearCallingIdentity();
10890 try {
10891 return getDefaultPhone().getMobileProvisioningUrl();
10892 } finally {
10893 Binder.restoreCallingIdentity(identity);
10894 }
10895 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010896
James.cf Linbcdf8b32021-01-14 16:44:13 +080010897 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010898 * Get the EAB contact from the EAB database.
10899 */
10900 @Override
10901 public String getContactFromEab(String contact) {
10902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10903 enforceModifyPermission();
10904 final long identity = Binder.clearCallingIdentity();
10905 try {
10906 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10907 } finally {
10908 Binder.restoreCallingIdentity(identity);
10909 }
10910 }
10911
10912 /**
Calvin Pana1434322021-07-01 19:27:01 +080010913 * Get the EAB capability from the EAB database.
10914 */
10915 @Override
10916 public String getCapabilityFromEab(String contact) {
10917 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10918 enforceModifyPermission();
10919 final long identity = Binder.clearCallingIdentity();
10920 try {
10921 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10922 } finally {
10923 Binder.restoreCallingIdentity(identity);
10924 }
10925 }
10926
10927 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010928 * Remove the EAB contacts from the EAB database.
10929 */
10930 @Override
10931 public int removeContactFromEab(int subId, String contacts) {
10932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10933 enforceModifyPermission();
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10937 } finally {
10938 Binder.restoreCallingIdentity(identity);
10939 }
10940 }
10941
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010942 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010943 public boolean getDeviceUceEnabled() {
10944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10945 final long identity = Binder.clearCallingIdentity();
10946 try {
10947 return mApp.getDeviceUceEnabled();
10948 } finally {
10949 Binder.restoreCallingIdentity(identity);
10950 }
10951 }
10952
10953 @Override
10954 public void setDeviceUceEnabled(boolean isEnabled) {
10955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10956 final long identity = Binder.clearCallingIdentity();
10957 try {
10958 mApp.setDeviceUceEnabled(isEnabled);
10959 } finally {
10960 Binder.restoreCallingIdentity(identity);
10961 }
10962 }
10963
Brad Ebinger14d467f2021-02-12 06:18:28 +000010964 /**
10965 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10966 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10967 */
10968 // Used for SHELL command only right now.
10969 @Override
10970 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10971 List<String> featureTags) {
10972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10973 "addUceRegistrationOverrideShell");
10974 final long identity = Binder.clearCallingIdentity();
10975 try {
10976 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10977 new ArraySet<>(featureTags));
10978 } catch (ImsException e) {
10979 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10980 } finally {
10981 Binder.restoreCallingIdentity(identity);
10982 }
10983 }
10984
10985 /**
10986 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10987 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10988 */
10989 // Used for SHELL command only right now.
10990 @Override
10991 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10992 List<String> featureTags) {
10993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10994 "removeUceRegistrationOverrideShell");
10995 final long identity = Binder.clearCallingIdentity();
10996 try {
10997 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10998 new ArraySet<>(featureTags));
10999 } catch (ImsException e) {
11000 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11001 } finally {
11002 Binder.restoreCallingIdentity(identity);
11003 }
11004 }
11005
11006 /**
11007 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11008 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11009 */
11010 // Used for SHELL command only right now.
11011 @Override
11012 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11014 "clearUceRegistrationOverrideShell");
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11018 } catch (ImsException e) {
11019 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11020 } finally {
11021 Binder.restoreCallingIdentity(identity);
11022 }
11023 }
11024
11025 /**
11026 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11027 */
11028 // Used for SHELL command only right now.
11029 @Override
11030 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11031 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11032 "getLatestRcsContactUceCapabilityShell");
11033 final long identity = Binder.clearCallingIdentity();
11034 try {
11035 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11036 } catch (ImsException e) {
11037 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11038 } finally {
11039 Binder.restoreCallingIdentity(identity);
11040 }
11041 }
11042
11043 /**
11044 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11045 * device does not have an active PUBLISH.
11046 */
11047 // Used for SHELL command only right now.
11048 @Override
11049 public String getLastUcePidfXmlShell(int subId) {
11050 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11051 final long identity = Binder.clearCallingIdentity();
11052 try {
11053 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11054 } catch (ImsException e) {
11055 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11056 } finally {
11057 Binder.restoreCallingIdentity(identity);
11058 }
11059 }
11060
James.cf Line8713a42021-04-29 16:04:26 +080011061 /**
11062 * Remove UCE requests cannot be sent to the network status.
11063 */
11064 // Used for SHELL command only right now.
11065 @Override
11066 public boolean removeUceRequestDisallowedStatus(int subId) {
11067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11068 final long identity = Binder.clearCallingIdentity();
11069 try {
11070 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11071 } catch (ImsException e) {
11072 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11073 } finally {
11074 Binder.restoreCallingIdentity(identity);
11075 }
11076 }
11077
James.cf Lin18bb9002021-05-25 01:37:38 +080011078 /**
11079 * Remove UCE requests cannot be sent to the network status.
11080 */
11081 // Used for SHELL command only.
11082 @Override
11083 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11085 final long identity = Binder.clearCallingIdentity();
11086 try {
11087 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11088 } catch (ImsException e) {
11089 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11090 } finally {
11091 Binder.restoreCallingIdentity(identity);
11092 }
11093 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011094
James.cf Lin4b784aa2021-01-31 03:25:15 +080011095 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011096 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11097 String callingPackage) {
11098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11099 mApp, subId, "setSignalStrengthUpdateRequest");
11100
11101 final int callingUid = Binder.getCallingUid();
11102 // Verify that tha callingPackage belongs to the calling UID
11103 mApp.getSystemService(AppOpsManager.class)
11104 .checkPackage(callingUid, callingPackage);
11105
Rambo Wang3607f502021-02-01 21:51:40 -080011106 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011107
11108 final long identity = Binder.clearCallingIdentity();
11109 try {
11110 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11111 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11112
11113 if (result instanceof IllegalStateException) {
11114 throw (IllegalStateException) result;
11115 }
11116 } finally {
11117 Binder.restoreCallingIdentity(identity);
11118 }
11119 }
11120
11121 @Override
11122 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11123 String callingPackage) {
11124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11125 mApp, subId, "clearSignalStrengthUpdateRequest");
11126
11127 final int callingUid = Binder.getCallingUid();
11128 // Verify that tha callingPackage belongs to the calling UID
11129 mApp.getSystemService(AppOpsManager.class)
11130 .checkPackage(callingUid, callingPackage);
11131
11132 final long identity = Binder.clearCallingIdentity();
11133 try {
11134 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11135 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11136
11137 if (result instanceof IllegalStateException) {
11138 throw (IllegalStateException) result;
11139 }
11140 } finally {
11141 Binder.restoreCallingIdentity(identity);
11142 }
11143 }
11144
Rambo Wang3607f502021-02-01 21:51:40 -080011145 private static void validateSignalStrengthUpdateRequest(Context context,
11146 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011147 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11148 // phone/system process do not have further restriction on request
11149 return;
11150 }
11151
11152 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011153 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011154 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011155 context.enforceCallingOrSelfPermission(
11156 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11157 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011158 }
11159
11160 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11161 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11162 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11163 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11164 || info.isEnabled()) {
11165 throw new IllegalArgumentException(
11166 "Only system can set hide fields in SignalThresholdInfo");
11167 }
11168
11169 // Thresholds length for each RAN need in range. This has been validated in
11170 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11171 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11172 final int[] thresholds = info.getThresholds();
11173 Objects.requireNonNull(thresholds);
11174 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11175 || thresholds.length
11176 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11177 throw new IllegalArgumentException(
11178 "thresholds length is out of range: " + thresholds.length);
11179 }
11180 }
11181 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011182
11183 /**
11184 * Gets the current phone capability.
11185 *
11186 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11187 * @return the PhoneCapability which describes the data connection capability of modem.
11188 * It's used to evaluate possible phone config change, for example from single
11189 * SIM device to multi-SIM device.
11190 */
11191 @Override
11192 public PhoneCapability getPhoneCapability() {
11193 enforceReadPrivilegedPermission("getPhoneCapability");
11194 final long identity = Binder.clearCallingIdentity();
11195 try {
11196 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11197 } finally {
11198 Binder.restoreCallingIdentity(identity);
11199 }
11200 }
Michele Berionne5e411512020-11-13 02:36:59 +000011201
11202 /**
11203 * Prepare TelephonyManager for an unattended reboot. The reboot is
11204 * required to be done shortly after the API is invoked.
11205 */
11206 @Override
11207 @TelephonyManager.PrepareUnattendedRebootResult
11208 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011210 enforceRebootPermission();
11211
11212 final long identity = Binder.clearCallingIdentity();
11213 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011214 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011215 } finally {
11216 Binder.restoreCallingIdentity(identity);
11217 }
11218 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011219
11220 /**
11221 * Request to get the current slicing configuration including URSP rules and
11222 * NSSAIs (configured, allowed and rejected).
11223 *
11224 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11225 */
11226 @Override
11227 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011228 TelephonyPermissions
11229 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11230 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011231
11232 final long identity = Binder.clearCallingIdentity();
11233 try {
11234 Phone phone = getDefaultPhone();
11235 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11236 } finally {
11237 Binder.restoreCallingIdentity(identity);
11238 }
11239 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011240
11241 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011242 * Check whether the given premium capability is available for purchase from the carrier.
11243 *
11244 * @param capability The premium capability to check.
11245 * @param subId The subId to check the premium capability for.
11246 *
11247 * @return Whether the given premium capability is available to purchase.
11248 */
11249 @Override
11250 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11251 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11252 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11253 log("Premium capability "
11254 + TelephonyManager.convertPremiumCapabilityToString(capability)
11255 + " is not available for purchase due to missing permissions.");
11256 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11257 + "permission READ_BASIC_PHONE_STATE.");
11258 }
11259
11260 Phone phone = getPhone(subId);
11261 final long identity = Binder.clearCallingIdentity();
11262 try {
11263 return SliceStore.getInstance(phone)
11264 .isPremiumCapabilityAvailableForPurchase(capability);
11265 } finally {
11266 Binder.restoreCallingIdentity(identity);
11267 }
11268 }
11269
11270 /**
11271 * Purchase the given premium capability from the carrier.
11272 *
11273 * @param capability The premium capability to purchase.
11274 * @param callback The result of the purchase request.
11275 * @param subId The subId to purchase the premium capability for.
11276 */
11277 @Override
11278 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11279 log("purchasePremiumCapability: capability="
11280 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11281 + getCurrentPackageName());
11282
11283 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11284 mApp, "purchasePremiumCapability")) {
11285 log("purchasePremiumCapability "
11286 + TelephonyManager.convertPremiumCapabilityToString(capability)
11287 + " failed due to missing permissions.");
11288 throw new SecurityException("purchasePremiumCapability requires permission "
11289 + "READ_BASIC_PHONE_STATE.");
11290 }
11291
11292 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011293 String appName;
11294 try {
11295 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11296 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11297 } catch (PackageManager.NameNotFoundException e) {
11298 appName = "An application";
11299 }
11300 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11301 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011302 }
11303
11304 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011305 * Register an IMS connection state callback
11306 */
11307 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011308 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11309 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011310 if (feature == ImsFeature.FEATURE_MMTEL) {
11311 // ImsMmTelManager
11312 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11313 TelephonyPermissions
11314 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11315 mApp, subId, "registerImsStateCallback");
11316 } else if (feature == ImsFeature.FEATURE_RCS) {
11317 // ImsRcsManager or SipDelegateManager
11318 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11319 Binder.getCallingUid(), "registerImsStateCallback",
11320 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11321 Manifest.permission.READ_PRECISE_PHONE_STATE,
11322 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11324 }
11325
11326 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11327 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11328 "IMS not available on device.");
11329 }
11330
11331 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11332 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11333 }
11334
11335 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11336 if (controller == null) {
11337 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11338 "IMS not available on device.");
11339 }
11340
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011341 if (callingPackage == null) {
11342 callingPackage = getCurrentPackageName();
11343 }
11344
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011345 final long token = Binder.clearCallingIdentity();
11346 try {
11347 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011348 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011349 } catch (ImsException e) {
11350 throw new ServiceSpecificException(e.getCode());
11351 } finally {
11352 Binder.restoreCallingIdentity(token);
11353 }
11354 }
11355
11356 /**
11357 * Unregister an IMS connection state callback
11358 */
11359 @Override
11360 public void unregisterImsStateCallback(IImsStateCallback cb) {
11361 final long token = Binder.clearCallingIdentity();
11362 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11363 if (controller == null) {
11364 return;
11365 }
11366 try {
11367 controller.unregisterImsStateCallback(cb);
11368 } finally {
11369 Binder.restoreCallingIdentity(token);
11370 }
11371 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011372
11373 /**
11374 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11375 *
11376 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11377 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11378 * SecurityException.
11379 * If there is current registered network this value will be same as the registered cell
11380 * identity. If the device goes out of service the previous cell identity is cached and
11381 * will be returned. If the cache age of the Cell identity is more than 24 hours
11382 * it will be cleared and null will be returned.
11383 *
11384 */
11385 @Override
11386 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11387 String callingFeatureId) {
11388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11389 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11390 LocationAccessPolicy.checkLocationPermission(mApp,
11391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11392 .setCallingPackage(callingPackage)
11393 .setCallingFeatureId(callingFeatureId)
11394 .setCallingPid(Binder.getCallingPid())
11395 .setCallingUid(Binder.getCallingUid())
11396 .setMethod("getLastKnownCellIdentity")
11397 .setLogAsInfo(true)
11398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11399 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11400 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11401 .build());
11402
11403 boolean hasFinePermission =
11404 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11405 if (!hasFinePermission
11406 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11407 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011408 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011409 }
11410
11411 final long identity = Binder.clearCallingIdentity();
11412 try {
11413 Phone phone = getPhone(subId);
11414 if (phone == null) return null;
11415 ServiceStateTracker sst = phone.getServiceStateTracker();
11416 if (sst == null) return null;
11417 return sst.getLastKnownCellIdentity();
11418 } finally {
11419 Binder.restoreCallingIdentity(identity);
11420 }
11421 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011422
jimsun3b9ccac2021-10-26 15:01:23 +080011423 /**
11424 * Sets the modem service class Name that Telephony will bind to.
11425 *
11426 * @param serviceName The class name of the modem service.
11427 * @return true if the operation is succeed, otherwise false.
11428 */
11429 public boolean setModemService(String serviceName) {
11430 Log.d(LOG_TAG, "setModemService - " + serviceName);
11431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11433 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11434 "setModemService");
11435 return mPhoneConfigurationManager.setModemService(serviceName);
11436 }
11437
11438 /**
11439 * Return the class name of the currently bounded modem service.
11440 *
11441 * @return the class name of the modem service.
11442 */
11443 public String getModemService() {
11444 String result;
11445 Log.d(LOG_TAG, "getModemService");
11446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11447 TelephonyPermissions
11448 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11449 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11450 "getModemService");
11451 result = mPhoneConfigurationManager.getModemService();
11452 Log.d(LOG_TAG, "result = " + result);
11453 return result;
11454 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011455
11456 @Override
11457 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11458 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11459 mApp.enforceCallingOrSelfPermission(
11460 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11462
11463 final long identity = Binder.clearCallingIdentity();
11464 try {
11465 Phone phone = getPhone(subId);
11466 if (phone == null) return;
11467 phone.setVoiceServiceStateOverride(hasService);
11468 } finally {
11469 Binder.restoreCallingIdentity(identity);
11470 }
11471 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011472
11473 /**
11474 * set removable eSIM as default eUICC.
11475 *
11476 * @hide
11477 */
11478 @Override
11479 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11480 enforceModifyPermission();
11481 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11482
11483 final long identity = Binder.clearCallingIdentity();
11484 try {
11485 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11486 } finally {
11487 Binder.restoreCallingIdentity(identity);
11488 }
11489 }
11490
11491 /**
11492 * Returns whether the removable eSIM is default eUICC or not.
11493 *
11494 * @hide
11495 */
11496 @Override
11497 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11498 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11499 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11500
11501 final long identity = Binder.clearCallingIdentity();
11502 try {
11503 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11504 } finally {
11505 Binder.restoreCallingIdentity(identity);
11506 }
11507 }
11508
11509
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011510}