blob: aa6f7f9a5836d4c5c9c2d5ea466fea27a4797226 [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;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000388 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389
Peter Wangdafb9ac2020-01-15 14:13:38 -0800390 /** User Activity */
391 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800392 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
393
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700394 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
395
Derek Tan97ebb422014-09-05 16:55:38 -0700396 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
397 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800398 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800399 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700400
Michelecea4cf22018-12-21 15:00:11 -0800401 // String to store multi SIM allowed
402 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
403
Derek Tan740e1672017-06-27 14:56:27 -0700404 // The AID of ISD-R.
405 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
406
yinxub1bed742017-04-17 11:45:04 -0700407 private NetworkScanRequestTracker mNetworkScanRequestTracker;
408
David Kelly5e06a7f2018-03-12 14:10:59 +0000409 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
410 private static final int MANUFACTURER_CODE_LENGTH = 8;
411
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800412 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800413 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800414
Sarah Chin2ec39f62022-08-31 17:03:26 -0700415 private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID =
416 "24bf97a6-e8a6-44d8-a6a4-255d7548733c";
417
Derek Tan89e89d42014-07-08 17:00:10 -0700418 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700419 * Experiment flag to enable erase modem config on reset network, default value is false
420 */
421 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
422 "reset_network_erase_modem_config_enabled";
423
Rambo Wang0f050d82021-02-12 11:43:36 -0800424 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800425
sandeepjsb6c87872021-09-27 15:34:44 +0000426 /**
427 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
428 * one ICCID active at the same time.
429 * Apps should use below API signatures if targeting SDK is T and beyond.
430 *
431 * @hide
432 */
433 @ChangeId
434 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
435 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800436
Naina Nallurid63128d2019-09-17 14:10:30 -0700437 /**
Chen Xu540470b2021-12-14 17:15:47 -0800438 * Apps targeting on Android T and beyond will get exception whenever icc close channel
439 * operation fails.
440 */
441 @ChangeId
442 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
443 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
444
445 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 * A request object to use for transmitting data to an ICC.
447 */
448 private static final class IccAPDUArgument {
449 public int channel, cla, command, p1, p2, p3;
450 public String data;
451
452 public IccAPDUArgument(int channel, int cla, int command,
453 int p1, int p2, int p3, String data) {
454 this.channel = channel;
455 this.cla = cla;
456 this.command = command;
457 this.p1 = p1;
458 this.p2 = p2;
459 this.p3 = p3;
460 this.data = data;
461 }
462 }
463
464 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700465 * A request object to use for transmitting data to an ICC.
466 */
467 private static final class ManualNetworkSelectionArgument {
468 public OperatorInfo operatorInfo;
469 public boolean persistSelection;
470
471 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
472 this.operatorInfo = operatorInfo;
473 this.persistSelection = persistSelection;
474 }
475 }
476
Sarah Chin71b3a852022-09-28 15:54:19 -0700477 private static final class PurchasePremiumCapabilityArgument {
478 public @TelephonyManager.PremiumCapability int capability;
479 public @NonNull String appName;
480 public @NonNull IIntegerConsumer callback;
481
482 PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability,
483 @NonNull String appName, @NonNull IIntegerConsumer callback) {
484 this.capability = capability;
485 this.appName = appName;
486 this.callback = callback;
487 }
488 }
489
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700490 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
492 * request after sending. The main thread will notify the request when it is complete.
493 */
494 private static final class MainThreadRequest {
495 /** The argument to use for the request */
496 public Object argument;
497 /** The result of the request that is run on the main thread */
498 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800499 // The subscriber id that this request applies to. Defaults to
500 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
501 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502
Nathan Harold92bed182018-10-12 18:16:49 -0700503 // In cases where subId is unavailable, the caller needs to specify the phone.
504 public Phone phone;
505
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 public WorkSource workSource;
507
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 public MainThreadRequest(Object argument) {
509 this.argument = argument;
510 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800511
Nathan Harold92bed182018-10-12 18:16:49 -0700512 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
513 this.argument = argument;
514 if (phone != null) {
515 this.phone = phone;
516 }
517 this.workSource = workSource;
518 }
519
vagdeviaf9a5b92018-08-15 16:01:53 -0700520 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800521 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800522 if (subId != null) {
523 this.subId = subId;
524 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700525 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 }
528
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800529 private static final class IncomingThirdPartyCallArgs {
530 public final ComponentName component;
531 public final String callId;
532 public final String callerDisplayName;
533
534 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
535 String callerDisplayName) {
536 this.component = component;
537 this.callId = callId;
538 this.callerDisplayName = callerDisplayName;
539 }
540 }
541
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 /**
543 * A handler that processes messages on the main thread in the phone process. Since many
544 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
545 * inbound binder threads to the main thread in the phone process. The Binder thread
546 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
547 * on, which will be notified when the operation completes and will contain the result of the
548 * request.
549 *
550 * <p>If a MainThreadRequest object is provided in the msg.obj field,
551 * note that request.result must be set to something non-null for the calling thread to
552 * unblock.
553 */
554 private final class MainThreadHandler extends Handler {
555 @Override
556 public void handleMessage(Message msg) {
557 MainThreadRequest request;
558 Message onCompleted;
559 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000560 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800562 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700563
564 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 case CMD_HANDLE_USSD_REQUEST: {
566 request = (MainThreadRequest) msg.obj;
567 final Phone phone = getPhoneFromRequest(request);
568 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800569 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700571
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 if (!isUssdApiAllowed(request.subId)) {
573 // Carrier does not support use of this API, return failure.
574 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
575 UssdResponse response = new UssdResponse(ussdRequest, null);
576 Bundle returnData = new Bundle();
577 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
578 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700579
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 request.result = true;
581 notifyRequester(request);
582 return;
583 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700584
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 try {
586 request.result = phone != null
587 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
588 } catch (CallStateException cse) {
589 request.result = false;
590 }
591 // Wake up the requesting thread
592 notifyRequester(request);
593 break;
pkanwar32d516d2016-10-14 19:37:38 -0700594 }
595
Yorke Lee716f67e2015-06-17 15:39:16 -0700596 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700597 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700598 final Phone phone = getPhoneFromRequest(request);
599 request.result = phone != null ?
600 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
601 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700602 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700603 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700604 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700606
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000610 uiccPort = getUiccPortFromRequest(request);
611 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800613 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800617 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000618 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800619 iccArgument.channel, iccArgument.cla, iccArgument.command,
620 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
621 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 ar = (AsyncResult) msg.obj;
627 request = (MainThreadRequest) ar.userObj;
628 if (ar.exception == null && ar.result != null) {
629 request.result = ar.result;
630 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 if (ar.result == null) {
633 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800634 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800636 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 } else {
638 loge("iccTransmitApduLogicalChannel: Unknown exception");
639 }
640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 break;
643
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
645 request = (MainThreadRequest) msg.obj;
646 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000647 uiccPort = getUiccPortFromRequest(request);
648 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700649 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800650 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 } else {
653 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800654 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000655 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800656 iccArgument.cla, iccArgument.command, iccArgument.p1,
657 iccArgument.p2,
658 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 }
660 break;
661
662 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
667 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 if (ar.result == null) {
670 loge("iccTransmitApduBasicChannel: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("iccTransmitApduBasicChannel: CommandException: " +
673 ar.exception);
674 } else {
675 loge("iccTransmitApduBasicChannel: Unknown exception");
676 }
677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 break;
680
681 case CMD_EXCHANGE_SIM_IO:
682 request = (MainThreadRequest) msg.obj;
683 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000684 uiccPort = getUiccPortFromRequest(request);
685 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800687 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 } else {
690 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
691 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
694 iccArgument.data, onCompleted);
695 }
696 break;
697
698 case EVENT_EXCHANGE_SIM_IO_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result;
703 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800704 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700706 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 break;
708
Derek Tan4d5e5c12014-02-04 11:54:58 -0800709 case CMD_SEND_ENVELOPE:
710 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000711 uiccPort = getUiccPortFromRequest(request);
712 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700713 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800714 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700716 } else {
717 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800718 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 break;
721
722 case EVENT_SEND_ENVELOPE_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700725 if (ar.exception == null && ar.result != null) {
726 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800727 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800728 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700729 if (ar.result == null) {
730 loge("sendEnvelopeWithStatus: Empty response");
731 } else if (ar.exception instanceof CommandException) {
732 loge("sendEnvelopeWithStatus: CommandException: " +
733 ar.exception);
734 } else {
735 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
736 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800739 break;
740
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 case CMD_OPEN_CHANNEL:
742 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000743 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800744 IccLogicalChannelRequest openChannelRequest =
745 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000746 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800748 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800749 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800753 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
754 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_OPEN_CHANNEL_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700761 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700763 int[] result = (int[]) ar.result;
764 int channelId = result[0];
765 byte[] selectResponse = null;
766 if (result.length > 1) {
767 selectResponse = new byte[result.length - 1];
768 for (int i = 1; i < result.length; ++i) {
769 selectResponse[i - 1] = (byte) result[i];
770 }
771 }
772 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800773 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800774
775 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700776 if (uiccPort == null) {
777 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
778 } else {
779 IccLogicalChannelRequest channelRequest =
780 (IccLogicalChannelRequest) request.argument;
781 channelRequest.channel = channelId;
782 uiccPort.onLogicalChannelOpened(channelRequest);
783 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 if (ar.result == null) {
786 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700787 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700788 if (ar.exception != null) {
789 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
790 }
791
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700792 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700793 if (ar.exception instanceof CommandException) {
794 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800795 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700796 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700797 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700798 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700799 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700800 }
801 }
802 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800803 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700804 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700805 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700807 break;
808
809 case CMD_CLOSE_CHANNEL:
810 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000811 uiccPort = getUiccPortFromRequest(request);
812 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700813 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800814 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800815 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800816 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700817 } else {
818 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000819 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700821 break;
822
823 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null) {
827 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800828 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700829 if (uiccPort == null) {
830 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
831 } else {
832 final int channelId = (Integer) request.argument;
833 uiccPort.onLogicalChannelClosed(channelId);
834 }
Chen Xu540470b2021-12-14 17:15:47 -0800835 } else {
836 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800837 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800838 if (ar.exception instanceof CommandException) {
839 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
840 CommandException.Error error =
841 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800842 if (error == CommandException.Error.INVALID_ARGUMENTS) {
843 // should only throw exceptions from the binder threads.
844 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800845 "iccCloseLogicalChannel: invalid argument ");
846 }
847 } else {
848 loge("iccCloseLogicalChannel: Unknown exception");
849 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800850 request.result = (exception != null) ? exception :
851 new IllegalStateException(
852 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800853 }
854 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800855 break;
856
857 case CMD_NV_READ_ITEM:
858 request = (MainThreadRequest) msg.obj;
859 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800860 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
861 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800862 break;
863
864 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700869 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800870 request.result = "";
871 if (ar.result == null) {
872 loge("nvReadItem: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("nvReadItem: CommandException: " +
875 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700876 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800877 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700878 }
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700881 break;
882
Jake Hambye994d462014-02-03 13:10:13 -0800883 case CMD_NV_WRITE_ITEM:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
886 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800887 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700888 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800889 break;
890
891 case EVENT_NV_WRITE_ITEM_DONE:
892 handleNullReturnEvent(msg, "nvWriteItem");
893 break;
894
895 case CMD_NV_WRITE_CDMA_PRL:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800898 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800899 break;
900
901 case EVENT_NV_WRITE_CDMA_PRL_DONE:
902 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
903 break;
904
chen xu6dac5ab2018-10-26 17:39:23 -0700905 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800906 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700907 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800908 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800909 break;
910
chen xu6dac5ab2018-10-26 17:39:23 -0700911 case EVENT_RESET_MODEM_CONFIG_DONE:
912 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800913 break;
914
Sooraj Sasindran37444802020-08-11 10:40:43 -0700915 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
918 request);
919 Phone phone = getPhoneFromRequest(request);
920 if (phone != null) {
921 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
922 } else {
923 loge("isNRDualConnectivityEnabled: No phone object");
924 request.result = false;
925 notifyRequester(request);
926 }
927 break;
928 }
929
930 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
931 ar = (AsyncResult) msg.obj;
932 request = (MainThreadRequest) ar.userObj;
933 if (ar.exception == null && ar.result != null) {
934 request.result = ar.result;
935 } else {
936 // request.result must be set to something non-null
937 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700938 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700939 request.result = ar.result;
940 } else {
941 request.result = false;
942 }
943 if (ar.result == null) {
944 loge("isNRDualConnectivityEnabled: Empty response");
945 } else if (ar.exception instanceof CommandException) {
946 loge("isNRDualConnectivityEnabled: CommandException: "
947 + ar.exception);
948 } else {
949 loge("isNRDualConnectivityEnabled: Unknown exception");
950 }
951 }
952 notifyRequester(request);
953 break;
954
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700955 case CMD_IS_VONR_ENABLED: {
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
958 request);
959 Phone phone = getPhoneFromRequest(request);
960 if (phone != null) {
961 phone.isVoNrEnabled(onCompleted, request.workSource);
962 } else {
963 loge("isVoNrEnabled: No phone object");
964 request.result = false;
965 notifyRequester(request);
966 }
967 break;
968 }
969
970 case EVENT_IS_VONR_ENABLED_DONE:
971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
973 if (ar.exception == null && ar.result != null) {
974 request.result = ar.result;
975 } else {
976 // request.result must be set to something non-null
977 // for the calling thread to unblock
978 if (ar.result != null) {
979 request.result = ar.result;
980 } else {
981 request.result = false;
982 }
983 if (ar.result == null) {
984 loge("isVoNrEnabled: Empty response");
985 } else if (ar.exception instanceof CommandException) {
986 loge("isVoNrEnabled: CommandException: "
987 + ar.exception);
988 } else {
989 loge("isVoNrEnabled: Unknown exception");
990 }
991 }
992 notifyRequester(request);
993 break;
994
Sooraj Sasindran37444802020-08-11 10:40:43 -0700995 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
996 request = (MainThreadRequest) msg.obj;
997 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
998 Phone phone = getPhoneFromRequest(request);
999 if (phone != null) {
1000 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
1001 request.workSource);
1002 } else {
1003 loge("enableNrDualConnectivity: No phone object");
1004 request.result =
1005 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
1006 notifyRequester(request);
1007 }
1008 break;
1009 }
1010
1011 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception == null) {
1015 request.result =
1016 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
1017 } else {
1018 request.result =
1019 TelephonyManager
1020 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1021 if (ar.exception instanceof CommandException) {
1022 CommandException.Error error =
1023 ((CommandException) (ar.exception)).getCommandError();
1024 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1025 request.result =
1026 TelephonyManager
1027 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001028 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1029 request.result =
1030 TelephonyManager
1031 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001032 }
1033 loge("enableNrDualConnectivity" + ": CommandException: "
1034 + ar.exception);
1035 } else {
1036 loge("enableNrDualConnectivity" + ": Unknown exception");
1037 }
1038 }
1039 notifyRequester(request);
1040 break;
1041 }
1042
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001043 case CMD_ENABLE_VONR: {
1044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1046 Phone phone = getPhoneFromRequest(request);
1047 if (phone != null) {
1048 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1049 request.workSource);
1050 } else {
1051 loge("setVoNrEnabled: No phone object");
1052 request.result =
1053 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1054 notifyRequester(request);
1055 }
1056 break;
1057 }
1058
1059 case EVENT_ENABLE_VONR_DONE: {
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 if (ar.exception == null) {
1063 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1064 } else {
1065 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1066 if (ar.exception instanceof CommandException) {
1067 CommandException.Error error =
1068 ((CommandException) (ar.exception)).getCommandError();
1069 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1070 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1071 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1072 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1073 } else {
1074 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1075 }
1076 loge("setVoNrEnabled" + ": CommandException: "
1077 + ar.exception);
1078 } else {
1079 loge("setVoNrEnabled" + ": Unknown exception");
1080 }
1081 }
1082 notifyRequester(request);
1083 break;
1084 }
1085
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001087 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001088 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1089 request);
1090 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001091 break;
1092
SongFerngWang3ef3e072020-12-21 16:41:52 +08001093 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null && ar.result != null) {
1097 request.result = ar.result; // Integer
1098 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301099 // request.result must be set to something non-null
1100 // for the calling thread to unblock
1101 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001102 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001103 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001104 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001105 loge("getAllowedNetworkTypesBitmask: CommandException: "
1106 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001107 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001108 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 }
1110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001112 break;
1113
SongFerngWang3ef3e072020-12-21 16:41:52 +08001114 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001115 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001116 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1117 request);
1118 Pair<Integer, Long> reasonWithNetworkTypes =
1119 (Pair<Integer, Long>) request.argument;
1120 getPhoneFromRequest(request).setAllowedNetworkTypes(
1121 reasonWithNetworkTypes.first,
1122 reasonWithNetworkTypes.second,
1123 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001124 break;
1125
SongFerngWang3ef3e072020-12-21 16:41:52 +08001126 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1127 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001128 break;
1129
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001130 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1131 request = (MainThreadRequest)msg.obj;
1132 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001133 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001134 break;
1135
1136 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1137 ar = (AsyncResult)msg.obj;
1138 request = (MainThreadRequest)ar.userObj;
1139 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001140 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001141 break;
1142
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001143 case CMD_SET_VOICEMAIL_NUMBER:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1146 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001147 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1148 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001149 break;
1150
1151 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1152 handleNullReturnEvent(msg, "setVoicemailNumber");
1153 break;
1154
Stuart Scott54788802015-03-30 13:18:01 -07001155 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1156 request = (MainThreadRequest) msg.obj;
1157 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1158 request);
1159 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1160 break;
1161
1162 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1163 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1164 break;
1165
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 case CMD_PERFORM_NETWORK_SCAN:
1167 request = (MainThreadRequest) msg.obj;
1168 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1169 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1170 break;
1171
Hall Liu27d24262020-09-18 19:04:59 -07001172 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001173 request = (MainThreadRequest) msg.obj;
1174 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001175 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1176 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1177 request.argument;
1178 int callForwardingReason = args.first;
1179 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
Hall Liu27d24262020-09-18 19:04:59 -07001181 }
1182 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001185 TelephonyManager.CallForwardingInfoCallback callback =
1186 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1187 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001188 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001189 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001190 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1191 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1192 // Service Class is a bit mask per 3gpp 27.007. Search for
1193 // any service for voice call.
1194 if ((callForwardInfo.serviceClass
1195 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001196 callForwardingInfo = new CallForwardingInfo(
1197 callForwardInfo.status
1198 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001199 callForwardInfo.reason,
1200 callForwardInfo.number,
1201 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001202 break;
1203 }
1204 }
1205 // Didn't find a call forward info for voice call.
1206 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001207 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1208 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001209 }
Hall Liu27d24262020-09-18 19:04:59 -07001210 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001211 } else {
1212 if (ar.result == null) {
1213 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1214 }
1215 if (ar.exception != null) {
1216 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1217 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001218 int errorCode = TelephonyManager
1219 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001220 if (ar.exception instanceof CommandException) {
1221 CommandException.Error error =
1222 ((CommandException) (ar.exception)).getCommandError();
1223 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001224 errorCode = TelephonyManager
1225 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001226 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001227 errorCode = TelephonyManager
1228 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001229 }
1230 }
Hall Liu27d24262020-09-18 19:04:59 -07001231 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 }
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 request = (MainThreadRequest) msg.obj;
1238 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001239 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001240 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001241 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1242 request.argument).first;
1243 request.phone.setCallForwardingOption(
1244 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001245 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001246 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001247 callForwardingInfoToSet.getReason(),
1248 callForwardingInfoToSet.getNumber(),
1249 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1250 break;
Hall Liu27d24262020-09-18 19:04:59 -07001251 }
Shuo Qian4a594052020-01-23 11:59:30 -08001252
Hall Liu27d24262020-09-18 19:04:59 -07001253 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001254 ar = (AsyncResult) msg.obj;
1255 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001256 Consumer<Integer> callback =
1257 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1258 request.argument).second;
1259 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001260 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001261 int errorCode = TelephonyManager.CallForwardingInfoCallback
1262 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001263 if (ar.exception instanceof CommandException) {
1264 CommandException.Error error =
1265 ((CommandException) (ar.exception)).getCommandError();
1266 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001267 errorCode = TelephonyManager.CallForwardingInfoCallback
1268 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001269 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001270 errorCode = TelephonyManager.CallForwardingInfoCallback
1271 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001272 }
1273 }
1274 callback.accept(errorCode);
1275 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001276 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001277 }
Shuo Qian4a594052020-01-23 11:59:30 -08001278 break;
Hall Liu27d24262020-09-18 19:04:59 -07001279 }
Shuo Qian4a594052020-01-23 11:59:30 -08001280
Hall Liu27d24262020-09-18 19:04:59 -07001281 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001282 request = (MainThreadRequest) msg.obj;
1283 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1284 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1285 break;
Hall Liu27d24262020-09-18 19:04:59 -07001286 }
Shuo Qian4a594052020-01-23 11:59:30 -08001287
Hall Liu27d24262020-09-18 19:04:59 -07001288 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001289 ar = (AsyncResult) msg.obj;
1290 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001291 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001292 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001293 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001294 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001295 // Service Class is a bit mask per 3gpp 27.007.
1296 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001297 if (callForwardResults.length > 1
1298 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001299 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001301 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1302 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001303 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001304 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001305 }
1306 } else {
1307 if (ar.result == null) {
1308 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1309 }
1310 if (ar.exception != null) {
1311 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1312 }
1313 if (ar.exception instanceof CommandException) {
1314 CommandException.Error error =
1315 ((CommandException) (ar.exception)).getCommandError();
1316 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001317 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001318 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001319 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1320 callWaitingStatus =
1321 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001322 }
1323 }
1324 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001325 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001326 break;
Hall Liu27d24262020-09-18 19:04:59 -07001327 }
Shuo Qian4a594052020-01-23 11:59:30 -08001328
Hall Liu27d24262020-09-18 19:04:59 -07001329 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001332 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1333 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001334 break;
Hall Liu27d24262020-09-18 19:04:59 -07001335 }
Shuo Qian4a594052020-01-23 11:59:30 -08001336
Hall Liu27d24262020-09-18 19:04:59 -07001337 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001340 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1341 Consumer<Integer> callback =
1342 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1343 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001344 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001345 if (ar.exception instanceof CommandException) {
1346 CommandException.Error error =
1347 ((CommandException) (ar.exception)).getCommandError();
1348 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1349 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001350 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1351 callback.accept(
1352 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001353 } else {
1354 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1355 }
1356 } else {
1357 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1358 }
1359 } else {
1360 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1361 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001362 }
Shuo Qian4a594052020-01-23 11:59:30 -08001363 break;
Hall Liu27d24262020-09-18 19:04:59 -07001364 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001365 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 CellNetworkScanResult cellScanResult;
1369 if (ar.exception == null && ar.result != null) {
1370 cellScanResult = new CellNetworkScanResult(
1371 CellNetworkScanResult.STATUS_SUCCESS,
1372 (List<OperatorInfo>) ar.result);
1373 } else {
1374 if (ar.result == null) {
1375 loge("getCellNetworkScanResults: Empty response");
1376 }
1377 if (ar.exception != null) {
1378 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1379 }
1380 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1381 if (ar.exception instanceof CommandException) {
1382 CommandException.Error error =
1383 ((CommandException) (ar.exception)).getCommandError();
1384 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1385 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1386 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1387 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1388 }
1389 }
1390 cellScanResult = new CellNetworkScanResult(errorCode, null);
1391 }
1392 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001394 break;
1395
1396 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1397 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001398 ManualNetworkSelectionArgument selArg =
1399 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001400 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1401 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001402 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1403 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001404 break;
1405
1406 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 if (ar.exception == null) {
1410 request.result = true;
1411 } else {
1412 request.result = false;
1413 loge("setNetworkSelectionModeManual " + ar.exception);
1414 }
1415 notifyRequester(request);
1416 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001417 break;
1418
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001419 case CMD_GET_MODEM_ACTIVITY_INFO:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001422 if (defaultPhone != null) {
1423 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001424 } else {
1425 ResultReceiver result = (ResultReceiver) request.argument;
1426 Bundle bundle = new Bundle();
1427 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001428 new ModemActivityInfo(0, 0, 0,
1429 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001430 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001431 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 break;
1433
Hall Liud0f208c2020-10-14 16:54:44 -07001434 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001435 ar = (AsyncResult) msg.obj;
1436 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001438 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001439 if (mLastModemActivityInfo == null) {
1440 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1441 mLastModemActivitySpecificInfo[0] =
1442 new ActivityStatsTechSpecificInfo(
1443 0,
1444 0,
1445 new int[ModemActivityInfo.getNumTxPowerLevels()],
1446 0);
1447 mLastModemActivityInfo =
1448 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1449 }
1450
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001451 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001452 // Update the last modem activity info and the result of the request.
1453 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1454 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001455 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001456 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001457 mLastModemActivityInfo =
1458 new ModemActivityInfo(
1459 mLastModemActivityInfo.getTimestampMillis(),
1460 mLastModemActivityInfo.getSleepTimeMillis(),
1461 mLastModemActivityInfo.getIdleTimeMillis(),
1462 mLastModemActivitySpecificInfo);
1463
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001464 } else {
1465 if (ar.result == null) {
1466 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001467 error = TelephonyManager.ModemActivityInfoException
1468 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001469 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001470 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001471 error = TelephonyManager.ModemActivityInfoException
1472 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001473 } else {
1474 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001475 error = TelephonyManager.ModemActivityInfoException
1476 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001477 }
1478 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001479 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001480 if (mLastModemActivityInfo != null) {
1481 bundle.putParcelable(
1482 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1483 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001484 } else {
1485 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1486 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001487 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001488 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001489 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001490 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001491
Meng Wang1a7c35a2016-05-05 20:56:15 -07001492 case CMD_SET_ALLOWED_CARRIERS:
1493 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001494 CarrierRestrictionRules argument =
1495 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001497 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001498 break;
1499
1500 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 if (ar.exception == null && ar.result != null) {
1504 request.result = ar.result;
1505 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001506 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1507 if (ar.exception instanceof CommandException) {
1508 loge("setAllowedCarriers: CommandException: " + ar.exception);
1509 CommandException.Error error =
1510 ((CommandException) (ar.exception)).getCommandError();
1511 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1512 request.result =
1513 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1514 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001515 } else {
1516 loge("setAllowedCarriers: Unknown exception");
1517 }
1518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001519 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001520 break;
1521
1522 case CMD_GET_ALLOWED_CARRIERS:
1523 request = (MainThreadRequest) msg.obj;
1524 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001525 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001526 break;
1527
1528 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception == null && ar.result != null) {
1532 request.result = ar.result;
1533 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001534 request.result = new IllegalStateException(
1535 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001536 if (ar.result == null) {
1537 loge("getAllowedCarriers: Empty response");
1538 } else if (ar.exception instanceof CommandException) {
1539 loge("getAllowedCarriers: CommandException: " +
1540 ar.exception);
1541 } else {
1542 loge("getAllowedCarriers: Unknown exception");
1543 }
1544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001545 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001546 break;
1547
Nathan Haroldb3014052017-01-25 15:57:32 -08001548 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 if (ar.exception == null && ar.result != null) {
1552 request.result = ar.result;
1553 } else {
1554 request.result = new IllegalArgumentException(
1555 "Failed to retrieve Forbidden Plmns");
1556 if (ar.result == null) {
1557 loge("getForbiddenPlmns: Empty response");
1558 } else {
1559 loge("getForbiddenPlmns: Unknown exception");
1560 }
1561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 break;
1564
1565 case CMD_GET_FORBIDDEN_PLMNS:
1566 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001567 uiccPort = getUiccPortFromRequest(request);
1568 if (uiccPort == null) {
1569 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001570 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001571 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001573 break;
1574 }
1575 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001576 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001577 if (uiccApp == null) {
1578 loge("getForbiddenPlmns() no app with specified type -- "
1579 + appType);
1580 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001581 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001582 break;
1583 } else {
1584 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1585 + " specified type -- " + appType);
1586 }
1587 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1588 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1589 onCompleted);
1590 break;
1591
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001592 case CMD_SWITCH_SLOTS:
1593 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001594 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001595 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001596 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001597 break;
1598
1599 case EVENT_SWITCH_SLOTS_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001603 notifyRequester(request);
1604 break;
1605 case CMD_GET_NETWORK_SELECTION_MODE:
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1608 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1609 break;
1610
1611 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1612 ar = (AsyncResult) msg.obj;
1613 request = (MainThreadRequest) ar.userObj;
1614 if (ar.exception != null) {
1615 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1616 } else {
1617 int mode = ((int[]) ar.result)[0];
1618 if (mode == 0) {
1619 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1620 } else {
1621 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1622 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001624 notifyRequester(request);
1625 break;
1626 case CMD_GET_CDMA_ROAMING_MODE:
1627 request = (MainThreadRequest) msg.obj;
1628 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1629 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1630 break;
1631 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception != null) {
1635 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1636 } else {
1637 request.result = ((int[]) ar.result)[0];
1638 }
1639 notifyRequester(request);
1640 break;
1641 case CMD_SET_CDMA_ROAMING_MODE:
1642 request = (MainThreadRequest) msg.obj;
1643 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1644 int mode = (int) request.argument;
1645 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1646 break;
1647 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 request.result = ar.exception == null;
1651 notifyRequester(request);
1652 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001653 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1654 request = (MainThreadRequest) msg.obj;
1655 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1656 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1657 break;
1658 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 if (ar.exception != null) {
1662 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1663 } else {
1664 request.result = ((int[]) ar.result)[0];
1665 }
1666 notifyRequester(request);
1667 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001668 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1671 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001672 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1673 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001674 break;
1675 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 request.result = ar.exception == null;
1679 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001680 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001681 case CMD_GET_ALL_CELL_INFO:
1682 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001683 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001684 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001685 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001686 case EVENT_GET_ALL_CELL_INFO_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001689 // If a timeout occurs, the response will be null
1690 request.result = (ar.exception == null && ar.result != null)
1691 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001692 synchronized (request) {
1693 request.notifyAll();
1694 }
1695 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 case CMD_REQUEST_CELL_INFO_UPDATE:
1697 request = (MainThreadRequest) msg.obj;
1698 request.phone.requestCellInfoUpdate(request.workSource,
1699 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1700 break;
1701 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1702 ar = (AsyncResult) msg.obj;
1703 request = (MainThreadRequest) ar.userObj;
1704 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1705 try {
1706 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001707 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001708 cb.onError(
1709 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1710 ar.exception.getClass().getName(),
1711 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001712 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001713 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001714 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001715 } else {
1716 // use the result as returned
1717 cb.onCellInfo((List<CellInfo>) ar.result);
1718 }
1719 } catch (RemoteException re) {
1720 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1721 }
1722 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001724 request = (MainThreadRequest) msg.obj;
1725 WorkSource ws = (WorkSource) request.argument;
1726 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001727 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001728 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001729 }
1730 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001731 ar = (AsyncResult) msg.obj;
1732 request = (MainThreadRequest) ar.userObj;
1733 if (ar.exception == null) {
1734 request.result = ar.result;
1735 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001736 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001737 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001738 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001739 }
1740
1741 synchronized (request) {
1742 request.notifyAll();
1743 }
1744 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001745 }
chen xu6dac5ab2018-10-26 17:39:23 -07001746 case CMD_MODEM_REBOOT:
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001749 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001750 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001751 case EVENT_CMD_MODEM_REBOOT_DONE:
1752 handleNullReturnEvent(msg, "rebootModem");
1753 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001754 case CMD_REQUEST_ENABLE_MODEM:
1755 request = (MainThreadRequest) msg.obj;
1756 boolean enable = (boolean) request.argument;
1757 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001758 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001759 PhoneConfigurationManager.getInstance()
1760 .enablePhone(request.phone, enable, onCompleted);
1761 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001762 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001763 ar = (AsyncResult) msg.obj;
1764 request = (MainThreadRequest) ar.userObj;
1765 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001766 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001767 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001768 if ((boolean) request.result) {
1769 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1770 updateModemStateMetrics();
1771 } else {
1772 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1773 + ar.exception);
1774 }
1775 notifyRequester(request);
1776 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001777 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001778 case CMD_GET_MODEM_STATUS:
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1781 PhoneConfigurationManager.getInstance()
1782 .getPhoneStatusFromModem(request.phone, onCompleted);
1783 break;
1784 case EVENT_GET_MODEM_STATUS_DONE:
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787 int id = request.phone.getPhoneId();
1788 if (ar.exception == null && ar.result != null) {
1789 request.result = ar.result;
1790 //update the cache as modem status has changed
1791 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1792 (boolean) request.result);
1793 } else {
1794 // Return true if modem status cannot be retrieved. For most cases,
1795 // modem status is on. And for older version modems, GET_MODEM_STATUS
1796 // and disable modem are not supported. Modem is always on.
1797 // TODO: this should be fixed in R to support a third
1798 // status UNKNOWN b/131631629
1799 request.result = true;
1800 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1801 + ar.exception);
1802 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001803 notifyRequester(request);
1804 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001805 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1806 request = (MainThreadRequest) msg.obj;
1807 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1808 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1809 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1810 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1811 break;
1812 }
1813 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1814 ar = (AsyncResult) msg.obj;
1815 request = (MainThreadRequest) ar.userObj;
1816 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1817 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1818 args.second.accept(ar.exception == null);
1819 notifyRequester(request);
1820 break;
1821 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001822 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1823 request = (MainThreadRequest) msg.obj;
1824 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1825 Phone phone = getPhoneFromRequest(request);
1826 if (phone != null) {
1827 phone.getSystemSelectionChannels(onCompleted);
1828 } else {
1829 loge("getSystemSelectionChannels: No phone object");
1830 request.result = new ArrayList<RadioAccessSpecifier>();
1831 notifyRequester(request);
1832 }
1833 break;
1834 }
1835 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1836 ar = (AsyncResult) msg.obj;
1837 request = (MainThreadRequest) ar.userObj;
1838 if (ar.exception == null && ar.result != null) {
1839 request.result = ar.result;
1840 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001841 request.result = new IllegalStateException(
1842 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001843 if (ar.result == null) {
1844 loge("getSystemSelectionChannels: Empty response");
1845 } else {
1846 loge("getSystemSelectionChannels: Unknown exception");
1847 }
1848 }
1849 notifyRequester(request);
1850 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001851 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1852 ar = (AsyncResult) msg.obj;
1853 request = (MainThreadRequest) ar.userObj;
1854 if (ar.exception == null && ar.result != null) {
1855 request.result = ar.result;
1856 } else {
1857 request.result = -1;
1858 loge("Failed to set Forbidden Plmns");
1859 if (ar.result == null) {
1860 loge("setForbidenPlmns: Empty response");
1861 } else if (ar.exception != null) {
1862 loge("setForbiddenPlmns: Exception: " + ar.exception);
1863 request.result = -1;
1864 } else {
1865 loge("setForbiddenPlmns: Unknown exception");
1866 }
1867 }
1868 notifyRequester(request);
1869 break;
1870 case CMD_SET_FORBIDDEN_PLMNS:
1871 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001872 uiccPort = getUiccPortFromRequest(request);
1873 if (uiccPort == null) {
1874 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001875 request.result = -1;
1876 notifyRequester(request);
1877 break;
1878 }
1879 Pair<Integer, List<String>> setFplmnsArgs =
1880 (Pair<Integer, List<String>>) request.argument;
1881 appType = setFplmnsArgs.first;
1882 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001883 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001884 if (uiccApp == null) {
1885 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1886 request.result = -1;
1887 loge("Failed to get UICC App");
1888 notifyRequester(request);
1889 } else {
1890 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1891 ((SIMRecords) uiccApp.getIccRecords())
1892 .setForbiddenPlmns(onCompleted, fplmns);
1893 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001894 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001895 case CMD_ERASE_MODEM_CONFIG:
1896 request = (MainThreadRequest) msg.obj;
1897 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1898 defaultPhone.eraseModemConfig(onCompleted);
1899 break;
1900 case EVENT_ERASE_MODEM_CONFIG_DONE:
1901 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001902 break;
zoey chene02881a2019-12-30 16:11:23 +08001903
Kai Shif70f46f2021-03-03 13:59:46 -08001904 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1905 request = (MainThreadRequest) msg.obj;
1906 request.result = defaultPhone.eraseDataInSharedPreferences();
1907 notifyRequester(request);
1908 break;
1909
zoey chene02881a2019-12-30 16:11:23 +08001910 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1911 request = (MainThreadRequest) msg.obj;
1912 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1913 Pair<String, String> changed = (Pair<String, String>) request.argument;
1914 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1915 changed.first, changed.second, onCompleted);
1916 break;
1917 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1918 ar = (AsyncResult) msg.obj;
1919 request = (MainThreadRequest) ar.userObj;
1920 if (ar.exception == null) {
1921 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001922 // If the operation is successful, update the PIN storage
1923 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1924 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001925 UiccController.getInstance().getPinStorage()
1926 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001927 } else {
1928 request.result = msg.arg1;
1929 }
1930 notifyRequester(request);
1931 break;
1932
Michele Berionne5e411512020-11-13 02:36:59 +00001933 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001934 request = (MainThreadRequest) msg.obj;
1935 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1936 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1937 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1938 enabled.first, enabled.second, onCompleted);
1939 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001940 }
zoey chene02881a2019-12-30 16:11:23 +08001941 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1942 ar = (AsyncResult) msg.obj;
1943 request = (MainThreadRequest) ar.userObj;
1944 if (ar.exception == null) {
1945 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001946 // If the operation is successful, update the PIN storage
1947 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1948 int phoneId = getPhoneFromRequest(request).getPhoneId();
1949 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001950 UiccController.getInstance().getPinStorage()
1951 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001952 } else {
1953 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1954 }
zoey chene02881a2019-12-30 16:11:23 +08001955 } else {
1956 request.result = msg.arg1;
1957 }
Michele Berionne5e411512020-11-13 02:36:59 +00001958
1959
zoey chene02881a2019-12-30 16:11:23 +08001960 notifyRequester(request);
1961 break;
1962
Peter Wangdafb9ac2020-01-15 14:13:38 -08001963 case MSG_NOTIFY_USER_ACTIVITY:
1964 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001965 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001966 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1967 getDefaultPhone().getContext().sendBroadcastAsUser(
1968 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1969 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001970
1971 case CMD_SET_DATA_THROTTLING: {
1972 request = (MainThreadRequest) msg.obj;
1973 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1974 DataThrottlingRequest dataThrottlingRequest =
1975 (DataThrottlingRequest) request.argument;
1976 Phone phone = getPhoneFromRequest(request);
1977 if (phone != null) {
1978 phone.setDataThrottling(onCompleted,
1979 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1980 dataThrottlingRequest.getCompletionDurationMillis());
1981 } else {
1982 loge("setDataThrottling: No phone object");
1983 request.result =
1984 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1985 notifyRequester(request);
1986 }
1987
1988 break;
1989 }
1990 case EVENT_SET_DATA_THROTTLING_DONE:
1991 ar = (AsyncResult) msg.obj;
1992 request = (MainThreadRequest) ar.userObj;
1993
1994 if (ar.exception == null) {
1995 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1996 } else if (ar.exception instanceof CommandException) {
1997 loge("setDataThrottling: CommandException: " + ar.exception);
1998 CommandException.Error error =
1999 ((CommandException) (ar.exception)).getCommandError();
2000
2001 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
2002 request.result = TelephonyManager
2003 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
2004 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2005 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08002006 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2007 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08002008 } else {
2009 request.result =
2010 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2011 }
2012 } else {
2013 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
2014 }
2015 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
2016 notifyRequester(request);
2017 break;
Jordan Liu109698e2020-11-24 14:50:34 -08002018
2019 case CMD_SET_SIM_POWER: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2022 request = (MainThreadRequest) msg.obj;
2023 int stateToSet =
2024 ((Pair<Integer, IIntegerConsumer>)
2025 request.argument).first;
2026 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2027 break;
2028 }
2029 case EVENT_SET_SIM_POWER_DONE: {
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 IIntegerConsumer callback =
2033 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2034 if (ar.exception != null) {
2035 loge("setSimPower exception: " + ar.exception);
2036 int errorCode = TelephonyManager.CallForwardingInfoCallback
2037 .RESULT_ERROR_UNKNOWN;
2038 if (ar.exception instanceof CommandException) {
2039 CommandException.Error error =
2040 ((CommandException) (ar.exception)).getCommandError();
2041 if (error == CommandException.Error.SIM_ERR) {
2042 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2043 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2044 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2045 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2046 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2047 } else {
2048 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2049 }
2050 }
2051 try {
2052 callback.accept(errorCode);
2053 } catch (RemoteException e) {
2054 // Ignore if the remote process is no longer available to call back.
2055 Log.w(LOG_TAG, "setSimPower: callback not available.");
2056 }
2057 } else {
2058 try {
2059 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2060 } catch (RemoteException e) {
2061 // Ignore if the remote process is no longer available to call back.
2062 Log.w(LOG_TAG, "setSimPower: callback not available.");
2063 }
2064 }
2065 break;
2066 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002067 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2068 request = (MainThreadRequest) msg.obj;
2069
2070 final Phone phone = getPhoneFromRequest(request);
2071 if (phone == null || phone.getServiceStateTracker() == null) {
2072 request.result = new IllegalStateException("Phone or SST is null");
2073 notifyRequester(request);
2074 break;
2075 }
2076
2077 Pair<Integer, SignalStrengthUpdateRequest> pair =
2078 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2079 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2080 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002081 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002082 request.subId, pair.first /*callingUid*/,
2083 pair.second /*request*/, onCompleted);
2084 break;
2085 }
2086 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2087 ar = (AsyncResult) msg.obj;
2088 request = (MainThreadRequest) ar.userObj;
2089 // request.result will be the exception of ar if present, true otherwise.
2090 // Be cautious not to leave result null which will wait() forever
2091 request.result = ar.exception != null ? ar.exception : true;
2092 notifyRequester(request);
2093 break;
2094 }
2095 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2096 request = (MainThreadRequest) msg.obj;
2097
2098 Phone phone = getPhoneFromRequest(request);
2099 if (phone == null || phone.getServiceStateTracker() == null) {
2100 request.result = new IllegalStateException("Phone or SST is null");
2101 notifyRequester(request);
2102 break;
2103 }
2104
2105 Pair<Integer, SignalStrengthUpdateRequest> pair =
2106 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2107 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2108 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002109 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002110 request.subId, pair.first /*callingUid*/,
2111 pair.second /*request*/, onCompleted);
2112 break;
2113 }
2114 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2115 ar = (AsyncResult) msg.obj;
2116 request = (MainThreadRequest) ar.userObj;
2117 request.result = ar.exception != null ? ar.exception : true;
2118 notifyRequester(request);
2119 break;
2120 }
Jordan Liu109698e2020-11-24 14:50:34 -08002121
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002122 case CMD_GET_SLICING_CONFIG: {
2123 request = (MainThreadRequest) msg.obj;
2124 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2125 request.phone.getSlicingConfig(onCompleted);
2126 break;
2127 }
2128 case EVENT_GET_SLICING_CONFIG_DONE: {
2129 ar = (AsyncResult) msg.obj;
2130 request = (MainThreadRequest) ar.userObj;
2131 ResultReceiver result = (ResultReceiver) request.argument;
2132
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002133 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002134 Bundle bundle = new Bundle();
2135 int resultCode = 0;
2136 if (ar.exception != null) {
2137 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2138 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002139 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002140 } else if (ar.result == null) {
2141 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002142 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002143 } else {
2144 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002145 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2146 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002147 }
2148
2149 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002150 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002151 }
2152 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2153 result.send(resultCode, bundle);
2154 notifyRequester(request);
2155 break;
2156 }
2157
Sarah Chin71b3a852022-09-28 15:54:19 -07002158 case CMD_PURCHASE_PREMIUM_CAPABILITY: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002159 request = (MainThreadRequest) msg.obj;
2160 onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request);
Sarah Chin71b3a852022-09-28 15:54:19 -07002161 PurchasePremiumCapabilityArgument arg =
2162 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002163 SliceStore.getInstance(request.phone).purchasePremiumCapability(
Sarah Chin71b3a852022-09-28 15:54:19 -07002164 arg.capability, arg.appName, onCompleted);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002165 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002166 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002167
Sarah Chin71b3a852022-09-28 15:54:19 -07002168 case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: {
Sarah Chin2ec39f62022-08-31 17:03:26 -07002169 ar = (AsyncResult) msg.obj;
2170 request = (MainThreadRequest) ar.userObj;
Sarah Chin71b3a852022-09-28 15:54:19 -07002171 PurchasePremiumCapabilityArgument arg =
2172 (PurchasePremiumCapabilityArgument) request.argument;
Sarah Chin2ec39f62022-08-31 17:03:26 -07002173 try {
2174 int result = (int) ar.result;
Sarah Chin71b3a852022-09-28 15:54:19 -07002175 arg.callback.accept(result);
Sarah Chin2ec39f62022-08-31 17:03:26 -07002176 log("purchasePremiumCapability: capability="
Sarah Chin71b3a852022-09-28 15:54:19 -07002177 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002178 + ", result= "
2179 + TelephonyManager.convertPurchaseResultToString(result));
2180 } catch (RemoteException e) {
2181 String logStr = "Purchase premium capability "
Sarah Chin71b3a852022-09-28 15:54:19 -07002182 + TelephonyManager.convertPremiumCapabilityToString(arg.capability)
Sarah Chin2ec39f62022-08-31 17:03:26 -07002183 + " failed: " + e;
2184 if (DBG) log(logStr);
2185 AnomalyReporter.reportAnomaly(
2186 UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr);
2187 }
2188 break;
Sarah Chin71b3a852022-09-28 15:54:19 -07002189 }
Sarah Chin2ec39f62022-08-31 17:03:26 -07002190
Michele Berionne5e411512020-11-13 02:36:59 +00002191 case CMD_PREPARE_UNATTENDED_REBOOT:
2192 request = (MainThreadRequest) msg.obj;
2193 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002194 UiccController.getInstance().getPinStorage()
2195 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002196 notifyRequester(request);
2197 break;
2198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 default:
2200 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2201 break;
2202 }
2203 }
Jake Hambye994d462014-02-03 13:10:13 -08002204
Pengquan Menga1bb6272018-09-06 09:59:22 -07002205 private void notifyRequester(MainThreadRequest request) {
2206 synchronized (request) {
2207 request.notifyAll();
2208 }
2209 }
2210
Jake Hambye994d462014-02-03 13:10:13 -08002211 private void handleNullReturnEvent(Message msg, String command) {
2212 AsyncResult ar = (AsyncResult) msg.obj;
2213 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2214 if (ar.exception == null) {
2215 request.result = true;
2216 } else {
2217 request.result = false;
2218 if (ar.exception instanceof CommandException) {
2219 loge(command + ": CommandException: " + ar.exception);
2220 } else {
2221 loge(command + ": Unknown exception");
2222 }
2223 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002224 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 }
2227
2228 /**
2229 * Posts the specified command to be executed on the main thread,
2230 * waits for the request to complete, and returns the result.
2231 * @see #sendRequestAsync
2232 */
2233 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002234 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2235 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002236 }
2237
2238 /**
2239 * Posts the specified command to be executed on the main thread,
2240 * waits for the request to complete, and returns the result.
2241 * @see #sendRequestAsync
2242 */
2243 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2244 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002245 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002246 }
2247
2248 /**
2249 * Posts the specified command to be executed on the main thread,
2250 * waits for the request to complete, and returns the result.
2251 * @see #sendRequestAsync
2252 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002253 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002254 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2255 }
2256
2257 /**
2258 * Posts the specified command to be executed on the main thread,
2259 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2260 * if not timeout or null otherwise.
2261 * @see #sendRequestAsync
2262 */
2263 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2264 long timeoutInMs) {
2265 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002266 }
2267
2268 /**
2269 * Posts the specified command to be executed on the main thread,
2270 * waits for the request to complete, and returns the result.
2271 * @see #sendRequestAsync
2272 */
Nathan Harold92bed182018-10-12 18:16:49 -07002273 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002274 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002275 }
2276
2277 /**
2278 * Posts the specified command to be executed on the main thread,
2279 * waits for the request to complete, and returns the result.
2280 * @see #sendRequestAsync
2281 */
2282 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002283 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2284 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002285 }
2286
2287 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002288 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2289 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2290 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002291 * @see #sendRequestAsync
2292 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002293 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2294 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2296 throw new RuntimeException("This method will deadlock if called from the main thread.");
2297 }
2298
Nathan Harold92bed182018-10-12 18:16:49 -07002299 MainThreadRequest request = null;
2300 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2301 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2302 } else if (phone != null) {
2303 request = new MainThreadRequest(argument, phone, workSource);
2304 } else {
2305 request = new MainThreadRequest(argument, subId, workSource);
2306 }
2307
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308 Message msg = mMainThreadHandler.obtainMessage(command, request);
2309 msg.sendToTarget();
2310
Rambo Wang0f050d82021-02-12 11:43:36 -08002311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002313 if (timeoutInMs >= 0) {
2314 // Wait for at least timeoutInMs before returning null request result
2315 long now = SystemClock.elapsedRealtime();
2316 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002317 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002318 try {
2319 request.wait(deadline - now);
2320 } catch (InterruptedException e) {
2321 // Do nothing, go back and check if request is completed or timeout
2322 } finally {
2323 now = SystemClock.elapsedRealtime();
2324 }
2325 }
2326 } else {
2327 // Wait for the request to complete
2328 while (request.result == null) {
2329 try {
2330 request.wait();
2331 } catch (InterruptedException e) {
2332 // Do nothing, go back and wait until the request is complete
2333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335 }
2336 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002337 if (request.result == null) {
2338 Log.wtf(LOG_TAG,
2339 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 return request.result;
2342 }
2343
2344 /**
2345 * Asynchronous ("fire and forget") version of sendRequest():
2346 * Posts the specified command to be executed on the main thread, and
2347 * returns immediately.
2348 * @see #sendRequest
2349 */
2350 private void sendRequestAsync(int command) {
2351 mMainThreadHandler.sendEmptyMessage(command);
2352 }
2353
2354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002357 */
2358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002359 sendRequestAsync(command, argument, null, null);
2360 }
2361
2362 /**
2363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2364 * @see {@link #sendRequest(int,Object)}
2365 */
2366 private void sendRequestAsync(
2367 int command, Object argument, Phone phone, WorkSource workSource) {
2368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002369 Message msg = mMainThreadHandler.obtainMessage(command, request);
2370 msg.sendToTarget();
2371 }
2372
2373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 * Initialize the singleton PhoneInterfaceManager instance.
2375 * This is only done once, at startup, from PhoneApp.onCreate().
2376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 synchronized (PhoneInterfaceManager.class) {
2379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 } else {
2382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2383 }
2384 return sInstance;
2385 }
2386 }
2387
2388 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002392 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002395 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002398 mTelephonySharedPreferences =
2399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002402 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002403 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002404 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002405 mTelephony2gUpdater = new Telephony2gUpdater(
2406 Executors.newSingleThreadExecutor(), mApp);
2407 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 publish();
2409 }
2410
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002411 private Phone getDefaultPhone() {
2412 Phone thePhone = getPhone(getDefaultSubscription());
2413 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 private void publish() {
2417 if (DBG) log("publish: " + this);
2418
Peter Wangc035ce42020-01-08 21:00:22 -08002419 TelephonyFrameworkInitializer
2420 .getTelephonyServiceManager()
2421 .getTelephonyServiceRegisterer()
2422 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424
Stuart Scott584921c2015-01-15 17:10:34 -08002425 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002426 if (request.phone != null) {
2427 return request.phone;
2428 } else {
2429 return getPhoneFromSubId(request.subId);
2430 }
2431 }
2432
2433 private Phone getPhoneFromSubId(int subId) {
2434 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2435 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002436 }
2437
Rambo Wange53e07d2022-05-10 13:01:13 -07002438 @Nullable
2439 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 Phone phone = getPhoneFromRequest(request);
2441 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002442 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002443 }
2444
Wink Saville36469e72014-06-11 15:17:00 -07002445 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002447 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449
Kai Shif70f46f2021-03-03 13:59:46 -08002450 private void sendEraseModemConfig(@NonNull Phone phone) {
2451 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2452 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2453 }
2454
2455 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2456 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2457 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002458 }
2459
Peter Wang44b186e2020-01-13 23:33:09 -08002460 private boolean isImsAvailableOnDevice() {
2461 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2462 if (pm == null) {
2463 // For some reason package manger is not available.. This will fail internally anyway,
2464 // so do not throw error and allow.
2465 return true;
2466 }
2467 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2468 }
2469
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002471 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002472 }
2473
Wink Savilleb564aae2014-10-23 10:18:09 -07002474 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 if (DBG) log("dial: " + number);
2476 // No permission check needed here: This is just a wrapper around the
2477 // ACTION_DIAL intent, which is available to any app since it puts up
2478 // the UI before it does anything.
2479
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 String url = createTelUrl(number);
2483 if (url == null) {
2484 return;
2485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002487 // PENDING: should we just silently fail if phone is offhook or ringing?
2488 PhoneConstants.State state = mCM.getState(subId);
2489 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2490 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2492 mApp.startActivity(intent);
2493 }
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497 }
2498
2499 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002500 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 if (DBG) log("call: " + number);
2505
2506 // This is just a wrapper around the ACTION_CALL intent, but we still
2507 // need to do a permission check since we're calling startActivity()
2508 // from the context of the phone app.
2509 enforceCallPermission();
2510
Jordan Liu1617b712019-07-10 15:06:26 -07002511 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002512 != AppOpsManager.MODE_ALLOWED) {
2513 return;
2514 }
2515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 String url = createTelUrl(number);
2519 if (url == null) {
2520 return;
2521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 boolean isValid = false;
2524 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2525 if (slist != null) {
2526 for (SubscriptionInfo subInfoRecord : slist) {
2527 if (subInfoRecord.getSubscriptionId() == subId) {
2528 isValid = true;
2529 break;
2530 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002531 }
Wink Saville08874612014-08-31 19:19:58 -07002532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 if (!isValid) {
2534 return;
2535 }
Wink Saville08874612014-08-31 19:19:58 -07002536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2538 intent.putExtra(SUBSCRIPTION_KEY, subId);
2539 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2540 mApp.startActivity(intent);
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 }
2545
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002547 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002548 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2549 }
2550
Wink Savilleb564aae2014-10-23 10:18:09 -07002551 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002552 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002553 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2554 }
2555
Wink Savilleb564aae2014-10-23 10:18:09 -07002556 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558
2559 final long identity = Binder.clearCallingIdentity();
2560 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002561 Phone phone = getPhone(subId);
2562 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 checkSimPin.start();
2564 return checkSimPin.unlockSim(null, pin);
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002575 Phone phone = getPhone(subId);
2576 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 checkSimPuk.start();
2578 return checkSimPuk.unlockSim(puk, pin);
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002585 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 * a synchronous one.
2587 */
2588 private static class UnlockSim extends Thread {
2589
2590 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002591 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002592
2593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596
2597 // For replies from SimCard interface
2598 private Handler mHandler;
2599
2600 // For async handler to identify request type
2601 private static final int SUPPLY_PIN_COMPLETE = 100;
2602
Michele Berionne5e411512020-11-13 02:36:59 +00002603 UnlockSim(int phoneId, IccCard simCard) {
2604 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 mSimCard = simCard;
2606 }
2607
2608 @Override
2609 public void run() {
2610 Looper.prepare();
2611 synchronized (UnlockSim.this) {
2612 mHandler = new Handler() {
2613 @Override
2614 public void handleMessage(Message msg) {
2615 AsyncResult ar = (AsyncResult) msg.obj;
2616 switch (msg.what) {
2617 case SUPPLY_PIN_COMPLETE:
2618 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2619 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002620 mRetryCount = msg.arg1;
2621 if (ar.exception != null) {
2622 if (ar.exception instanceof CommandException &&
2623 ((CommandException)(ar.exception)).getCommandError()
2624 == CommandException.Error.PASSWORD_INCORRECT) {
2625 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002626 } //When UiccCardApp dispose,handle message and return exception
2627 else if (ar.exception instanceof CommandException &&
2628 ((CommandException) (ar.exception)).getCommandError()
2629 == CommandException.Error.ABORTED) {
2630 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002631 } else {
2632 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2633 }
2634 } else {
2635 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 mDone = true;
2638 UnlockSim.this.notifyAll();
2639 }
2640 break;
2641 }
2642 }
2643 };
2644 UnlockSim.this.notifyAll();
2645 }
2646 Looper.loop();
2647 }
2648
2649 /*
2650 * Use PIN or PUK to unlock SIM card
2651 *
2652 * If PUK is null, unlock SIM card with PIN
2653 *
2654 * If PUK is not null, unlock SIM card with PUK and set PIN code
2655 */
Wink Saville9de0f752013-10-22 19:04:03 -07002656 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657
2658 while (mHandler == null) {
2659 try {
2660 wait();
2661 } catch (InterruptedException e) {
2662 Thread.currentThread().interrupt();
2663 }
2664 }
2665 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2666
2667 if (puk == null) {
2668 mSimCard.supplyPin(pin, callback);
2669 } else {
2670 mSimCard.supplyPuk(puk, pin, callback);
2671 }
2672
2673 while (!mDone) {
2674 try {
2675 Log.d(LOG_TAG, "wait for done");
2676 wait();
2677 } catch (InterruptedException e) {
2678 // Restore the interrupted status
2679 Thread.currentThread().interrupt();
2680 }
2681 }
2682 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002683 int[] resultArray = new int[2];
2684 resultArray[0] = mResult;
2685 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002686
2687 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002688 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002689 }
2690
Wink Saville9de0f752013-10-22 19:04:03 -07002691 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693 }
2694
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002695 /**
2696 * This method has been removed due to privacy and stability concerns.
2697 */
2698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002700 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2701 return;
Wink Saville36469e72014-06-11 15:17:00 -07002702 }
2703
Nathan Harold1f889d82020-06-04 17:05:26 -07002704 @Override
2705 public void updateServiceLocationWithPackageName(String callingPackage) {
2706 mApp.getSystemService(AppOpsManager.class)
2707 .checkPackage(Binder.getCallingUid(), callingPackage);
2708
Nathan Haroldf096d982020-11-18 17:18:06 -08002709 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002710 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2711 // Callers targeting S have no business invoking this method.
2712 return;
2713 }
2714
2715 LocationAccessPolicy.LocationPermissionResult locationResult =
2716 LocationAccessPolicy.checkLocationPermission(mApp,
2717 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2718 .setCallingPackage(callingPackage)
2719 .setCallingFeatureId(null)
2720 .setCallingPid(Binder.getCallingPid())
2721 .setCallingUid(Binder.getCallingUid())
2722 .setMethod("updateServiceLocation")
2723 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2724 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2725 .build());
2726 // Apps that lack location permission have no business calling this method;
2727 // however, because no permission was declared in the public API, denials must
2728 // all be "soft".
2729 switch (locationResult) {
2730 case DENIED_HARD: /* fall through */
2731 case DENIED_SOFT:
2732 return;
2733 }
2734
2735 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002738 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002740 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002747 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002748 @Override
2749 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002750 return isRadioOnWithFeature(callingPackage, null);
2751 }
2752
2753
2754 @Override
2755 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2756 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2757 callingFeatureId);
2758 }
2759
2760 @Deprecated
2761 @Override
2762 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2763 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002764 }
2765
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002767 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002770 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002771 return false;
2772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773
2774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 return isRadioOnForSubscriber(subId);
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002780 }
2781
2782 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
2785 final Phone phone = getPhone(subId);
2786 if (phone != null) {
2787 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
2796 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002797 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
Wink Saville36469e72014-06-11 15:17:00 -07002799
Wink Savilleb564aae2014-10-23 10:18:09 -07002800 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Wink Saville36469e72014-06-11 15:17:00 -07002812 }
2813
2814 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002815 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002816 }
2817
Wink Savilleb564aae2014-10-23 10:18:09 -07002818 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820
2821 final long identity = Binder.clearCallingIdentity();
2822 try {
2823 final Phone phone = getPhone(subId);
2824 if (phone == null) {
2825 return false;
2826 }
2827 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2828 toggleRadioOnOffForSubscriber(subId);
2829 }
2830 return true;
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
Wink Saville36469e72014-06-11 15:17:00 -07002835
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002836 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002837 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002838 /*
2839 * If any of the Radios are available, it will need to be
2840 * shutdown. So return true if any Radio is available.
2841 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2845 Phone phone = PhoneFactory.getPhone(i);
2846 if (phone != null && phone.isRadioAvailable()) return true;
2847 }
2848 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2849 return false;
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002852 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002853 }
2854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002855 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002856 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 enforceModifyPermission();
2858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
2861 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2862 logv("Shutting down Phone " + i);
2863 shutdownRadioUsingPhoneId(i);
2864 }
2865 } finally {
2866 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002867 }
2868 }
2869
2870 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002871 Phone phone = PhoneFactory.getPhone(phoneId);
2872 if (phone != null && phone.isRadioAvailable()) {
2873 phone.shutdownRadio();
2874 }
2875 }
2876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002879
2880 final long identity = Binder.clearCallingIdentity();
2881 try {
2882 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2883 if (defaultPhone != null) {
2884 defaultPhone.setRadioPower(turnOn);
2885 return true;
2886 } else {
2887 loge("There's no default phone.");
2888 return false;
2889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002892 }
Wink Saville36469e72014-06-11 15:17:00 -07002893 }
2894
Wink Savilleb564aae2014-10-23 10:18:09 -07002895 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 final Phone phone = getPhone(subId);
2901 if (phone != null) {
2902 phone.setRadioPower(turnOn);
2903 return true;
2904 } else {
2905 return false;
2906 }
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Thomas Nguyenfd0572f2022-07-15 22:28:49 +00002912 /**
2913 * Vote on powering off the radio for a reason. The radio will be turned on only when there is
2914 * no reason to power it off. When any of the voters want to power it off, it will be turned
2915 * off. In case of emergency, the radio will be turned on even if there are some reasons for
2916 * powering it off, and these radio off votes will be cleared.
2917 * Multiple apps can vote for the same reason and the last vote will take effect. Each app is
2918 * responsible for its vote. A powering-off vote of a reason will be maintained until it is
2919 * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call
2920 * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make
2921 * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to
2922 * check its vote.
2923 *
2924 * @param subId The subscription ID.
2925 * @param reason The reason for powering off radio.
2926 * @return true on success and false on failure.
2927 */
2928 public boolean requestRadioPowerOffForReason(int subId,
2929 @TelephonyManager.RadioPowerReason int reason) {
2930 enforceModifyPermission();
2931
2932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 final Phone phone = getPhone(subId);
2935 if (phone != null) {
2936 phone.setRadioPowerForReason(false, reason);
2937 return true;
2938 } else {
2939 return false;
2940 }
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
2943 }
2944 }
2945
2946 /**
2947 * Remove the vote on powering off the radio for a reason, as requested by
2948 * {@link requestRadioPowerOffForReason}.
2949 *
2950 * @param subId The subscription ID.
2951 * @param reason The reason for powering off radio.
2952 * @return true on success and false on failure.
2953 */
2954 public boolean clearRadioPowerOffForReason(int subId,
2955 @TelephonyManager.RadioPowerReason int reason) {
2956 enforceModifyPermission();
2957
2958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 final Phone phone = getPhone(subId);
2961 if (phone != null) {
2962 phone.setRadioPowerForReason(true, reason);
2963 return true;
2964 } else {
2965 return false;
2966 }
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 /**
2973 * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}.
2974 *
2975 * @param subId The subscription ID.
2976 * @param callingPackage The package making the call.
2977 * @param callingFeatureId The feature in the package.
2978 * @return List of reasons for powering off radio.
2979 */
2980 public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) {
2981 enforceReadPrivilegedPermission("getRadioPowerOffReasons");
2982
2983 final long identity = Binder.clearCallingIdentity();
2984 List result = new ArrayList();
2985 try {
2986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId,
2987 callingPackage, callingFeatureId, "getRadioPowerOffReasons")) {
2988 return result;
2989 }
2990
2991 final Phone phone = getPhone(subId);
2992 if (phone != null) {
2993 result.addAll(phone.getRadioPowerOffReasons());
2994 }
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 return result;
2999 }
3000
Wink Saville36469e72014-06-11 15:17:00 -07003001 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003003 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 int subId = mSubscriptionController.getDefaultDataSubId();
3009 final Phone phone = getPhone(subId);
3010 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003011 phone.getDataSettingsManager().setDataEnabled(
3012 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 return true;
3014 } else {
3015 return false;
3016 }
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 }
3021
Wink Saville36469e72014-06-11 15:17:00 -07003022 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07003023 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07003024 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 int subId = mSubscriptionController.getDefaultDataSubId();
3030 final Phone phone = getPhone(subId);
3031 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003032 phone.getDataSettingsManager().setDataEnabled(
3033 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034 return true;
3035 } else {
3036 return false;
3037 }
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003041 }
3042
Sanket Padawe356d7632015-06-22 14:03:32 -07003043 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07003044 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045 final long identity = Binder.clearCallingIdentity();
3046 try {
3047 final Phone phone = getPhone(subId);
3048 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07003049 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 } else {
3051 return false;
3052 }
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003055 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 }
3057
3058 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07003059 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07003060 }
3061
pkanwarae03a6b2016-11-06 20:37:09 -08003062 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 enforceCallPermission();
3064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3068 return;
3069 }
3070 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
3071 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
pkanwar32d516d2016-10-14 19:37:38 -07003075 };
3076
Wink Savilleb564aae2014-10-23 10:18:09 -07003077 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3083 return false;
3084 }
3085 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 }
3090
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003091 /**
3092 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
3093 * tag on getCallState Binder call.
3094 */
3095 @Deprecated
3096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003098 if (CompatChanges.isChangeEnabled(
3099 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3100 Binder.getCallingUid())) {
3101 // Do not allow this API to be called on API version 31+, it should only be
3102 // called on old apps using this Binder call directly.
3103 throw new SecurityException("This method can only be used for applications "
3104 + "targeting API version 30 or less.");
3105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 final long identity = Binder.clearCallingIdentity();
3107 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00003108 Phone phone = getPhone(getDefaultSubscription());
3109 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3110 PhoneConstantConversions.convertCallState(phone.getState());
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
3117 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
3118 if (CompatChanges.isChangeEnabled(
3119 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
3120 Binder.getCallingUid())) {
3121 // Check READ_PHONE_STATE for API version 31+
3122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
3123 featureId, "getCallStateForSubscription")) {
3124 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
3125 + "targeting API level 31+.");
3126 }
3127 }
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
3132 PhoneConstantConversions.convertCallState(phone.getState());
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 }
3137
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00003139 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003140 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
3141 }
3142
3143 @Override
3144 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145 final long identity = Binder.clearCallingIdentity();
3146 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003147 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 if (phone != null) {
Jack Yu7968c6d2022-07-31 00:43:21 -07003149 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 } else {
3151 return PhoneConstantConversions.convertDataState(
3152 PhoneConstants.DataState.DISCONNECTED);
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 }
3158
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003160 public @DataActivityType int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003161 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
3162 }
3163
3164 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003165 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003168 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003170 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 } else {
3172 return TelephonyManager.DATA_ACTIVITY_NONE;
3173 }
3174 } finally {
3175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003177 }
3178
3179 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003180 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003181 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003182 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003183
3184 LocationAccessPolicy.LocationPermissionResult locationResult =
3185 LocationAccessPolicy.checkLocationPermission(mApp,
3186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3187 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003189 .setCallingPid(Binder.getCallingPid())
3190 .setCallingUid(Binder.getCallingUid())
3191 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003192 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003193 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3194 .build());
3195 switch (locationResult) {
3196 case DENIED_HARD:
3197 throw new SecurityException("Not allowed to access cell location");
3198 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003199 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3200 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 }
3202
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07003207 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003208 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Svetoslav64fad262015-04-14 14:35:21 -07003212 }
3213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003215 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003216 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3217 // registered cell info, so return a NULL country instead.
3218 final long identity = Binder.clearCallingIdentity();
3219 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003220 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3221 // Get default phone in this case.
3222 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3223 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003224 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003226 if (phone == null) return "";
3227 ServiceStateTracker sst = phone.getServiceStateTracker();
3228 if (sst == null) return "";
3229 LocaleTracker lt = sst.getLocaleTracker();
3230 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003231 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003235 }
3236
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003237 /**
3238 * This method was removed due to potential issues caused by performing partial
3239 * updates of service state, and lack of a credible use case.
3240 *
3241 * This has the ability to break the telephony implementation by disabling notification of
3242 * changes in device connectivity. DO NOT USE THIS!
3243 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003244 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 public void enableLocationUpdates() {
3246 mApp.enforceCallingOrSelfPermission(
3247 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 }
3249
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003250 /**
3251 * This method was removed due to potential issues caused by performing partial
3252 * updates of service state, and lack of a credible use case.
3253 *
3254 * This has the ability to break the telephony implementation by disabling notification of
3255 * changes in device connectivity. DO NOT USE THIS!
3256 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 @Override
3258 public void disableLocationUpdates() {
3259 mApp.enforceCallingOrSelfPermission(
3260 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
3263 @Override
3264 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003265 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3266 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003267 try {
3268 mApp.getSystemService(AppOpsManager.class)
3269 .checkPackage(Binder.getCallingUid(), callingPackage);
3270 } catch (SecurityException e) {
3271 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3272 throw e;
3273 }
3274
Nathan Haroldf096d982020-11-18 17:18:06 -08003275 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003276 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3277 throw new SecurityException(
3278 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3279 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003280
Jordan Liu1617b712019-07-10 15:06:26 -07003281 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003282 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3283 return null;
3284 }
Svetoslav64fad262015-04-14 14:35:21 -07003285
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003286 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003288 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003289 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290
Nathan Haroldf180aac2018-06-01 18:43:55 -07003291 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3292 for (CellInfo ci : info) {
3293 if (ci instanceof CellInfoGsm) {
3294 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3295 } else if (ci instanceof CellInfoWcdma) {
3296 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003299 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003302 private List<CellInfo> getCachedCellInfo() {
3303 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3304 for (Phone phone : PhoneFactory.getPhones()) {
3305 List<CellInfo> info = phone.getAllCellInfo();
3306 if (info != null) cellInfos.addAll(info);
3307 }
3308 return cellInfos;
3309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310
3311 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003312 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003313 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003314 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003315
3316 LocationAccessPolicy.LocationPermissionResult locationResult =
3317 LocationAccessPolicy.checkLocationPermission(mApp,
3318 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3319 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003320 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003321 .setCallingPid(Binder.getCallingPid())
3322 .setCallingUid(Binder.getCallingUid())
3323 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003324 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003325 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3326 .build());
3327 switch (locationResult) {
3328 case DENIED_HARD:
3329 throw new SecurityException("Not allowed to access cell info");
3330 case DENIED_SOFT:
3331 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003332 }
3333
Nathan Haroldf096d982020-11-18 17:18:06 -08003334 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003335 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3336 return getCachedCellInfo();
3337 }
3338
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003339 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003340 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3344 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003345 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003346 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 if (info != null) cellInfos.addAll(info);
3348 }
3349 return cellInfos;
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353 }
3354
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003355 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003356 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3357 String callingFeatureId) {
3358 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3359 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003360 }
3361
3362 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003363 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3364 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003365 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003366 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003367 }
3368
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003369 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3370 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003372 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003373
3374 LocationAccessPolicy.LocationPermissionResult locationResult =
3375 LocationAccessPolicy.checkLocationPermission(mApp,
3376 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3377 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003378 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003379 .setCallingPid(Binder.getCallingPid())
3380 .setCallingUid(Binder.getCallingUid())
3381 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003382 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3383 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003384 .build());
3385 switch (locationResult) {
3386 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003387 if (TelephonyPermissions
3388 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003389 // Safetynet logging for b/154934934
3390 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3391 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003392 throw new SecurityException("Not allowed to access cell info");
3393 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003394 if (TelephonyPermissions
3395 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003396 // Safetynet logging for b/154934934
3397 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3398 }
Nathan Harold5320c422019-05-09 10:26:08 -07003399 try {
3400 cb.onCellInfo(new ArrayList<CellInfo>());
3401 } catch (RemoteException re) {
3402 // Drop without consequences
3403 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003404 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003405 }
3406
Nathan Harolda939a962019-05-09 10:13:47 -07003407
3408 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003409 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3410
3411 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3412 }
3413
3414 @Override
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003415 public void setCellInfoListRate(int rateInMillis, int subId) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003416 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003417 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
Aishwarya Mallampati0603fb12022-08-24 21:16:56 +00003421 Phone phone = getPhone(subId);
3422 if (phone == null) {
3423 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
3424 } else {
3425 phone.setCellInfoListRate(rateInMillis, workSource);
3426 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 }
3431
Shishir Agrawala9f32182016-04-12 12:00:16 -07003432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003433 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003434 Phone phone = PhoneFactory.getPhone(slotIndex);
3435 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003436 return null;
3437 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003438 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003439 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003440 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003441 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003442 return null;
3443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return phone.getImei();
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003451 }
3452
3453 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003454 public String getTypeAllocationCodeForSlot(int slotIndex) {
3455 Phone phone = PhoneFactory.getPhone(slotIndex);
3456 String tac = null;
3457 if (phone != null) {
3458 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003459 try {
3460 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3461 } catch (IndexOutOfBoundsException e) {
3462 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3463 return null;
3464 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003465 }
3466 return tac;
3467 }
3468
3469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003470 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003471 try {
3472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3473 } catch (SecurityException se) {
3474 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3475 throw new SecurityException("Package " + callingPackage + " does not belong to "
3476 + Binder.getCallingUid());
3477 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003478 Phone phone = PhoneFactory.getPhone(slotIndex);
3479 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003480 return null;
3481 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482
Jeff Davidson913390f2018-02-23 17:11:49 -08003483 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003484 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003485 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003486 return null;
3487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 return phone.getMeid();
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
Jack Yu2af8d712017-03-15 17:14:14 -07003495 }
3496
3497 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003498 public String getManufacturerCodeForSlot(int slotIndex) {
3499 Phone phone = PhoneFactory.getPhone(slotIndex);
3500 String manufacturerCode = null;
3501 if (phone != null) {
3502 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003503 try {
3504 manufacturerCode =
3505 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3506 } catch (IndexOutOfBoundsException e) {
3507 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3508 return null;
3509 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003510 }
3511 return manufacturerCode;
3512 }
3513
3514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3516 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003517 Phone phone = PhoneFactory.getPhone(slotIndex);
3518 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003519 return null;
3520 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 int subId = phone.getSubId();
3522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003523 mApp, subId, callingPackage, callingFeatureId,
3524 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003525 return null;
3526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 return phone.getDeviceSvn();
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003534 }
3535
fionaxu43304da2017-11-27 22:51:16 -08003536 @Override
3537 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3542 } finally {
3543 Binder.restoreCallingIdentity(identity);
3544 }
fionaxu43304da2017-11-27 22:51:16 -08003545 }
3546
3547 @Override
3548 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 final Phone phone = getPhone(subId);
3552 return phone == null ? null : phone.getCarrierName();
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
fionaxu43304da2017-11-27 22:51:16 -08003556 }
3557
calvinpanffe225e2018-11-01 19:43:06 +08003558 @Override
chen xu0026ca62019-03-06 15:28:50 -08003559 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = getPhone(subId);
3563 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003564 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
3568 }
3569
3570 @Override
chen xu0026ca62019-03-06 15:28:50 -08003571 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003575 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
3579 }
3580
chen xu651eec72018-11-11 19:03:44 -08003581 @Override
chen xu864e11c2018-12-06 22:10:03 -08003582 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3583 if (!isSubscriptionMccMnc) {
3584 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3585 }
chen xu651eec72018-11-11 19:03:44 -08003586 final Phone phone = PhoneFactory.getPhone(slotIndex);
3587 if (phone == null) {
3588 return TelephonyManager.UNKNOWN_CARRIER_ID;
3589 }
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003598 //
3599 // Internal helper methods.
3600 //
3601
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003602 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003603 * Make sure the caller is the calling package itself
3604 *
3605 * @throws SecurityException if the caller is not the calling package
3606 */
3607 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3608 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003609 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3610 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003611 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003612 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003613 } catch (PackageManager.NameNotFoundException e) {
3614 // packageUid is -1
3615 }
3616 if (packageUid != callingUid) {
3617 throw new SecurityException(message + ": Package " + callingPackage
3618 + " does not belong to " + callingUid);
3619 }
3620 }
3621
3622 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3624 *
3625 * @throws SecurityException if the caller does not have the required permission
3626 */
3627 private void enforceModifyPermission() {
3628 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3629 }
3630
Shuo Qian3b6ee772019-11-13 17:43:31 -08003631 private void enforceActiveEmergencySessionPermission() {
3632 mApp.enforceCallingOrSelfPermission(
3633 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3634 }
3635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 /**
3637 * Make sure the caller has the CALL_PHONE permission.
3638 *
3639 * @throws SecurityException if the caller does not have the required permission
3640 */
3641 private void enforceCallPermission() {
3642 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3643 }
3644
paulhu5a773602019-08-23 19:17:33 +08003645 private void enforceSettingsPermission() {
3646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003647 }
3648
Michele Berionne5e411512020-11-13 02:36:59 +00003649 private void enforceRebootPermission() {
3650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3651 }
3652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003653 private String createTelUrl(String number) {
3654 if (TextUtils.isEmpty(number)) {
3655 return null;
3656 }
3657
Jake Hambye994d462014-02-03 13:10:13 -08003658 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003659 }
3660
Ihab Awadf9e92732013-12-05 18:02:52 -08003661 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003662 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3663 }
3664
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003665 private static void logv(String msg) {
3666 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3667 }
3668
Ihab Awadf9e92732013-12-05 18:02:52 -08003669 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003670 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3671 }
3672
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003673 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003674 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003675 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003676 }
3677
Sanket Padawe356d7632015-06-22 14:03:32 -07003678 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003679 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = PhoneFactory.getPhone(slotIndex);
3683 if (phone == null) {
3684 return PhoneConstants.PHONE_TYPE_NONE;
3685 } else {
3686 return phone.getPhoneType();
3687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003691 }
3692
3693 /**
3694 * Returns the CDMA ERI icon index to display
3695 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003696 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003697 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3698 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3699 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003700 }
3701
Sanket Padawe356d7632015-06-22 14:03:32 -07003702 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003703 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3704 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003706 mApp, subId, callingPackage, callingFeatureId,
3707 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003708 return -1;
3709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710
3711 final long identity = Binder.clearCallingIdentity();
3712 try {
3713 final Phone phone = getPhone(subId);
3714 if (phone != null) {
3715 return phone.getCdmaEriIconIndex();
3716 } else {
3717 return -1;
3718 }
3719 } finally {
3720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003722 }
3723
3724 /**
3725 * Returns the CDMA ERI icon mode,
3726 * 0 - ON
3727 * 1 - FLASHING
3728 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003729 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003730 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3731 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3732 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003733 }
3734
Sanket Padawe356d7632015-06-22 14:03:32 -07003735 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003736 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3737 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003739 mApp, subId, callingPackage, callingFeatureId,
3740 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003741 return -1;
3742 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 final Phone phone = getPhone(subId);
3747 if (phone != null) {
3748 return phone.getCdmaEriIconMode();
3749 } else {
3750 return -1;
3751 }
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 }
3756
3757 /**
3758 * Returns the CDMA ERI text,
3759 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003761 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3762 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3763 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003764 }
3765
Sanket Padawe356d7632015-06-22 14:03:32 -07003766 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003767 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3768 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003769 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003770 mApp, subId, callingPackage, callingFeatureId,
3771 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 return null;
3773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 return phone.getCdmaEriText();
3780 } else {
3781 return null;
3782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003786 }
3787
3788 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003789 * Returns the CDMA MDN.
3790 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003792 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3794 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003799 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 return phone.getLine1Number();
3801 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003802 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 return null;
3804 }
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003807 }
3808 }
3809
3810 /**
3811 * Returns the CDMA MIN.
3812 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003813 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003814 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3816 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 final Phone phone = getPhone(subId);
3821 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3822 return phone.getCdmaMin();
3823 } else {
3824 return null;
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003828 }
3829 }
3830
Hall Liud892bec2018-11-30 14:51:45 -08003831 @Override
3832 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3833 INumberVerificationCallback callback, String callingPackage) {
3834 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3835 != PERMISSION_GRANTED) {
3836 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3837 }
3838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3839
3840 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3841 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003842 throw new SecurityException("Calling package must be configured in the device config: "
3843 + "calling package: " + callingPackage
3844 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003845 }
3846
3847 if (range == null) {
3848 throw new NullPointerException("Range must be non-null");
3849 }
3850
3851 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003852 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003853
3854 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3855 }
3856
Junda Liuca05d5d2014-08-14 22:36:34 -07003857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 * Returns true if CDMA provisioning needs to run.
3859 */
3860 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003863 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 } finally {
3865 Binder.restoreCallingIdentity(identity);
3866 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003867 }
3868
3869 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003870 * Sets the voice mail number of a given subId.
3871 */
3872 @Override
3873 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003874 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3875 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876
3877 final long identity = Binder.clearCallingIdentity();
3878 try {
3879 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3880 new Pair<String, String>(alphaTag, number), new Integer(subId));
3881 return success;
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
3884 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003885 }
3886
Ta-wei Yen87c49842016-05-13 21:19:52 -07003887 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003888 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003890 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3891 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003892 if (!TextUtils.equals(callingPackage, systemDialer)) {
3893 throw new SecurityException("caller must be system dialer");
3894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3899 if (phoneAccountHandle == null) {
3900 return null;
3901 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003905 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003906 }
3907
3908 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003909 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3910 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003911 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003913 mApp, subId, callingPackage, callingFeatureId,
3914 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003915 return null;
3916 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003918 final long identity = Binder.clearCallingIdentity();
3919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003920 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003924 }
3925
3926 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003927 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3928 VisualVoicemailSmsFilterSettings settings) {
3929 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930
3931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 } finally {
3936 Binder.restoreCallingIdentity(identity);
3937 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003938 }
3939
3940 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003941 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003943
3944 final long identity = Binder.clearCallingIdentity();
3945 try {
3946 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003951 }
3952
3953 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003954 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3955 String callingPackage, int subId) {
3956 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003961 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 } finally {
3963 Binder.restoreCallingIdentity(identity);
3964 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003965 }
3966
3967 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003968 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970
3971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003974 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003975 } finally {
3976 Binder.restoreCallingIdentity(identity);
3977 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003978 }
3979
3980 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003981 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3982 String callingAttributionTag, int subId, String number, int port, String text,
3983 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003984 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003985 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003986 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003987 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003988 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3989 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003990 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003991
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003992 /**
fionaxu0152e512016-11-14 13:36:14 -08003993 * Sets the voice activation state of a given subId.
3994 */
3995 @Override
3996 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3998 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999
4000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 final Phone phone = getPhone(subId);
4003 if (phone != null) {
4004 phone.setVoiceActivationState(activationState);
4005 } else {
4006 loge("setVoiceActivationState fails with invalid subId: " + subId);
4007 }
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004010 }
4011 }
4012
4013 /**
4014 * Sets the data activation state of a given subId.
4015 */
4016 @Override
4017 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4019 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 final Phone phone = getPhone(subId);
4024 if (phone != null) {
4025 phone.setDataActivationState(activationState);
4026 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09004027 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028 }
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004031 }
4032 }
4033
4034 /**
4035 * Returns the voice activation state of a given subId.
4036 */
4037 @Override
4038 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004040
fionaxu0152e512016-11-14 13:36:14 -08004041 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 if (phone != null) {
4045 return phone.getVoiceActivationState();
4046 } else {
4047 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4048 }
4049 } finally {
4050 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004051 }
4052 }
4053
4054 /**
4055 * Returns the data activation state of a given subId.
4056 */
4057 @Override
4058 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060
fionaxu0152e512016-11-14 13:36:14 -08004061 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 if (phone != null) {
4065 return phone.getDataActivationState();
4066 } else {
4067 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
4068 }
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08004071 }
4072 }
4073
4074 /**
Wink Saville36469e72014-06-11 15:17:00 -07004075 * Returns the unread count of voicemails for a subId
4076 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004077 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004078 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
4079 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004081 mApp, subId, callingPackage, callingFeatureId,
4082 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08004083 return 0;
4084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 final Phone phone = getPhone(subId);
4088 if (phone != null) {
4089 return phone.getVoiceMessageCount();
4090 } else {
4091 return 0;
4092 }
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004096 }
4097
4098 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08004099 * returns true, if the device is in a state where both voice and data
4100 * are supported simultaneously. This can change based on location or network condition.
4101 */
4102 @Override
4103 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 final Phone phone = getPhone(subId);
4107 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08004111 }
4112
4113 /**
fionaxu235cc5e2017-03-06 22:25:57 -08004114 * Send the dialer code if called from the current default dialer or the caller has
4115 * carrier privilege.
4116 * @param inputCode The dialer code to send
4117 */
4118 @Override
4119 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08004121 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07004122 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
4123 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08004124 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08004125 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08004126 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08004127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128
4129 final long identity = Binder.clearCallingIdentity();
4130 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004131 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
fionaxu235cc5e2017-03-06 22:25:57 -08004135 }
4136
Pengquan Menga1bb6272018-09-06 09:59:22 -07004137 @Override
4138 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08004139 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07004140 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08004141 mApp, subId, "getNetworkSelectionMode");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 if (!isActiveSubscription(subId)) {
4145 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
4146 }
4147 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4148 } finally {
4149 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004150 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004151 }
4152
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004154 public boolean isInEmergencySmsMode() {
4155 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4156 final long identity = Binder.clearCallingIdentity();
4157 try {
4158 for (Phone phone : PhoneFactory.getPhones()) {
4159 if (phone.isInEmergencySmsMode()) {
4160 return true;
4161 }
4162 }
4163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 return false;
4167 }
4168
shilu366312e2019-12-17 09:28:10 -08004169 /**
4170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 * @param c The callback that will be used to send the result.
4173 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004175 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4176 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004178 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004179
4180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4182 "IMS not available on device.");
4183 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 final long token = Binder.clearCallingIdentity();
4185 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004186 int slotId = getSlotIndexOrException(subId);
4187 verifyImsMmTelConfiguredOrThrow(slotId);
joonhunshin49f0aed2022-08-05 08:33:05 +00004188
4189 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4190 if (controller != null) {
4191 ImsManager imsManager = controller.getImsManager(subId);
4192 if (imsManager != null) {
4193 imsManager.addRegistrationCallbackForSubscription(c, subId);
4194 } else {
4195 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
4196 }
4197 } else {
4198 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4199 }
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (ImsException e) {
4201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 } finally {
4203 Binder.restoreCallingIdentity(token);
4204 }
4205 }
4206
shilu366312e2019-12-17 09:28:10 -08004207 /**
4208 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4209 * @param subId The subscription to use to check the configuration.
4210 * @param c The callback that will be used to send the result.
4211 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004213 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004214 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004215 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4217 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4218 }
Meng Wangafbc5852019-09-19 17:37:13 -07004219 final long token = Binder.clearCallingIdentity();
joonhunshin49f0aed2022-08-05 08:33:05 +00004220
Meng Wangafbc5852019-09-19 17:37:13 -07004221 try {
joonhunshin49f0aed2022-08-05 08:33:05 +00004222 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
4223 if (controller != null) {
4224 ImsManager imsManager = controller.getImsManager(subId);
4225 if (imsManager != null) {
4226 imsManager.removeRegistrationCallbackForSubscription(c, subId);
4227 } else {
4228 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4229 + "is inactive, ignoring unregister.");
4230 // If the ImsManager is not valid, just return, since the callback
4231 // will already have been removed internally.
4232 }
4233 }
Meng Wangafbc5852019-09-19 17:37:13 -07004234 } finally {
4235 Binder.restoreCallingIdentity(token);
4236 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 }
4238
Brad Ebingera34a6c22019-10-22 17:36:18 -07004239 /**
4240 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4241 */
4242 @Override
4243 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4244 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4245 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4247 "IMS not available on device.");
4248 }
4249 final long token = Binder.clearCallingIdentity();
4250 try {
4251 Phone phone = getPhone(subId);
4252 if (phone == null) {
4253 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4254 + subId + "'");
4255 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4256 }
4257 phone.getImsRegistrationState(regState -> {
4258 try {
4259 consumer.accept((regState == null)
4260 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4261 } catch (RemoteException e) {
4262 // Ignore if the remote process is no longer available to call back.
4263 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4264 }
4265 });
4266 } finally {
4267 Binder.restoreCallingIdentity(token);
4268 }
4269 }
4270
4271 /**
4272 * Get the transport type for the IMS service registration state.
4273 */
4274 @Override
4275 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004276 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004277 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004278 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4279 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4280 "IMS not available on device.");
4281 }
4282 final long token = Binder.clearCallingIdentity();
4283 try {
4284 Phone phone = getPhone(subId);
4285 if (phone == null) {
4286 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4287 + subId + "'");
4288 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4289 }
4290 phone.getImsRegistrationTech(regTech -> {
4291 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4292 int regTechConverted = (regTech == null)
4293 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4294 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4295 regTechConverted);
4296 try {
4297 consumer.accept(regTechConverted);
4298 } catch (RemoteException e) {
4299 // Ignore if the remote process is no longer available to call back.
4300 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4301 }
4302 });
4303 } finally {
4304 Binder.restoreCallingIdentity(token);
4305 }
4306 }
4307
shilu366312e2019-12-17 09:28:10 -08004308 /**
4309 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 * @param c The callback that will be used to send the result.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004314 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4315 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004317 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004318 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4320 "IMS not available on device.");
4321 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 final long token = Binder.clearCallingIdentity();
4323 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004324 int slotId = getSlotIndexOrException(subId);
4325 verifyImsMmTelConfiguredOrThrow(slotId);
4326 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004327 } catch (ImsException e) {
4328 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004329 } finally {
4330 Binder.restoreCallingIdentity(token);
4331 }
4332 }
4333
shilu366312e2019-12-17 09:28:10 -08004334 /**
4335 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4336 * @param subId The subscription to use to check the configuration.
4337 * @param c The callback that will be used to send the result.
4338 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004339 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004340 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004341 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004342 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004343 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4344 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4345 }
Meng Wangafbc5852019-09-19 17:37:13 -07004346
4347 final long token = Binder.clearCallingIdentity();
4348 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004349 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004350 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004351 } catch (ImsException e) {
4352 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4353 + "is inactive, ignoring unregister.");
4354 // If the subscription is no longer active, just return, since the callback
4355 // will already have been removed internally.
4356 } finally {
4357 Binder.restoreCallingIdentity(token);
4358 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 }
4360
4361 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004362 public boolean isCapable(int subId, int capability, int regTech) {
4363 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 final long token = Binder.clearCallingIdentity();
4365 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004366 int slotId = getSlotIndexOrException(subId);
4367 verifyImsMmTelConfiguredOrThrow(slotId);
4368 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4369 } catch (com.android.ims.ImsException e) {
4370 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4371 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004373 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4374 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 } finally {
4376 Binder.restoreCallingIdentity(token);
4377 }
4378 }
4379
4380 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004381 public boolean isAvailable(int subId, int capability, int regTech) {
4382 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 final long token = Binder.clearCallingIdentity();
4384 try {
4385 Phone phone = getPhone(subId);
4386 if (phone == null) return false;
4387 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004388 } catch (com.android.ims.ImsException e) {
4389 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4390 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 } finally {
4392 Binder.restoreCallingIdentity(token);
4393 }
4394 }
4395
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004396 /**
4397 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4398 * subscription.
4399 * @param subId The subscription to use to check the configuration.
4400 * @param callback The callback that will be used to send the result.
4401 * @param capability The MmTelFeature capability that will be used to send the result.
4402 * @param transportType The transport type of the MmTelFeature capability.
4403 */
4404 @Override
4405 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4406 int transportType) {
4407 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004408 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4409 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4410 "IMS not available on device.");
4411 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004412 final long token = Binder.clearCallingIdentity();
4413 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004414 int slotId = getSlotIndex(subId);
4415 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4416 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4417 + subId + "'");
4418 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4419 }
4420 verifyImsMmTelConfiguredOrThrow(slotId);
4421 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4422 transportType, aBoolean -> {
4423 try {
4424 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4425 } catch (RemoteException e) {
4426 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4427 + "running. Ignore");
4428 }
4429 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004432 } finally {
4433 Binder.restoreCallingIdentity(token);
4434 }
4435 }
4436
shilu366312e2019-12-17 09:28:10 -08004437 /**
4438 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4439 * @param subId The subscription to use to check the configuration.
4440 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004441 @Override
4442 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004444 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004445
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 final long token = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004448 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004449 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004451 } catch (ImsException e) {
4452 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 } finally {
4454 Binder.restoreCallingIdentity(token);
4455 }
4456 }
4457
4458 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004459 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004461 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004462 final long identity = Binder.clearCallingIdentity();
4463 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004464 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004465 // This setting doesn't require an active ImsService connection, so do not verify. The
4466 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004467 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004468 } catch (ImsException e) {
4469 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004470 } finally {
4471 Binder.restoreCallingIdentity(identity);
4472 }
4473 }
4474
shilu366312e2019-12-17 09:28:10 -08004475 /**
4476 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4477 * @param subId The subscription to use to check the configuration.
4478 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004480 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004481 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004482 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004483 final long identity = Binder.clearCallingIdentity();
4484 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004486 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (ImsException e) {
4489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004490 } finally {
4491 Binder.restoreCallingIdentity(identity);
4492 }
4493 }
4494
4495 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004496 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004498 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 final long identity = Binder.clearCallingIdentity();
4500 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004501 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004502 // This setting doesn't require an active ImsService connection, so do not verify. The
4503 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004505 } catch (ImsException e) {
4506 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
4510 }
4511
shilu366312e2019-12-17 09:28:10 -08004512 /**
4513 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4514 * @param subId The subscription to use to check the configuration.
4515 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 @Override
4517 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004518 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004519 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004520 final long identity = Binder.clearCallingIdentity();
4521 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004523 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004524 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004525 } catch (ImsException e) {
4526 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
4530 }
4531
4532 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004533 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004535 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004536 final long identity = Binder.clearCallingIdentity();
4537 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004538 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004539 // This setting doesn't require an active ImsService connection, so do not verify. The
4540 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004541 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004542 } catch (ImsException e) {
4543 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004544 } finally {
4545 Binder.restoreCallingIdentity(identity);
4546 }
4547 }
4548
shilu366312e2019-12-17 09:28:10 -08004549 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004550 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4551 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4552 * @param subId The subscription to use to check the configuration.
4553 */
4554 @Override
4555 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004556 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004557 mApp, subId, "isCrossSimCallingEnabledByUser");
4558 final long identity = Binder.clearCallingIdentity();
4559 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004560 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004561 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004563 } catch (ImsException e) {
4564 throw new ServiceSpecificException(e.getCode());
4565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
4570 /**
4571 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4572 * Requires MODIFY_PHONE_STATE permission.
4573 * @param subId The subscription to use to check the configuration.
4574 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4575 * false otherwise
4576 */
4577 @Override
4578 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4580 "setCrossSimCallingEnabled");
4581 final long identity = Binder.clearCallingIdentity();
4582 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004583 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004584 // This setting doesn't require an active ImsService connection, so do not verify. The
4585 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004586 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004587 } catch (ImsException e) {
4588 throw new ServiceSpecificException(e.getCode());
4589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
4592 }
4593
4594 /**
shilu366312e2019-12-17 09:28:10 -08004595 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4596 * @param subId The subscription to use to check the configuration.
4597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004598 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004599
Brad Ebinger35c841c2018-10-01 10:40:55 -07004600 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004601 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004602 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004603 final long identity = Binder.clearCallingIdentity();
4604 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004605 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004606 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004607 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004608 } catch (ImsException e) {
4609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
4613 }
4614
4615 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004616 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004618 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004619 final long identity = Binder.clearCallingIdentity();
4620 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004621 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004622 // This setting doesn't require an active ImsService connection, so do not verify. The
4623 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004624 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004625 } catch (ImsException e) {
4626 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
4632 @Override
4633 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4635 "setVoWiFiNonPersistent");
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004638 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004639 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004640 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004641 } catch (ImsException e) {
4642 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
4646 }
4647
shilu366312e2019-12-17 09:28:10 -08004648 /**
4649 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4650 * @param subId The subscription to use to check the configuration.
4651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004652 @Override
4653 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004654 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004655 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004656 final long identity = Binder.clearCallingIdentity();
4657 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004658 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004659 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004660 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004661 } catch (ImsException e) {
4662 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
4669 public void setVoWiFiModeSetting(int subId, int mode) {
4670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4671 "setVoWiFiModeSetting");
4672 final long identity = Binder.clearCallingIdentity();
4673 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004674 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004675 // This setting doesn't require an active ImsService connection, so do not verify. The
4676 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004677 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (ImsException e) {
4679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
4686 public int getVoWiFiRoamingModeSetting(int subId) {
4687 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004690 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004691 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004692 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (ImsException e) {
4694 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
4701 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4703 "setVoWiFiRoamingModeSetting");
4704 final long identity = Binder.clearCallingIdentity();
4705 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004706 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004707 // This setting doesn't require an active ImsService connection, so do not verify. The
4708 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004709 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 } catch (ImsException e) {
4711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 } finally {
4713 Binder.restoreCallingIdentity(identity);
4714 }
4715 }
4716
4717 @Override
4718 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4720 "setRttCapabilityEnabled");
4721 final long identity = Binder.clearCallingIdentity();
4722 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004723 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004724 // This setting doesn't require an active ImsService connection, so do not verify. The
4725 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004726 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004727 } catch (ImsException e) {
4728 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 }
4733
shilu366312e2019-12-17 09:28:10 -08004734 /**
4735 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4736 * @param subId The subscription to use to check the configuration.
4737 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004738 @Override
4739 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004740 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004741 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 final long identity = Binder.clearCallingIdentity();
4743 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004744 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004745 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004746 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004747 } catch (ImsException e) {
4748 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004754 @Override
4755 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4756 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004757
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004758 final long identity = Binder.clearCallingIdentity();
4759 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004760 if (!isImsAvailableOnDevice()) {
4761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4762 "IMS not available on device.");
4763 }
4764 int slotId = getSlotIndexOrException(subId);
4765 verifyImsMmTelConfiguredOrThrow(slotId);
4766 ImsManager.getInstance(mApp, slotId)
4767 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004768 } catch (ImsException e) {
4769 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
4773 }
4774
4775 @Override
4776 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4777 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004778
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4782 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004783 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004784 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004785 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004787 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4788 + "is inactive, ignoring unregister.");
4789 // If the subscription is no longer active, just return, since the callback will already
4790 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004791 } finally {
4792 Binder.restoreCallingIdentity(identity);
4793 }
4794 }
4795
joonhunshincffb7fc2021-11-28 07:32:01 +00004796 @Override
4797 public void registerFeatureProvisioningChangedCallback(int subId,
4798 IFeatureProvisioningCallback callback) {
4799 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4800 mApp, subId, "registerFeatureProvisioningChangedCallback");
4801
4802 final long identity = Binder.clearCallingIdentity();
4803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4805 }
4806
joonhunshin91bc1952022-04-29 08:47:15 +00004807 try {
4808 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4809 if (controller == null) {
4810 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4811 "Device does not support IMS");
4812 }
4813 controller.addFeatureProvisioningChangedCallback(subId, callback);
4814 } finally {
4815 Binder.restoreCallingIdentity(identity);
4816 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004817 }
4818
4819 @Override
4820 public void unregisterFeatureProvisioningChangedCallback(int subId,
4821 IFeatureProvisioningCallback callback) {
4822 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4823 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4824
4825 final long identity = Binder.clearCallingIdentity();
4826 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4827 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4828 }
4829
joonhunshin91bc1952022-04-29 08:47:15 +00004830 try {
4831 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4832 if (controller == null) {
4833 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4834 return;
4835 }
4836 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004840 }
allenwtsu99c623b2020-01-03 18:24:23 +08004841
4842 private void checkModifyPhoneStatePermission(int subId, String message) {
4843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4844 message);
4845 }
4846
allenwtsu99c623b2020-01-03 18:24:23 +08004847 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004848 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004849 boolean isProvisioned) {
4850 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4851
4852 final long identity = Binder.clearCallingIdentity();
4853 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004854 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4855 if (controller == null) {
4856 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4857 return;
4858 }
4859 controller.setRcsProvisioningStatusForCapability(
4860 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
allenwtsu99c623b2020-01-03 18:24:23 +08004864 }
4865
4866
4867 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004868 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4869 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4870 mApp, subId, "getRcsProvisioningStatusForCapability");
4871
allenwtsu99c623b2020-01-03 18:24:23 +08004872 final long identity = Binder.clearCallingIdentity();
4873 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004874 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4875 if (controller == null) {
4876 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4877
4878 // device does not support IMS, this method will return true always.
4879 return true;
4880 }
4881 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004882 } finally {
4883 Binder.restoreCallingIdentity(identity);
4884 }
4885 }
4886
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004887 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4889 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004890 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004891
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004894 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4895 if (controller == null) {
4896 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4897 return;
4898 }
4899 controller.setImsProvisioningStatusForCapability(
4900 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905
4906 @Override
4907 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004908 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4909 mApp, subId, "getProvisioningStatusForCapability");
4910
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 final long identity = Binder.clearCallingIdentity();
4912 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004913 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4914 if (controller == null) {
4915 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004916
joonhunshin91bc1952022-04-29 08:47:15 +00004917 // device does not support IMS, this method will return true always.
4918 return true;
4919 }
4920 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
4924 }
4925
4926 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004927 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4928 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4929 mApp, subId, "isProvisioningRequiredForCapability");
4930
4931 final long identity = Binder.clearCallingIdentity();
4932 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004933 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4934 if (controller == null) {
4935 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4936
4937 // device does not support IMS, this method will return false
4938 return false;
4939 }
4940 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004941 } finally {
4942 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004944 }
4945
4946 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004947 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4948 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4949 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950
joonhunshincffb7fc2021-11-28 07:32:01 +00004951 final long identity = Binder.clearCallingIdentity();
4952 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004953 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4954 if (controller == null) {
4955 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4956
4957 // device does not support IMS, this method will return false
4958 return false;
4959 }
4960 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 }
4965
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004966 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004967 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4969 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4970 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004971 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4972 mApp, subId, "getImsProvisioningInt");
4973
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004977 int slotId = getSlotIndex(subId);
4978 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4979 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4980 + subId + "' for key:" + key);
4981 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4982 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004983
joonhunshin91bc1952022-04-29 08:47:15 +00004984 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4985 if (controller == null) {
4986 loge("getImsProvisioningInt: Device does not support IMS");
4987
4988 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4989 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4990 }
4991 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004992 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4993 return retVal;
4994 }
4995
calvinpanb5a34062021-02-08 19:59:36 +08004996 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004997 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004998 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4999 + subId + "' for key:" + key);
5000 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
5004 }
5005
5006 @Override
5007 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5009 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5010 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005011 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5012 mApp, subId, "getImsProvisioningString");
5013
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005014 final long identity = Binder.clearCallingIdentity();
5015 try {
5016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005017 int slotId = getSlotIndex(subId);
5018 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5019 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
5020 + subId + "' for key:" + key);
5021 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
5022 }
calvinpanb5a34062021-02-08 19:59:36 +08005023 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005024 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005025 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
5026 + subId + "' for key:" + key);
5027 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
5031 }
5032
5033 @Override
5034 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005035 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5036 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5037 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5039 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00005040
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005041 final long identity = Binder.clearCallingIdentity();
5042 try {
5043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005044 int slotId = getSlotIndex(subId);
5045 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5046 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
5047 + subId + "' for key:" + key);
5048 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5049 }
joonhunshincffb7fc2021-11-28 07:32:01 +00005050
joonhunshin91bc1952022-04-29 08:47:15 +00005051 ImsProvisioningController controller = ImsProvisioningController.getInstance();
5052 if (controller == null) {
5053 loge("setImsProvisioningInt: Device does not support IMS");
5054
5055 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
5056 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5057 }
5058 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00005059 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
5060 return retVal;
5061 }
5062
calvinpanb5a34062021-02-08 19:59:36 +08005063 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5064 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005065 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005066 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005067 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005068 } finally {
5069 Binder.restoreCallingIdentity(identity);
5070 }
5071 }
5072
5073 @Override
5074 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
5076 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
5077 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08005078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
5079 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005083 int slotId = getSlotIndex(subId);
5084 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5085 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
5086 + subId + "' for key:" + key);
5087 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
5088 }
calvinpanb5a34062021-02-08 19:59:36 +08005089 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
5090 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005091 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08005092 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005093 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07005094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
5097 }
5098
Brad Ebinger919631e2021-06-02 17:46:35 -07005099 /**
5100 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
5101 * for the given slot ID or no ImsResolver instance has been created.
5102 * @param slotId The slot ID that the IMS service is created for.
5103 * @throws ImsException If there is no ImsService configured for this slot.
5104 */
5105 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
5106 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5107 ImsFeature.FEATURE_MMTEL)) {
5108 throw new ImsException("This subscription does not support MMTEL over IMS",
5109 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5110 }
5111 }
5112
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005113 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005114 int slotId = SubscriptionManager.getSlotIndex(subId);
5115 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005116 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5117 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005118 }
5119 return slotId;
5120 }
5121
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005122 private int getSlotIndex(int subId) {
5123 int slotId = SubscriptionManager.getSlotIndex(subId);
5124 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5125 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5126 }
5127 return slotId;
5128 }
5129
Wink Saville36469e72014-06-11 15:17:00 -07005130 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005131 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005132 */
5133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005134 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5135 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005136 try {
5137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5138 } catch (SecurityException se) {
5139 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5140 throw new SecurityException("Package " + callingPackage + " does not belong to "
5141 + Binder.getCallingUid());
5142 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005143 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005144 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005145 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005146 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005147 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005148 mApp, subId, callingPackage, callingFeatureId,
5149 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5151 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 final Phone phone = getPhone(subId);
5156 if (phone != null) {
5157 return phone.getServiceState().getDataNetworkType();
5158 } else {
5159 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5160 }
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005163 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005164 }
5165
5166 /**
5167 * Returns the data network type
5168 */
5169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005170 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005171 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5172 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005173 }
5174
5175 /**
5176 * Returns the data network type for a subId
5177 */
5178 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005179 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5180 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005181 String functionName = "getDataNetworkTypeForSubscriber";
5182 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5183 mApp, functionName)) {
5184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5185 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5186 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5187 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005188 }
5189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 final Phone phone = getPhone(subId);
5193 if (phone != null) {
5194 return phone.getServiceState().getDataNetworkType();
5195 } else {
5196 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5197 }
5198 } finally {
5199 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005201 }
5202
5203 /**
Wink Saville36469e72014-06-11 15:17:00 -07005204 * Returns the Voice network type for a subId
5205 */
5206 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005207 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5208 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005209 String functionName = "getVoiceNetworkTypeForSubscriber";
5210 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5211 mApp, functionName)) {
5212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5213 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5214 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5215 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005216 }
5217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 final Phone phone = getPhone(subId);
5221 if (phone != null) {
5222 return phone.getServiceState().getVoiceNetworkType();
5223 } else {
5224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5225 }
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005229 }
5230
5231 /**
5232 * @return true if a ICC card is present
5233 */
5234 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005235 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005236 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5237 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005238 }
5239
5240 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005241 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005242 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005244 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 final Phone phone = PhoneFactory.getPhone(slotIndex);
5248 if (phone != null) {
5249 return phone.getIccCard().hasIccCard();
5250 } else {
5251 return false;
5252 }
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005256 }
5257
5258 /**
5259 * Return if the current radio is LTE on CDMA. This
5260 * is a tri-state return value as for a period of time
5261 * the mode may be unknown.
5262 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005263 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005264 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005265 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005266 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005268 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5269 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5270 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005271 }
5272
Sanket Padawe356d7632015-06-22 14:03:32 -07005273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005274 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5275 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005276 try {
5277 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5278 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005279 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5280 }
5281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 final long identity = Binder.clearCallingIdentity();
5283 try {
5284 final Phone phone = getPhone(subId);
5285 if (phone == null) {
5286 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5287 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005288 return TelephonyProperties.lte_on_cdma_device()
5289 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 }
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005293 }
Wink Saville36469e72014-06-11 15:17:00 -07005294 }
5295
Wink Saville36469e72014-06-11 15:17:00 -07005296 /**
5297 * {@hide}
5298 * Returns Default subId, 0 in the case of single standby.
5299 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005300 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005301 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005302 }
5303
Shishir Agrawala9f32182016-04-12 12:00:16 -07005304 private int getSlotForDefaultSubscription() {
5305 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5306 }
5307
Wink Savilleb564aae2014-10-23 10:18:09 -07005308 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005309 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005310 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005311
Pengquan Menge92a50d2018-09-21 15:54:48 -07005312 private boolean isActiveSubscription(int subId) {
5313 return mSubscriptionController.isActiveSubId(subId);
5314 }
5315
Ihab Awadf2177b72013-11-25 13:33:23 -08005316 /**
5317 * @see android.telephony.TelephonyManager.WifiCallingChoices
5318 */
5319 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 final long identity = Binder.clearCallingIdentity();
5321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005322 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5324 getWhenToMakeWifiCallsDefaultPreference());
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005328 }
5329
5330 /**
5331 * @see android.telephony.TelephonyManager.WifiCallingChoices
5332 */
5333 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005337 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005342 }
5343
Sailesh Nepald1e68152013-12-12 19:08:02 -08005344 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005345 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005346 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005347 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005348
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005349 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5350 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5351 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005352 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005353 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5354 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005355 }
5356 return PhoneFactory.getPhone(phoneId);
5357 }
5358
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005360 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005361 @NonNull IccLogicalChannelRequest request) {
5362 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5363 /*message=*/ "iccOpenLogicalChannel");
5364
5365 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5366 // Verify that the callingPackage in the request belongs to the calling UID
5367 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5368
5369 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005370 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005371
Rambo Wanga1782702021-11-10 20:15:19 -08005372 private Phone getPhoneFromValidIccLogicalChannelRequest(
5373 @NonNull IccLogicalChannelRequest request, String message) {
5374 Phone phone;
5375 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5377 mApp, request.subId, message);
5378 phone = getPhoneFromSubId(request.subId);
5379 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5380 enforceModifyPermission();
5381 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5382 } else {
5383 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005384 }
Rambo Wanga1782702021-11-10 20:15:19 -08005385 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005386 }
5387
5388 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005389 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005392 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005394 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5395 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005396 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5397 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 loge("The calling package is not allowed to access ISD-R.");
5399 throw new SecurityException(
5400 "The calling package is not allowed to access ISD-R.");
5401 }
Derek Tan740e1672017-06-27 14:56:27 -07005402 }
Derek Tan740e1672017-06-27 14:56:27 -07005403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005405 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5406 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 return response;
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005411 }
5412
5413 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005414 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5415 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5416 /*message=*/"iccCloseLogicalChannel");
5417
5418 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5419
5420 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005422
Rambo Wanga1782702021-11-10 20:15:19 -08005423 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5424 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005425 // before this feature is enabled, this API should only return false if
5426 // the operation fails instead of throwing runtime exception for
5427 // backward-compatibility.
5428 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5429 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005432 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005433 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 }
Chen Xue9d737e2022-01-01 23:41:31 -08005435 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005436 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005437 Boolean success = false;
5438 if (result instanceof RuntimeException) {
5439 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005440 if (shouldThrowExceptionOnFailure) {
5441 throw (RuntimeException) result;
5442 } else {
5443 return false;
5444 }
Chen Xue9d737e2022-01-01 23:41:31 -08005445 } else if (result instanceof Boolean) {
5446 success = (Boolean) result;
5447 } else {
5448 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5449 }
Rambo Wanga1782702021-11-10 20:15:19 -08005450 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 return success;
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005455 }
5456
5457 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005458 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005459 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005462 if (DBG) {
5463 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5464 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5465 + p3 + " data=" + data);
5466 }
5467 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5468 command, p1, p2, p3, data);
5469 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005470
Jordan Liu4c733742019-02-28 12:03:40 -08005471 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005472 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5473 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005474 enforceModifyPermission();
5475 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005476 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5477 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5478 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005479 }
5480 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005481 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5482 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005483 }
5484
5485 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5486 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487 final long identity = Binder.clearCallingIdentity();
5488 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005489 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 return "";
5491 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005494 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5495 null /* workSource */);
5496 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 // Append the returned status code to the end of the response payload.
5499 String s = Integer.toHexString(
5500 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5501 if (response.payload != null) {
5502 s = IccUtils.bytesToHexString(response.payload) + s;
5503 }
5504 return s;
5505 } finally {
5506 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005507 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005508 }
Jake Hambye994d462014-02-03 13:10:13 -08005509
Evan Charltonc66da362014-05-16 14:06:40 -07005510 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005511 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5512 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005516 if (DBG) {
5517 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5518 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5519 }
5520 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5521 cla, command, p1, p2, p3, data);
5522 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005523
Jordan Liu4c733742019-02-28 12:03:40 -08005524 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005525 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5526 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005527 enforceModifyPermission();
5528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5529 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005530 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5531 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5532 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005533 }
5534
5535 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005536 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5537 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005538 }
5539
5540 // open APDU basic channel assuming the caller has sufficient permissions
5541 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5542 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5546 && TextUtils.equals(ISDR_AID, data)) {
5547 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005548 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5549 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 if (bestComponent == null
5551 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5552 loge("The calling package is not allowed to select ISD-R.");
5553 throw new SecurityException(
5554 "The calling package is not allowed to select ISD-R.");
5555 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005556 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005558 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005559 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5560 null /* workSource */);
5561 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 // Append the returned status code to the end of the response payload.
5564 String s = Integer.toHexString(
5565 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5566 if (response.payload != null) {
5567 s = IccUtils.bytesToHexString(response.payload) + s;
5568 }
5569 return s;
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005572 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005573 }
5574
5575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005576 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005577 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (DBG) {
5584 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5585 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5586 }
5587
5588 IccIoResult response =
5589 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5590 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5591 subId);
5592
5593 if (DBG) {
5594 log("Exchange SIM_IO [R]" + response);
5595 }
5596
5597 byte[] result = null;
5598 int length = 2;
5599 if (response.payload != null) {
5600 length = 2 + response.payload.length;
5601 result = new byte[length];
5602 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5603 } else {
5604 result = new byte[length];
5605 }
5606
5607 result[length - 1] = (byte) response.sw2;
5608 result[length - 2] = (byte) response.sw1;
5609 return result;
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005612 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005613 }
5614
Nathan Haroldb3014052017-01-25 15:57:32 -08005615 /**
5616 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5617 * on a particular subscription
5618 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005619 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5620 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005622 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005623 return null;
5624 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 if (appType != TelephonyManager.APPTYPE_USIM
5629 && appType != TelephonyManager.APPTYPE_SIM) {
5630 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5631 return null;
5632 }
5633 Object response = sendRequest(
5634 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5635 if (response instanceof String[]) {
5636 return (String[]) response;
5637 }
yincheng zhao2737e882019-09-06 17:06:54 -07005638 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005640 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005643 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005644 }
5645
yincheng zhao2737e882019-09-06 17:06:54 -07005646 /**
5647 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5648 * subscription.
5649 *
5650 * @param subId the id of the subscription.
5651 * @param appType the uicc app type, must be USIM or SIM.
5652 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5653 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005654 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005655 * @return number of fplmns that is successfully written to the SIM.
5656 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5658 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, subId, "setForbiddenPlmns");
5661
yincheng zhao2737e882019-09-06 17:06:54 -07005662 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5663 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5664 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5665 }
5666 if (fplmns == null) {
5667 throw new IllegalArgumentException("Fplmn List provided is null");
5668 }
5669 for (String fplmn : fplmns) {
5670 if (!CellIdentity.isValidPlmn(fplmn)) {
5671 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5672 }
5673 }
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 Object response = sendRequest(
5677 CMD_SET_FORBIDDEN_PLMNS,
5678 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5679 subId);
5680 return (int) response;
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
5684 }
5685
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005686 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005687 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5694 if (response.payload == null) {
5695 return "";
5696 }
Evan Charltonc66da362014-05-16 14:06:40 -07005697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 // Append the returned status code to the end of the response payload.
5699 String s = Integer.toHexString(
5700 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5701 s = IccUtils.bytesToHexString(response.payload) + s;
5702 return s;
5703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Evan Charltonc66da362014-05-16 14:06:40 -07005706 }
5707
Jake Hambye994d462014-02-03 13:10:13 -08005708 /**
5709 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5710 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5711 *
5712 * @param itemID the ID of the item to read
5713 * @return the NV item as a String, or null on error.
5714 */
5715 @Override
5716 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005717 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5719 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
5723 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005724 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5726 return value;
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Jake Hambye994d462014-02-03 13:10:13 -08005730 }
5731
5732 /**
5733 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5734 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5735 *
5736 * @param itemID the ID of the item to read
5737 * @param itemValue the value to write, as a String
5738 * @return true on success; false on any failure
5739 */
5740 @Override
5741 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005742 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5744 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
5747 try {
5748 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5749 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005750 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5752 return success;
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Jake Hambye994d462014-02-03 13:10:13 -08005756 }
5757
5758 /**
5759 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5760 * Used for device configuration by some CDMA operators.
5761 *
5762 * @param preferredRoamingList byte array containing the new PRL
5763 * @return true on success; false on any failure
5764 */
5765 @Override
5766 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5768 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5773 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5774 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5775 return success;
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Jake Hambye994d462014-02-03 13:10:13 -08005779 }
5780
5781 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005782 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005783 * Used for device configuration by some CDMA operators.
5784 *
chen xu6dac5ab2018-10-26 17:39:23 -07005785 * @param slotIndex - device slot.
5786 *
Jake Hambye994d462014-02-03 13:10:13 -08005787 * @return true on success; false on any failure
5788 */
5789 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005790 public boolean resetModemConfig(int slotIndex) {
5791 Phone phone = PhoneFactory.getPhone(slotIndex);
5792 if (phone != null) {
5793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5794 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795
chen xu6dac5ab2018-10-26 17:39:23 -07005796 final long identity = Binder.clearCallingIdentity();
5797 try {
5798 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5799 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5800 return success;
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 }
chen xu6dac5ab2018-10-26 17:39:23 -07005805 return false;
5806 }
5807
5808 /**
5809 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5810 *
5811 * @param slotIndex - device slot.
5812 *
5813 * @return true on success; false on any failure
5814 */
5815 @Override
5816 public boolean rebootModem(int slotIndex) {
5817 Phone phone = PhoneFactory.getPhone(slotIndex);
5818 if (phone != null) {
5819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5820 mApp, phone.getSubId(), "rebootModem");
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5825 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5826 return success;
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
5830 }
5831 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005832 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005833
Brad Ebinger51f743a2017-01-23 13:50:20 -08005834 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005835 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5836 * {@link #disableIms(int)}.
5837 * @param slotIndex device slot.
5838 */
5839 public void resetIms(int slotIndex) {
5840 enforceModifyPermission();
5841
5842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 if (mImsResolver == null) {
5845 // may happen if the does not support IMS.
5846 return;
5847 }
Hyunhoa17ac7c2022-08-30 12:03:04 +00005848 mImsResolver.resetIms(slotIndex);
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005849 } finally {
5850 Binder.restoreCallingIdentity(identity);
5851 }
5852 }
5853
5854 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005855 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5856 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005857 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005858 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005863 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005864 // may happen if the device does not support IMS.
5865 return;
5866 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005867 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005871 }
5872
5873 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005874 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5875 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005876 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005877 public void disableIms(int slotId) {
5878 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005882 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005883 // may happen if the device does not support IMS.
5884 return;
5885 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005886 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005890 }
5891
5892 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005893 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5894 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005895 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005896 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005897 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005898 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899
5900 final long identity = Binder.clearCallingIdentity();
5901 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005902 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005903 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5904 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005905 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005906 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 } finally {
5908 Binder.restoreCallingIdentity(identity);
5909 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005910 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005911 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005912 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5913 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005914 @Override
5915 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005916 enforceModifyPermission();
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005921 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005922 } finally {
5923 Binder.restoreCallingIdentity(identity);
5924 }
5925 }
5926
5927 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005928 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005929 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005930 */
5931 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5932 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933
5934 final long identity = Binder.clearCallingIdentity();
5935 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005937 // may happen if the device does not support IMS.
5938 return null;
5939 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005944 }
5945
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005946 /**
5947 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005948 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005949 */
5950 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5951 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952
5953 final long identity = Binder.clearCallingIdentity();
5954 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005955 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005956 // may happen if the device does not support IMS.
5957 return null;
5958 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005959 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005963 }
5964
Brad Ebinger884c07b2018-02-15 16:17:40 -08005965 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005966 * Sets the ImsService Package Name that Telephony will bind to.
5967 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005968 * @param slotIndex the slot ID that the ImsService should bind for.
5969 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005970 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005971 * @param featureTypes An integer array of feature types associated with a packageName.
5972 * @param packageName The name of the package that the current configuration will be replaced
5973 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005974 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005975 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005976 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5977 int[] featureTypes, String packageName) {
5978 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5979 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5981 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005982 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005986 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005987 // may happen if the device does not support IMS.
5988 return false;
5989 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005990 Map<Integer, String> featureConfig = new HashMap<>();
5991 for (int featureType : featureTypes) {
5992 featureConfig.put(featureType, packageName);
5993 }
5994 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5995 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005999 }
6000
6001 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08006002 * Clears any carrier ImsService overrides for the slot index specified that were previously
6003 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
6004 *
6005 * This should only be used for testing.
6006 *
6007 * @param slotIndex the slot ID that the ImsService should bind for.
6008 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
6009 */
6010 @Override
6011 public boolean clearCarrierImsServiceOverride(int slotIndex) {
6012 int[] subIds = SubscriptionManager.getSubId(slotIndex);
6013 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6014 "clearCarrierImsServiceOverride");
6015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
6016 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6017 "clearCarrierImsServiceOverride");
6018
6019 final long identity = Binder.clearCallingIdentity();
6020 try {
6021 if (mImsResolver == null) {
6022 // may happen if the device does not support IMS.
6023 return false;
6024 }
6025 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
6026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
6029 }
6030
6031 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08006032 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006033 *
6034 * @param slotId The slot that the ImsService is associated with.
6035 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
6036 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08006037 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07006038 * @return the package name of the ImsService configuration.
6039 */
Brad Ebinger24c29992019-12-05 13:03:21 -08006040 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
6041 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07006042 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08006043 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006044 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08006045 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
6046 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07006047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 final long identity = Binder.clearCallingIdentity();
6049 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08006050 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08006051 // may happen if the device does not support IMS.
6052 return "";
6053 }
Brad Ebingera80c3312019-12-02 10:59:39 -08006054 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08006055 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
6056 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07006060 }
6061
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006062 /**
6063 * Get the MmTelFeature state associated with the requested subscription id.
6064 * @param subId The subscription that the MmTelFeature is associated with.
6065 * @param callback A callback with an integer containing the
6066 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
6067 */
6068 @Override
6069 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
6070 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00006071 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
6072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
6073 "IMS not available on device.");
6074 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006075 final long token = Binder.clearCallingIdentity();
6076 try {
Brad Ebingera2628302022-02-18 03:44:55 +00006077 int slotId = getSlotIndex(subId);
6078 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6079 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
6080 + subId + "'");
6081 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
6082 }
6083 verifyImsMmTelConfiguredOrThrow(slotId);
6084 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
6085 try {
6086 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
6087 } catch (RemoteException e) {
6088 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
6089 + "Ignore");
6090 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006091 });
Brad Ebinger919631e2021-06-02 17:46:35 -07006092 } catch (ImsException e) {
6093 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006094 } finally {
6095 Binder.restoreCallingIdentity(token);
6096 }
6097 }
6098
Daniel Brightbb5840b2021-01-12 15:48:18 -08006099 /**
6100 * Sets the ims registration state on all valid {@link Phone}s.
6101 */
6102 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07006103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08006107 // NOTE: Before S, this method only set the default phone.
6108 for (final Phone phone : PhoneFactory.getPhones()) {
6109 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6110 phone.setImsRegistrationState(registered);
6111 }
6112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Wink Saville36469e72014-06-11 15:17:00 -07006116 }
6117
6118 /**
Stuart Scott54788802015-03-30 13:18:01 -07006119 * Set the network selection mode to automatic.
6120 *
6121 */
6122 @Override
6123 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6125 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
shilufc958392020-01-20 11:36:01 -08006129 if (!isActiveSubscription(subId)) {
6130 return;
6131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006133 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6134 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Stuart Scott54788802015-03-30 13:18:01 -07006138 }
6139
Jack Yud10cdd42020-09-28 20:28:01 -07006140 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006141 * Ask the radio to connect to the input network and change selection mode to manual.
6142 *
6143 * @param subId the id of the subscription.
6144 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6145 * the operator to attach to.
6146 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6147 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6148 * normal network selection next time.
6149 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006150 */
6151 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006152 public boolean setNetworkSelectionModeManual(
6153 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006156
6157 if (!isActiveSubscription(subId)) {
6158 return false;
6159 }
6160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 final long identity = Binder.clearCallingIdentity();
6162 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006163 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006165 if (DBG) {
6166 log("setNetworkSelectionModeManual: subId: " + subId
6167 + " operator: " + operatorInfo);
6168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006173 }
shilu84f6e8b2019-12-19 13:58:01 -08006174 /**
6175 * Get the manual network selection
6176 *
6177 * @param subId the id of the subscription.
6178 *
6179 * @return the previously saved user selected PLMN
6180 */
6181 @Override
6182 public String getManualNetworkSelectionPlmn(int subId) {
6183 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006184 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006185 mApp, subId, "getManualNetworkSelectionPlmn");
6186
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006190 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006191 }
6192
6193 final Phone phone = getPhone(subId);
6194 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006195 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006196 }
6197 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6198 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6199 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006204
6205 /**
6206 * Scans for available networks.
6207 */
6208 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006209 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6210 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6212 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006213 LocationAccessPolicy.LocationPermissionResult locationResult =
6214 LocationAccessPolicy.checkLocationPermission(mApp,
6215 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6216 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006217 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .setCallingPid(Binder.getCallingPid())
6219 .setCallingUid(Binder.getCallingUid())
6220 .setMethod("getCellNetworkScanResults")
6221 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006222 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6223 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006224 .build());
6225 switch (locationResult) {
6226 case DENIED_HARD:
6227 throw new SecurityException("Not allowed to access scan results -- location");
6228 case DENIED_SOFT:
6229 return null;
6230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006231
Pengquan Menga1bb6272018-09-06 09:59:22 -07006232 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 try {
6234 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006235 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006240 }
6241
6242 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006243 * Get the call forwarding info, given the call forwarding reason.
6244 */
6245 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006246 public void getCallForwarding(int subId, int callForwardingReason,
6247 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006248 enforceReadPrivilegedPermission("getCallForwarding");
6249 long identity = Binder.clearCallingIdentity();
6250 try {
6251 if (DBG) {
6252 log("getCallForwarding: subId " + subId
6253 + " callForwardingReason" + callForwardingReason);
6254 }
Hall Liu27d24262020-09-18 19:04:59 -07006255
6256 Phone phone = getPhone(subId);
6257 if (phone == null) {
6258 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006259 callback.onError(
6260 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006261 } catch (RemoteException e) {
6262 // ignore
6263 }
6264 return;
6265 }
6266
6267 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6268 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6269 @Override
6270 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6271 try {
6272 callback.onCallForwardingInfoAvailable(info);
6273 } catch (RemoteException e) {
6274 // ignore
6275 }
6276 }
6277
6278 @Override
6279 public void onError(int error) {
6280 try {
6281 callback.onError(error);
6282 } catch (RemoteException e) {
6283 // ignore
6284 }
6285 }
6286 });
6287 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
6293 /**
6294 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6295 * reason, the number to forward, and the timeout before the forwarding is attempted.
6296 */
6297 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006298 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6299 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006300 enforceModifyPermission();
6301 long identity = Binder.clearCallingIdentity();
6302 try {
6303 if (DBG) {
6304 log("setCallForwarding: subId " + subId
6305 + " callForwardingInfo" + callForwardingInfo);
6306 }
Hall Liu27d24262020-09-18 19:04:59 -07006307
6308 Phone phone = getPhone(subId);
6309 if (phone == null) {
6310 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006311 callback.accept(
6312 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006313 } catch (RemoteException e) {
6314 // ignore
6315 }
6316 return;
6317 }
6318
6319 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6320 FunctionalUtils.ignoreRemoteException(callback::accept));
6321
6322 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
6326 }
6327
6328 /**
Hall Liu27d24262020-09-18 19:04:59 -07006329 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006330 */
6331 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006332 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006333 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006334 long identity = Binder.clearCallingIdentity();
6335 try {
Hall Liu27d24262020-09-18 19:04:59 -07006336 Phone phone = getPhone(subId);
6337 if (phone == null) {
6338 try {
6339 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6340 } catch (RemoteException e) {
6341 // ignore
6342 }
6343 return;
6344 }
SongFerngWang0e767992021-03-31 22:08:45 +08006345 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6346 PersistableBundle c = configManager.getConfigForSubId(subId);
6347 boolean requireUssd = c.getBoolean(
6348 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006349
Shuo Qian4a594052020-01-23 11:59:30 -08006350 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006351 if (requireUssd) {
6352 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6353 getSubscriptionCarrierId(subId));
6354 String newUssdCommand = "";
6355 try {
6356 newUssdCommand = carrierXmlParser.getFeature(
6357 CarrierXmlParser.FEATURE_CALL_WAITING)
6358 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6359 } catch (NullPointerException e) {
6360 loge("Failed to generate USSD number" + e);
6361 }
6362 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6363 mMainThreadHandler, callback, carrierXmlParser,
6364 CarrierXmlParser.SsEntry.SSAction.QUERY);
6365 final String ussdCommand = newUssdCommand;
6366 Executors.newSingleThreadExecutor().execute(() -> {
6367 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6368 });
6369 } else {
6370 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6371 callback::accept);
6372 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6373 }
Shuo Qian4a594052020-01-23 11:59:30 -08006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
6377 }
6378
6379 /**
Hall Liu27d24262020-09-18 19:04:59 -07006380 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006381 */
6382 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006383 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006384 enforceModifyPermission();
6385 long identity = Binder.clearCallingIdentity();
6386 try {
Hall Liu27d24262020-09-18 19:04:59 -07006387 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6388
6389 Phone phone = getPhone(subId);
6390 if (phone == null) {
6391 try {
6392 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6393 } catch (RemoteException e) {
6394 // ignore
6395 }
6396 return;
6397 }
6398
SongFerngWang0e767992021-03-31 22:08:45 +08006399 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6400 PersistableBundle c = configManager.getConfigForSubId(subId);
6401 boolean requireUssd = c.getBoolean(
6402 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006403
SongFerngWang0e767992021-03-31 22:08:45 +08006404 if (DBG) log("getCallWaitingStatus: subId " + subId);
6405 if (requireUssd) {
6406 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6407 getSubscriptionCarrierId(subId));
6408 CarrierXmlParser.SsEntry.SSAction ssAction =
6409 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6410 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6411 String newUssdCommand = "";
6412 try {
6413 newUssdCommand = carrierXmlParser.getFeature(
6414 CarrierXmlParser.FEATURE_CALL_WAITING)
6415 .makeCommand(ssAction, null);
6416 } catch (NullPointerException e) {
6417 loge("Failed to generate USSD number" + e);
6418 }
6419 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6420 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6421 final String ussdCommand = newUssdCommand;
6422 Executors.newSingleThreadExecutor().execute(() -> {
6423 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6424 });
6425 } else {
6426 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6427 FunctionalUtils.ignoreRemoteException(callback::accept));
6428
6429 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6430 }
Shuo Qian4a594052020-01-23 11:59:30 -08006431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
yinxub1bed742017-04-17 11:45:04 -07006437 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006438 *
yinxub1bed742017-04-17 11:45:04 -07006439 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006440 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6441 * location related information which will be sent if the caller already possess
6442 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006443 * @param request contains the radio access networks with bands/channels to scan
6444 * @param messenger callback messenger for scan results or errors
6445 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006446 * @return the id of the requested scan which can be used to stop the scan.
6447 */
6448 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006449 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6450 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006451 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6453 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006454 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006455 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6456 if (!renounceFineLocationAccess) {
6457 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6458 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6459 .setCallingPackage(callingPackage)
6460 .setCallingFeatureId(callingFeatureId)
6461 .setCallingPid(Binder.getCallingPid())
6462 .setCallingUid(Binder.getCallingUid())
6463 .setMethod("requestNetworkScan")
6464 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6465 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6466 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6467 .build());
6468 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006469 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006470 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6471 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006472 if (e != null) {
6473 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6474 throw e;
6475 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006476 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006477 return TelephonyScanManager.INVALID_SCAN_ID;
6478 }
6479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 }
Hall Liu912dfd32019-04-25 14:02:26 -07006481 int callingUid = Binder.getCallingUid();
6482 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006483 final long identity = Binder.clearCallingIdentity();
6484 try {
6485 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006486 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006487 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
yinxu504e1392017-04-12 16:03:22 -07006491 }
6492
Hall Liub2ac8ef2019-02-28 15:56:23 -08006493 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006494 NetworkScanRequest request, int subId, String callingPackage) {
Rambo Wang3dee30a2022-10-20 16:52:29 +00006495 boolean hasCarrierPriv;
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
6499 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Hall Liu558027f2019-05-15 19:14:05 -07006503 boolean hasNetworkScanPermission =
6504 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6505 == PERMISSION_GRANTED;
6506
6507 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6508 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6509 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006510 }
6511
6512 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6513 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006514 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6515 return new SecurityException("Specific channels must not be"
6516 + " scanned without location access.");
6517 }
6518 }
6519 }
6520
Hall Liub2ac8ef2019-02-28 15:56:23 -08006521 return null;
6522 }
6523
yinxu504e1392017-04-12 16:03:22 -07006524 /**
6525 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006526 *
6527 * @param subId id of the subscription
6528 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006529 */
6530 @Override
6531 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6533 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534
Hall Liu912dfd32019-04-25 14:02:26 -07006535 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536 final long identity = Binder.clearCallingIdentity();
6537 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006538 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
yinxu504e1392017-04-12 16:03:22 -07006542 }
6543
6544 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006546 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006547 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006548 */
6549 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006550 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006551 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006552 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006557 if (DBG) log("getAllowedNetworkTypesBitmask");
6558 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6559 int networkTypesBitmask = (result != null ? result[0] : -1);
6560 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6561 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006565 }
6566
6567 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006568 * Get the allowed network types for certain reason.
6569 *
6570 * @param subId the id of the subscription.
6571 * @param reason the reason the allowed network type change is taking place
6572 * @return the allowed network types.
6573 */
6574 @Override
6575 public long getAllowedNetworkTypesForReason(int subId,
6576 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006577 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006578 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6582 } finally {
6583 Binder.restoreCallingIdentity(identity);
6584 }
6585 }
6586
6587 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006588 * Enable/Disable E-UTRA-NR Dual Connectivity
6589 * @param subId subscription id of the sim card
6590 * @param nrDualConnectivityState expected NR dual connectivity state
6591 * This can be passed following states
6592 * <ol>
6593 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6594 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6595 * <li>Disable NR dual connectivity and force secondary cell to be released
6596 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6597 * </ol>
6598 * @return operation result.
6599 */
6600 @Override
6601 public int setNrDualConnectivityState(int subId,
6602 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6604 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006605 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006606 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6607 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6608 }
6609
Sooraj Sasindran37444802020-08-11 10:40:43 -07006610 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6611 final long identity = Binder.clearCallingIdentity();
6612 try {
6613 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6614 nrDualConnectivityState, subId,
6615 workSource);
6616 if (DBG) log("enableNRDualConnectivity result: " + result);
6617 return result;
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
6620 }
6621 }
6622
6623 /**
6624 * Is E-UTRA-NR Dual Connectivity enabled
6625 * @return true if dual connectivity is enabled else false
6626 */
6627 @Override
6628 public boolean isNrDualConnectivityEnabled(int subId) {
6629 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006630 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006631 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006632 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006633 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6634 return false;
6635 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006636 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6640 null, subId, workSource);
6641 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6642 return isEnabled;
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
6648 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006649 * Set the allowed network types of the device and
6650 * provide the reason triggering the allowed network change.
6651 *
6652 * @param subId the id of the subscription.
6653 * @param reason the reason the allowed network type change is taking place
6654 * @param allowedNetworkTypes the allowed network types.
6655 * @return true on success; false on any failure.
6656 */
6657 @Override
6658 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006659 @TelephonyManager.AllowedNetworkTypesReason int reason,
6660 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6662 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006663 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006664 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6665 return false;
6666 }
6667 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6668 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006669 return false;
6670 }
6671
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006672 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6673 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6674
6675
6676 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6677 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6678 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006679 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006680
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006681 final long identity = Binder.clearCallingIdentity();
6682 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006683 Boolean success = (Boolean) sendRequest(
6684 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6685 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6686
6687 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6688 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
6692 }
6693
6694 /**
Miaoa84611c2019-03-15 09:21:10 +08006695 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006696 *
Miaoa84611c2019-03-15 09:21:10 +08006697 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006698 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006699 * @hide
6700 */
6701 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006702 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006703 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006705 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 try {
Miaoa84611c2019-03-15 09:21:10 +08006707 if (phone != null) {
6708 return phone.hasMatchedTetherApnSetting();
6709 } else {
6710 return false;
6711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 } finally {
6713 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006714 }
Junda Liu475951f2014-11-07 16:45:03 -08006715 }
6716
6717 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006718 * Get the user enabled state of Mobile Data.
6719 *
6720 * TODO: remove and use isUserDataEnabled.
6721 * This can't be removed now because some vendor codes
6722 * calls through ITelephony directly while they should
6723 * use TelephonyManager.
6724 *
6725 * @return true on enabled
6726 */
6727 @Override
6728 public boolean getDataEnabled(int subId) {
6729 return isUserDataEnabled(subId);
6730 }
6731
6732 /**
6733 * Get whether mobile data is enabled per user setting.
6734 *
6735 * There are other factors deciding whether mobile data is actually enabled, but they are
6736 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006737 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006738 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6739 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006740 *
6741 * @return {@code true} if data is enabled else {@code false}
6742 */
6743 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006744 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006745 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006746 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006747 try {
6748 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6749 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006750 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006751 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6752 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006753 } catch (SecurityException e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006755 mApp, subId, functionName);
6756
Robert Greenwalt646120a2014-05-23 11:54:03 -07006757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 int phoneId = mSubscriptionController.getPhoneId(subId);
6762 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6763 Phone phone = PhoneFactory.getPhone(phoneId);
6764 if (phone != null) {
6765 boolean retVal = phone.isUserDataEnabled();
6766 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6767 return retVal;
6768 } else {
6769 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6770 return false;
6771 }
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006774 }
6775 }
6776
6777 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006778 * Checks if the device is capable of mobile data by considering whether whether the
6779 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6780 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006781 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006782 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006783 */
6784 @Override
6785 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006786 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006787 try {
6788 try {
6789 mApp.enforceCallingOrSelfPermission(
6790 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006791 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006792 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006793 try {
6794 mApp.enforceCallingOrSelfPermission(
6795 android.Manifest.permission.READ_PHONE_STATE,
6796 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006797 } catch (SecurityException e2) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006798 mApp.enforceCallingOrSelfPermission(
6799 permission.READ_BASIC_PHONE_STATE, functionName);
6800 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006801 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006802 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006803 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 Phone phone = PhoneFactory.getPhone(phoneId);
6810 if (phone != null) {
Sarah Chine04784a2022-10-31 20:32:34 -07006811 boolean retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006812 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 return retVal;
6814 } else {
6815 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6816 return false;
6817 }
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006820 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006821 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006822
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006823 /**
6824 * Check if data is enabled for a specific reason
6825 * @param subId Subscription index
6826 * @param reason the reason the data enable change is taking place
6827 * @return {@code true} if the overall data is enabled; {@code false} if not.
6828 */
6829 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006830 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006831 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006832 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006833 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006834 try {
6835 mApp.enforceCallingOrSelfPermission(
6836 android.Manifest.permission.ACCESS_NETWORK_STATE,
6837 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006838 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006839 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6840 functionName);
6841 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006842 } catch (SecurityException e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006843 try {
6844 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006845 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07006846 } catch (SecurityException e2) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006848 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006849 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006850 }
6851
6852
6853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 int phoneId = mSubscriptionController.getPhoneId(subId);
6856 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006857 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006858 + " reason=" + reason);
6859 }
6860 Phone phone = PhoneFactory.getPhone(phoneId);
6861 if (phone != null) {
6862 boolean retVal;
Jack Yu7968c6d2022-07-31 00:43:21 -07006863 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006864 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006865 return retVal;
6866 } else {
6867 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006868 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006869 + subId + " retVal=false");
6870 }
6871 return false;
6872 }
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
6876 }
6877
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006879 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006880 // No permission needed; this only lets the caller inspect their own status.
6881 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006882 }
Junda Liu29340342014-07-10 15:23:27 -07006883
6884 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006885 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006886 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006887 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6888 }
6889
6890 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6891 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006892 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006893 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006894 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6895 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006896 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6897 if (cpt == null) {
6898 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6900 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006901 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006902 }
6903
6904 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006905 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006907 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006909 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006910 Phone phone = getPhone(subId);
6911 if (phone == null) {
6912 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6914 }
6915 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6916 if (cpt == null) {
6917 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6919 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006920 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006921 }
6922
6923 @Override
6924 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006925 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006926 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6927 }
6928
6929 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006930 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006931 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006932 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006933 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006934 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6935 Phone phone = PhoneFactory.getPhone(phoneId);
6936 if (phone == null) {
6937 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006938 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006939 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6940 if (cpt == null) {
6941 continue;
6942 }
6943 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006944 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6945 break;
6946 }
6947 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006948 return result;
Junda Liu29340342014-07-10 15:23:27 -07006949 }
Derek Tan89e89d42014-07-08 17:00:10 -07006950
6951 @Override
Junda Liue64de782015-04-16 17:19:16 -07006952 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006953 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006954 Phone phone = PhoneFactory.getPhone(phoneId);
6955 if (phone == null) {
6956 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006957 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006958 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6959 if (cpt == null) {
6960 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006961 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006962 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006963 }
6964
Amith Yamasani6e118872016-02-19 12:53:51 -08006965 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006966 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006967 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006968 Phone phone = PhoneFactory.getPhone(phoneId);
6969 if (phone == null) {
6970 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006971 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006972 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6973 if (cpt == null) {
6974 return Collections.emptyList();
6975 }
6976 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006977 }
6978
chen xuf7e9fe82019-05-09 19:31:02 -07006979 @Override
6980 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006981 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006982 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006983 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006984 try {
6985 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6986 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6987 }
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006990 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006991 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006992 }
6993
Rambo Wang6812ffb2022-03-15 16:54:17 -07006994 @Override
6995 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6996 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6997
6998 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6999 if (phone == null) {
7000 return null;
7001 }
7002 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
7003 if (cpt == null) {
7004 return null;
7005 }
7006 return cpt.getCarrierServicePackageName();
7007 }
7008
Wink Savilleb564aae2014-10-23 10:18:09 -07007009 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07007010 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007011 UiccPort port = phone == null ? null : phone.getUiccPort();
7012 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07007013 return null;
7014 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00007015 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07007016 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07007017 return null;
7018 }
7019 return iccId;
7020 }
7021
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07007022 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08007023 public void setCallComposerStatus(int subId, int status) {
7024 enforceModifyPermission();
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 Phone phone = getPhone(subId);
7029 if (phone != null) {
7030 Phone defaultPhone = phone.getImsPhone();
7031 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7032 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7033 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08007034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
7035 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08007036 }
7037 }
Shuo Qian284ae752020-12-22 19:10:14 -08007038 } catch (ImsException e) {
7039 throw new ServiceSpecificException(e.getCode());
7040 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08007041 Binder.restoreCallingIdentity(identity);
7042 }
7043 }
7044
7045 @Override
7046 public int getCallComposerStatus(int subId) {
7047 enforceReadPrivilegedPermission("getCallComposerStatus");
7048
7049 final long identity = Binder.clearCallingIdentity();
7050 try {
7051 Phone phone = getPhone(subId);
7052 if (phone != null) {
7053 Phone defaultPhone = phone.getImsPhone();
7054 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7055 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7056 return imsPhone.getCallComposerStatus();
7057 }
7058 }
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7063 }
7064
7065 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007066 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7067 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007068 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 final long identity = Binder.clearCallingIdentity();
7072 try {
7073 final String iccId = getIccId(subId);
7074 final Phone phone = getPhone(subId);
7075 if (phone == null) {
7076 return false;
7077 }
7078 final String subscriberId = phone.getSubscriberId();
7079
7080 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007081 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 + subscriberId + " to " + number);
7083 }
7084
7085 if (TextUtils.isEmpty(iccId)) {
7086 return false;
7087 }
7088
7089 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7090
7091 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7092 if (alphaTag == null) {
7093 editor.remove(alphaTagPrefKey);
7094 } else {
7095 editor.putString(alphaTagPrefKey, alphaTag);
7096 }
7097
7098 // Record both the line number and IMSI for this ICCID, since we need to
7099 // track all merged IMSIs based on line number
7100 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7101 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7102 if (number == null) {
7103 editor.remove(numberPrefKey);
7104 editor.remove(subscriberPrefKey);
7105 } else {
7106 editor.putString(numberPrefKey, number);
7107 editor.putString(subscriberPrefKey, subscriberId);
7108 }
7109
7110 editor.commit();
7111 return true;
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007114 }
Derek Tan7226c842014-07-02 17:42:23 -07007115 }
7116
7117 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007118 public String getLine1NumberForDisplay(int subId, String callingPackage,
7119 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007120 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007122 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007123 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007124 return null;
7125 }
Derek Tan97ebb422014-09-05 16:55:38 -07007126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 String iccId = getIccId(subId);
7130 if (iccId != null) {
7131 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7132 if (DBG_MERGE) {
7133 log("getLine1NumberForDisplay returning "
7134 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7135 }
7136 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7139 return null;
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007142 }
Derek Tan7226c842014-07-02 17:42:23 -07007143 }
7144
7145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007146 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7147 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007149 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007150 return null;
7151 }
Derek Tan97ebb422014-09-05 16:55:38 -07007152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 String iccId = getIccId(subId);
7156 if (iccId != null) {
7157 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7158 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7159 }
7160 return null;
7161 } finally {
7162 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007163 }
Derek Tan7226c842014-07-02 17:42:23 -07007164 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007165
7166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007167 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7168 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7170 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007173 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007174 return null;
7175 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007176
Jordan Liub49b04b2019-05-06 14:45:15 -07007177 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7178 // the process, where TelephonyManager was instantiated.
7179 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007180 final long identity = Binder.clearCallingIdentity();
7181 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007182 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 final TelephonyManager tele = TelephonyManager.from(context);
7184 final SubscriptionManager sub = SubscriptionManager.from(context);
7185
7186 // Figure out what subscribers are currently active
7187 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188
Jordan Liub49b04b2019-05-06 14:45:15 -07007189 // Only consider subs which match the current subId
7190 // This logic can be simplified. See b/131189269 for progress.
7191 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007192 activeSubscriberIds.add(tele.getSubscriberId(subId));
7193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 // First pass, find a number override for an active subscriber
7196 String mergeNumber = null;
7197 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7198 for (String key : prefs.keySet()) {
7199 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7200 final String subscriberId = (String) prefs.get(key);
7201 if (activeSubscriberIds.contains(subscriberId)) {
7202 final String iccId = key.substring(
7203 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7204 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7205 mergeNumber = (String) prefs.get(numberKey);
7206 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007207 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 + " for active subscriber " + subscriberId);
7209 }
7210 if (!TextUtils.isEmpty(mergeNumber)) {
7211 break;
7212 }
7213 }
7214 }
7215 }
7216
7217 // Shortcut when no active merged subscribers
7218 if (TextUtils.isEmpty(mergeNumber)) {
7219 return null;
7220 }
7221
7222 // Second pass, find all subscribers under that line override
7223 final ArraySet<String> result = new ArraySet<>();
7224 for (String key : prefs.keySet()) {
7225 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7226 final String number = (String) prefs.get(key);
7227 if (mergeNumber.equals(number)) {
7228 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7229 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7230 final String subscriberId = (String) prefs.get(subscriberKey);
7231 if (!TextUtils.isEmpty(subscriberId)) {
7232 result.add(subscriberId);
7233 }
7234 }
7235 }
7236 }
7237
7238 final String[] resultArray = result.toArray(new String[result.size()]);
7239 Arrays.sort(resultArray);
7240 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007241 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7243 }
7244 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007245 } finally {
7246 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007247 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007248 }
7249
7250 @Override
zoey chen38003472019-12-13 17:16:31 +08007251 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7252 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 final TelephonyManager telephonyManager = mApp.getSystemService(
7257 TelephonyManager.class);
7258 String subscriberId = telephonyManager.getSubscriberId(subId);
7259 if (subscriberId == null) {
7260 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007261 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007262 + subId);
7263 }
7264 return null;
7265 }
7266
7267 final SubscriptionInfo info = SubscriptionController.getInstance()
7268 .getSubscriptionInfo(subId);
7269 final ParcelUuid groupUuid = info.getGroupUuid();
7270 // If it doesn't belong to any group, return just subscriberId of itself.
7271 if (groupUuid == null) {
7272 return new String[]{subscriberId};
7273 }
7274
7275 // Get all subscriberIds from the group.
7276 final List<String> mergedSubscriberIds = new ArrayList<>();
7277 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007278 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007279 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007280 for (SubscriptionInfo subInfo : groupInfos) {
7281 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7282 if (subscriberId != null) {
7283 mergedSubscriberIds.add(subscriberId);
7284 }
7285 }
7286
7287 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7288 } finally {
7289 Binder.restoreCallingIdentity(identity);
7290
7291 }
7292 }
7293
7294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007295 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007296 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007297 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 final Phone phone = getPhone(subId);
7302 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007306 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007307
7308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007309 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007310 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7311 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007312 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7313 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 final Phone phone = getPhone(subId);
7318 if (phone == null) {
7319 return false;
7320 }
7321 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7322 cdmaNonRoamingList);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007325 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007326 }
7327
7328 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007329 @Deprecated
7330 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7331 enforceModifyPermission();
7332
7333 int returnValue = 0;
7334 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007335 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007336 if(result.exception == null) {
7337 if (result.result != null) {
7338 byte[] responseData = (byte[])(result.result);
7339 if(responseData.length > oemResp.length) {
7340 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7341 responseData.length + "bytes. Buffer Size is " +
7342 oemResp.length + "bytes.");
7343 }
7344 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7345 returnValue = responseData.length;
7346 }
7347 } else {
7348 CommandException ex = (CommandException) result.exception;
7349 returnValue = ex.getCommandError().ordinal();
7350 if(returnValue > 0) returnValue *= -1;
7351 }
7352 } catch (RuntimeException e) {
7353 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7354 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7355 if(returnValue > 0) returnValue *= -1;
7356 }
7357
7358 return returnValue;
7359 }
7360
7361 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007362 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007363 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007364 try {
7365 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007366 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007367 mApp, phone.getSubId(), "getRadioAccessFamily");
7368 } catch (SecurityException e) {
7369 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7370 throw e;
7371 }
chen xub97461a2018-10-26 14:17:57 -07007372 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007373 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007374 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 final long identity = Binder.clearCallingIdentity();
7377 try {
chen xub97461a2018-10-26 14:17:57 -07007378 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007379 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007380 mApp, phone.getSubId(), "getRadioAccessFamily");
7381 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 } finally {
7383 Binder.restoreCallingIdentity(identity);
7384 }
chen xub97461a2018-10-26 14:17:57 -07007385 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007386 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007387
7388 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007389 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007390 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007391 try {
7392 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7393 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007394 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007395 }
7396 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007397 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007398 }
7399 RoleManager rm = mApp.getSystemService(RoleManager.class);
7400 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7401 if (!dialerRoleHolders.contains(callingPackage)) {
7402 throw new SecurityException("App must be the dialer role holder to"
7403 + " upload a call composer pic");
7404 }
7405
7406 Executors.newSingleThreadExecutor().execute(() -> {
7407 ByteArrayOutputStream output = new ByteArrayOutputStream(
7408 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7409 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7410 boolean readUntilEnd = false;
7411 int totalBytesRead = 0;
7412 byte[] buffer = new byte[16 * 1024];
7413 while (true) {
7414 int numRead;
7415 try {
7416 numRead = input.read(buffer);
7417 } catch (IOException e) {
7418 try {
7419 fd.checkError();
7420 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7421 null);
7422 } catch (IOException e1) {
7423 // This means that the other side closed explicitly with an error. If this
7424 // happens, log and ignore.
7425 loge("Remote end of call composer picture pipe closed: " + e1);
7426 }
7427 break;
7428 }
7429 if (numRead == -1) {
7430 readUntilEnd = true;
7431 break;
7432 }
7433 totalBytesRead += numRead;
7434 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7435 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7436 try {
7437 input.close();
7438 } catch (IOException e) {
7439 // ignore
7440 }
7441 break;
7442 }
7443 output.write(buffer, 0, numRead);
7444 }
7445 // Generally, the remote end will close the file descriptors. The only case where we
7446 // close is above, where the picture size is too big.
7447
7448 try {
7449 fd.checkError();
7450 } catch (IOException e) {
7451 loge("Remote end for call composer closed with an error: " + e);
7452 return;
7453 }
7454
Hall Liuaa4211e2021-01-20 15:43:39 -08007455 if (!readUntilEnd) {
7456 loge("Did not finish reading entire image; aborting");
7457 return;
7458 }
Hall Liu82694d52020-12-11 18:22:04 -08007459
Hall Liuaa4211e2021-01-20 15:43:39 -08007460 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7461 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7462 new CallComposerPictureTransfer.Factory() {},
7463 imageData,
7464 (result) -> {
7465 if (result.first != null) {
7466 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7467 Bundle outputResult = new Bundle();
7468 outputResult.putParcelable(
7469 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7470 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7471 outputResult);
7472 } else {
7473 callback.send(result.second, null);
7474 }
7475 }
7476 );
Hall Liu82694d52020-12-11 18:22:04 -08007477 });
7478 }
7479
7480 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007481 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007482 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007483 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 ImsManager.getInstance(defaultPhone.getContext(),
7488 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007492 }
7493
7494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7498 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007499 return false;
7500 }
Svet Ganovb320e182015-04-16 12:30:10 -07007501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 // Check the user preference and the system-level IMS setting. Even if the user has
7505 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7506 // In the long run, we may instead need to check if there exists a connection service
7507 // which can support video calling.
7508 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007509 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 return imsManager.isVtEnabledByPlatform()
7511 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7512 && imsManager.isVtEnabledByUser();
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
7515 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007516 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007517
Andrew Leea1239f22015-03-02 17:44:07 -08007518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7520 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007522 mApp, subId, callingPackage, callingFeatureId,
7523 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 return false;
7525 }
7526
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 CarrierConfigManager configManager =
7530 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007531 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7533 } finally {
7534 Binder.restoreCallingIdentity(identity);
7535 }
Andrew Leea1239f22015-03-02 17:44:07 -08007536 }
7537
7538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007539 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007541 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 return false;
7543 }
7544
7545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 CarrierConfigManager configManager =
7548 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Andrew Leea1239f22015-03-02 17:44:07 -08007554 }
7555
Andrew Lee9431b832015-03-09 18:46:45 -07007556 @Override
7557 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007558 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007559 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007560 }
7561
7562 @Override
7563 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007566 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Andrew Lee9431b832015-03-09 18:46:45 -07007570 }
7571
Hall Liuf6668912018-10-31 17:05:23 -07007572 /**
7573 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7574 * support for the feature and device firmware support.
7575 *
7576 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7577 */
7578 @Override
7579 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581 final Phone phone = getPhone(subscriptionId);
7582 if (phone == null) {
7583 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7584 return false;
7585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007588 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7589 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 return isCarrierSupported && isDeviceSupported;
7592 } finally {
7593 Binder.restoreCallingIdentity(identity);
7594 }
Hall Liu98187582018-01-22 19:15:32 -08007595 }
7596
Hall Liuf6668912018-10-31 17:05:23 -07007597 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007598 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7599 * RTT setting, will return true if the device and carrier both support RTT.
7600 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007601 */
7602 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 final long identity = Binder.clearCallingIdentity();
7604 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007605 boolean isRttSupported = isRttSupported(subscriptionId);
7606 boolean isUserRttSettingOn = Settings.Secure.getInt(
7607 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7608 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7609 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7610 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007614 }
7615
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007616 @Deprecated
7617 @Override
7618 public String getDeviceId(String callingPackage) {
7619 return getDeviceIdWithFeature(callingPackage, null);
7620 }
7621
Sanket Padawe7310cc72015-01-14 09:53:20 -08007622 /**
7623 * Returns the unique device ID of phone, for example, the IMEI for
7624 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7625 *
7626 * <p>Requires Permission:
7627 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7628 */
7629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007630 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007631 try {
7632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7633 } catch (SecurityException se) {
7634 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7635 throw new SecurityException("Package " + callingPackage + " does not belong to "
7636 + Binder.getCallingUid());
7637 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007638 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007639 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007640 return null;
7641 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007642 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007643 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007644 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007645 return null;
7646 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 return phone.getDeviceId();
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007654 }
7655
Ping Sunc67b7c22016-03-02 19:16:45 +08007656 /**
7657 * {@hide}
7658 * Returns the IMS Registration Status on a particular subid
7659 *
7660 * @param subId
7661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007663 Phone phone = getPhone(subId);
7664 if (phone != null) {
7665 return phone.isImsRegistered();
7666 } else {
7667 return false;
7668 }
7669 }
7670
Santos Cordon7a1885b2015-02-03 11:15:19 -08007671 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007672 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007673 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007676 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7677 }
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
7684 }
7685
7686 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007687 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007688 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007689 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007690 mApp,
7691 subscriptionId,
7692 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007693 final long identity = Binder.clearCallingIdentity();
7694 try {
7695 Phone phone = getPhone(subscriptionId);
7696 if (phone == null) {
7697 return null;
7698 }
7699 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
7704
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007705 /**
7706 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007707 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 Phone phone = getPhone(subId);
7712 if (phone != null) {
7713 return phone.isWifiCallingEnabled();
7714 } else {
7715 return false;
7716 }
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007719 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007720 }
7721
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007722 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007723 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007724 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007725 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007726 final long identity = Binder.clearCallingIdentity();
7727 try {
7728 Phone phone = getPhone(subId);
7729 if (phone != null) {
7730 return phone.isVideoEnabled();
7731 } else {
7732 return false;
7733 }
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007736 }
7737 }
7738
7739 /**
7740 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7741 * defined in {@link ImsRegistrationImplBase}.
7742 */
7743 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 final long identity = Binder.clearCallingIdentity();
7745 try {
7746 Phone phone = getPhone(subId);
7747 if (phone != null) {
7748 return phone.getImsRegistrationTech();
7749 } else {
7750 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7751 }
7752 } finally {
7753 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007754 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007755 }
7756
Stuart Scott8eef64f2015-04-08 15:13:54 -07007757 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007758 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007759 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007760 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7761 return;
7762 }
Kai Shif70f46f2021-03-03 13:59:46 -08007763 Phone defaultPhone = getDefaultPhone();
7764 if (defaultPhone != null) {
7765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7766 mApp, getDefaultPhone().getSubId(), "factoryReset");
7767 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007768 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007769
Svet Ganovcc087f82015-05-12 20:35:54 -07007770 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007771 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7772 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007773 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007774 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007775 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007776 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007777 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007778 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007779 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007780 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007781 // There has been issues when Sms raw table somehow stores orphan
7782 // fragments. They lead to garbled message when new fragments come
7783 // in and combined with those stale ones. In case this happens again,
7784 // user can reset all network settings which will clean up this table.
7785 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007786 // Clean up IMS settings as well here.
7787 int slotId = getSlotIndex(subId);
7788 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7789 ImsManager.getInstance(mApp, slotId).factoryReset();
7790 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007791
Kai Shif70f46f2021-03-03 13:59:46 -08007792 if (defaultPhone == null) {
7793 return;
7794 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007795 // Erase modem config if erase modem on network setting is enabled.
7796 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7797 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7798 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007799 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007800 }
Kai Shif70f46f2021-03-03 13:59:46 -08007801
7802 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007803 } finally {
7804 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007805 }
7806 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007807
SongFerngWangfd89b102021-05-27 22:44:54 +08007808 @VisibleForTesting
7809 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7810 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7811 return;
7812 }
7813 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7814 RILConstants.PREFERRED_NETWORK_MODE);
7815 SubscriptionManager.setSubscriptionProperty(subId,
7816 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7817 "user=" + defaultNetworkType);
7818 phone.loadAllowedNetworksFromSubscriptionDatabase();
7819 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7820 defaultNetworkType, null);
7821 }
7822
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007823 private void cleanUpSmsRawTable(Context context) {
7824 ContentResolver resolver = context.getContentResolver();
7825 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7826 resolver.delete(uri, null, null);
7827 }
7828
Narayan Kamath1c496c22015-04-16 14:40:19 +01007829 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007830 public String getSimLocaleForSubscriber(int subId) {
7831 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7832 final Phone phone = getPhone(subId);
7833 if (phone == null) {
7834 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007835 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837 final long identity = Binder.clearCallingIdentity();
7838 try {
chen xu5d3637b2019-01-21 23:31:38 -08007839 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007840 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007841 if (info == null) {
7842 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7843 return null;
7844 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 // Try and fetch the locale from the carrier properties or from the SIM language
7846 // preferences (EF-PL and EF-LI)...
7847 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007849 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7850 if (localeFromDefaultSim != null) {
7851 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7852 if (DBG) log("Using locale from subId: " + subId + " locale: "
7853 + localeFromDefaultSim);
Greg Kaiser4380e732022-10-25 16:07:20 +00007854 return matchLocaleFromSupportedLocaleList(localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007855 } else {
7856 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007857 }
7858 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 // The SIM language preferences only store a language (e.g. fr = French), not an
7861 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7862 // the SIM and carrier preferences does not include a country we add the country
7863 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007864 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007866 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Greg Kaiser4380e732022-10-25 16:07:20 +00007867 return matchLocaleFromSupportedLocaleList(mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 }
7869
7870 if (DBG) log("No locale found - returning null");
7871 return null;
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007875 }
7876
tom hsu0b59d292022-09-29 23:49:21 +08007877 @VisibleForTesting
Greg Kaiser4380e732022-10-25 16:07:20 +00007878 String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) {
tom hsu0b59d292022-09-29 23:49:21 +08007879 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
Greg Kaiser4380e732022-10-25 16:07:20 +00007880 getDefaultPhone().getContext());
tom hsu0b59d292022-09-29 23:49:21 +08007881 for (String localeTag : supportedLocale) {
7882 if (LocaleList.matchesLanguageAndScript(
7883 inputLocale, Locale.forLanguageTag(localeTag))
7884 && inputLocale.getCountry().equals(
7885 Locale.forLanguageTag(localeTag).getCountry())) {
7886 return localeTag;
7887 }
7888 }
7889 return inputLocale.toLanguageTag();
7890 }
7891
Narayan Kamath1c496c22015-04-16 14:40:19 +01007892 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007894 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007895 }
7896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 /**
7898 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7899 */
7900 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007901 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007902 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007903 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007904
Gary Jian3aa9a762022-01-24 16:41:19 +08007905 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7906 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007907
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007908 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007909 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7910 * representing the state of the modem.
7911 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007912 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7913 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007914 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007915 */
7916 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007917 public void requestModemActivityInfo(ResultReceiver result) {
7918 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920
7921 final long identity = Binder.clearCallingIdentity();
7922 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007923 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007926 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007927 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007928
Siddharth Rayb8114062018-06-17 15:02:38 -07007929 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7930 // less than total activity duration.
7931 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7932 if (info == null) {
7933 return false;
7934 }
7935 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007936 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7937 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7938
Siddharth Rayb8114062018-06-17 15:02:38 -07007939 return (info.isValid()
7940 && (info.getSleepTimeMillis() <= activityDurationMs)
7941 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007942 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007943 && (totalTxTimeMs <= activityDurationMs));
7944 }
7945
Gary Jian3aa9a762022-01-24 16:41:19 +08007946 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7947 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7948 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7949 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7950
7951 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7952 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7953 }
7954
7955 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7956 mLastModemActivityInfo.setReceiveTimeMillis(
7957 rat,
7958 freq,
7959 info.getReceiveTimeMillis(rat, freq)
7960 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7961 }
7962
7963 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7964 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7965 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7966 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7967
7968 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7969 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7970 }
7971 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7972 mLastModemActivityInfo.setReceiveTimeMillis(
7973 rat,
7974 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7975 }
7976
7977 /**
7978 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7979 * @param info recent ModemActivityInfo
7980 */
7981 private void mergeModemActivityInfo(ModemActivityInfo info) {
7982 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7983 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7984 boolean matched;
7985 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7986 matched = false;
7987 int rat = info.getSpecificInfoRat(i);
7988 int freq = info.getSpecificInfoFrequencyRange(i);
7989 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7990 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7991 //if it already exists
7992 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7993 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7994 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7995 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7996 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7997 updateLastModemActivityInfo(info, rat, freq);
7998 matched = true;
7999 }
8000 } else {
8001 updateLastModemActivityInfo(info, rat);
8002 matched = true;
8003 }
8004 }
8005 }
8006
8007 if (!matched) {
8008 mDeltaSpecificInfo =
8009 new ActivityStatsTechSpecificInfo(
8010 rat,
8011 freq,
8012 info.getTransmitTimeMillis(rat, freq),
8013 (int) info.getReceiveTimeMillis(rat, freq));
8014 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
8015 }
8016 }
8017 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
8018 mLastModemActivitySpecificInfo =
8019 new ActivityStatsTechSpecificInfo[merged.size()];
8020 merged.toArray(mLastModemActivitySpecificInfo);
8021
8022 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
8023 mLastModemActivityInfo.setSleepTimeMillis(
8024 info.getSleepTimeMillis()
8025 + mLastModemActivityInfo.getSleepTimeMillis());
8026 mLastModemActivityInfo.setIdleTimeMillis(
8027 info.getIdleTimeMillis()
8028 + mLastModemActivityInfo.getIdleTimeMillis());
8029 }
8030
Jack Yu85bd38a2015-11-09 11:34:32 -08008031 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08008032 * Returns the service state information on specified subscription.
8033 */
8034 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008035 public ServiceState getServiceStateForSubscriber(int subId,
8036 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
8037 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008039 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08008040 return null;
8041 }
8042
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008043 boolean hasFinePermission = false;
8044 boolean hasCoarsePermission = false;
8045 if (!renounceFineLocationAccess) {
8046 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
8047 LocationAccessPolicy.checkLocationPermission(mApp,
8048 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8049 .setCallingPackage(callingPackage)
8050 .setCallingFeatureId(callingFeatureId)
8051 .setCallingPid(Binder.getCallingPid())
8052 .setCallingUid(Binder.getCallingUid())
8053 .setMethod("getServiceStateForSubscriber")
8054 .setLogAsInfo(true)
8055 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
8056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8057 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8058 .build());
8059 hasFinePermission =
8060 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8061 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008062
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08008063 if (!renounceCoarseLocationAccess) {
8064 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
8065 LocationAccessPolicy.checkLocationPermission(mApp,
8066 new LocationAccessPolicy.LocationPermissionQuery.Builder()
8067 .setCallingPackage(callingPackage)
8068 .setCallingFeatureId(callingFeatureId)
8069 .setCallingPid(Binder.getCallingPid())
8070 .setCallingUid(Binder.getCallingUid())
8071 .setMethod("getServiceStateForSubscriber")
8072 .setLogAsInfo(true)
8073 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
8074 .setMinSdkVersionForFine(Integer.MAX_VALUE)
8075 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
8076 .build());
8077 hasCoarsePermission =
8078 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
8079 }
Hall Liuf19c44f2018-11-27 14:38:17 -08008080
Jack Yu479f40e2020-10-27 21:29:25 -07008081 final Phone phone = getPhone(subId);
8082 if (phone == null) {
8083 return null;
8084 }
8085
Jordan Liu0f2bc442020-11-18 16:47:37 -08008086 final long identity = Binder.clearCallingIdentity();
8087
Jack Yu479f40e2020-10-27 21:29:25 -07008088 boolean isCallingPackageDataService = phone.getDataServicePackages()
8089 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008090 try {
Jordan Liuc437b192020-08-17 10:59:12 -07008091 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
8092 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
8093 Rlog.d(LOG_TAG,
8094 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
8095 return null;
8096 }
8097
Hall Liuf19c44f2018-11-27 14:38:17 -08008098 ServiceState ss = phone.getServiceState();
8099
8100 // Scrub out the location info in ServiceState depending on what level of access
8101 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07008102 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08008103 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
8104 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Jack Yu85bd38a2015-11-09 11:34:32 -08008108 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008109
8110 /**
8111 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
8112 *
8113 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8114 * voicemail ringtone.
8115 * @return The URI for the ringtone to play when receiving a voicemail from a specific
8116 * PhoneAccount.
8117 */
8118 @Override
8119 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8123 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008124 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008131 }
8132
8133 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008134 * Sets the per-account voicemail ringtone.
8135 *
8136 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8137 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8138 *
8139 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8140 * voicemail ringtone.
8141 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8142 * PhoneAccount.
8143 */
8144 @Override
8145 public void setVoicemailRingtoneUri(String callingPackage,
8146 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008147 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008149 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8150 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8152 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8153 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008154 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8159 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008160 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 }
8162 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008165 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008166 }
8167
8168 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008169 * Returns whether vibration is set for voicemail notification in Phone settings.
8170 *
8171 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8172 * voicemail vibration setting.
8173 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8174 */
8175 @Override
8176 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 final long identity = Binder.clearCallingIdentity();
8178 try {
8179 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8180 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008181 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008188 }
8189
Youhan Wange64578a2016-05-02 15:32:42 -07008190 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008191 * Sets the per-account voicemail vibration.
8192 *
8193 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8194 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8195 *
8196 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8197 * voicemail vibration setting.
8198 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8199 * specific PhoneAccount.
8200 */
8201 @Override
8202 public void setVoicemailVibrationEnabled(String callingPackage,
8203 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008205 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008206 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8207 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8209 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8210 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008211 }
8212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8216 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008217 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 }
8219 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008222 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008223 }
8224
8225 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008226 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8227 *
8228 * @throws SecurityException if the caller does not have the required permission
8229 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008230 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008232 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008233 }
8234
8235 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008236 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8237 * permission.
8238 *
8239 * @throws SecurityException if the caller does not have the required permission
8240 */
8241 private void enforceSendSmsPermission() {
8242 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8243 }
8244
8245 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008246 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008247 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008248 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008249 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008250 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 final long identity = Binder.clearCallingIdentity();
8252 try {
8253 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008254 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008255 if (componentName == null) {
8256 throw new SecurityException(
8257 "Caller not current active visual voicemail package[null]");
8258 }
8259 String vvmPackage = componentName.getPackageName();
8260 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008261 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008262 }
8263 } finally {
8264 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008265 }
8266 }
8267
8268 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008269 * Return the application ID for the app type.
8270 *
8271 * @param subId the subscription ID that this request applies to.
8272 * @param appType the uicc app type.
8273 * @return Application ID for specificied app type, or null if no uicc.
8274 */
8275 @Override
8276 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008277 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008278 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279
8280 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008281 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282 if (phone == null) {
8283 return null;
8284 }
8285 String aid = null;
8286 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008287 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 .getApplicationByType(appType).getAid();
8289 } catch (Exception e) {
8290 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8291 }
8292 return aid;
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008295 }
Youhan Wange64578a2016-05-02 15:32:42 -07008296 }
8297
Youhan Wang4001d252016-05-11 10:29:41 -07008298 /**
8299 * Return the Electronic Serial Number.
8300 *
8301 * @param subId the subscription ID that this request applies to.
8302 * @return ESN or null if error.
8303 */
8304 @Override
8305 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008307 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308
8309 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008310 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311 if (phone == null) {
8312 return null;
8313 }
8314 String esn = null;
8315 try {
8316 esn = phone.getEsn();
8317 } catch (Exception e) {
8318 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8319 }
8320 return esn;
8321 } finally {
8322 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008323 }
Youhan Wang4001d252016-05-11 10:29:41 -07008324 }
8325
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008326 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008327 * Return the Preferred Roaming List Version.
8328 *
8329 * @param subId the subscription ID that this request applies to.
8330 * @return PRLVersion or null if error.
8331 */
8332 @Override
8333 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008334 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008335 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008336
8337 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008338 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008339 if (phone == null) {
8340 return null;
8341 }
8342 String cdmaPrlVersion = null;
8343 try {
8344 cdmaPrlVersion = phone.getCdmaPrlVersion();
8345 } catch (Exception e) {
8346 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8347 }
8348 return cdmaPrlVersion;
8349 } finally {
8350 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008351 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008352 }
8353
8354 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008355 * Get snapshot of Telephony histograms
8356 * @return List of Telephony histograms
8357 * @hide
8358 */
8359 @Override
8360 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8362 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 return RIL.getTelephonyRILTimingHistograms();
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008370 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008371
8372 /**
8373 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008374 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8375 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008376 * Require system privileges. In the future we may add this to carrier APIs.
8377 *
Michele Berionne482f8202018-11-27 18:57:59 -08008378 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008379 */
8380 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008381 @TelephonyManager.SetCarrierRestrictionResult
8382 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008383 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008384 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008385
Michele Berionne482f8202018-11-27 18:57:59 -08008386 if (carrierRestrictionRules == null) {
8387 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008388 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 final long identity = Binder.clearCallingIdentity();
8391 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008392 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008393 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394 } finally {
8395 Binder.restoreCallingIdentity(identity);
8396 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008397 }
8398
8399 /**
8400 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008401 * Get the allowed carrier list and the excluded carrier list, including the priority between
8402 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008403 * Require system privileges. In the future we may add this to carrier APIs.
8404 *
Michele Berionne482f8202018-11-27 18:57:59 -08008405 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008406 */
8407 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008408 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008409 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008414 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8415 if (response instanceof CarrierRestrictionRules) {
8416 return (CarrierRestrictionRules) response;
8417 }
8418 // Response is an Exception of some kind,
8419 // which is signalled to the user as a NULL retval
8420 return null;
8421 } catch (Exception e) {
8422 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8423 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008427 }
8428
fionaxu59545b42016-05-25 15:53:37 -07008429 /**
fionaxu59545b42016-05-25 15:53:37 -07008430 * Action set from carrier signalling broadcast receivers to enable/disable radio
8431 * @param subId the subscription ID that this action applies to.
8432 * @param enabled control enable or disable radio.
8433 * {@hide}
8434 */
8435 @Override
8436 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8437 enforceModifyPermission();
8438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008439
8440 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008441 if (phone == null) {
8442 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8443 return;
8444 }
8445 try {
8446 phone.carrierActionSetRadioEnabled(enabled);
8447 } catch (Exception e) {
8448 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008449 } finally {
8450 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008451 }
8452 }
8453
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008454 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008455 * Enable or disable Voice over NR (VoNR)
8456 * @param subId the subscription ID that this action applies to.
8457 * @param enabled enable or disable VoNR.
8458 * @return operation result.
8459 */
8460 @Override
8461 public int setVoNrEnabled(int subId, boolean enabled) {
8462 enforceModifyPermission();
8463 final Phone phone = getPhone(subId);
8464
8465 final long identity = Binder.clearCallingIdentity();
8466 if (phone == null) {
8467 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8468 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8469 }
8470
8471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8472 try {
8473 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8474 workSource);
8475 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008476
8477 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8478 if (DBG) {
8479 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8480 }
8481 SubscriptionManager.setSubscriptionProperty(
8482 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8483 (enabled ? "1" : "0"));
8484 }
8485
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008486 return result;
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
8490 }
8491
8492 /**
8493 * Is voice over NR enabled
8494 * @return true if VoNR is enabled else false
8495 */
8496 @Override
8497 public boolean isVoNrEnabled(int subId) {
8498 enforceReadPrivilegedPermission("isVoNrEnabled");
8499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8503 null, subId, workSource);
8504 if (DBG) log("isVoNrEnabled: " + isEnabled);
8505 return isEnabled;
8506 } finally {
8507 Binder.restoreCallingIdentity(identity);
8508 }
8509 }
8510
8511 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008512 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8513 * network status based on which carrier apps could apply actions accordingly,
8514 * enable/disable default url handler for example.
8515 *
8516 * @param subId the subscription ID that this action applies to.
8517 * @param report control start/stop reporting the default network status.
8518 * {@hide}
8519 */
8520 @Override
8521 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8522 enforceModifyPermission();
8523 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524
8525 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008526 if (phone == null) {
8527 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8528 return;
8529 }
8530 try {
8531 phone.carrierActionReportDefaultNetworkStatus(report);
8532 } catch (Exception e) {
8533 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 } finally {
8535 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008536 }
8537 }
8538
8539 /**
fionaxud9622282017-07-17 17:51:30 -07008540 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8541 * @param subId the subscription ID that this action applies to.
8542 * {@hide}
8543 */
8544 @Override
8545 public void carrierActionResetAll(int subId) {
8546 enforceModifyPermission();
8547 final Phone phone = getPhone(subId);
8548 if (phone == null) {
8549 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8550 return;
8551 }
8552 try {
8553 phone.carrierActionResetAll();
8554 } catch (Exception e) {
8555 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8556 }
8557 }
8558
8559 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008560 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8561 * bug report is being generated.
8562 */
8563 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008564 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8566 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008567 writer.println("Permission Denial: can't dump Phone from pid="
8568 + Binder.getCallingPid()
8569 + ", uid=" + Binder.getCallingUid()
8570 + "without permission "
8571 + android.Manifest.permission.DUMP);
8572 return;
8573 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008574 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008575 }
Jack Yueb89b242016-06-22 13:27:47 -07008576
Brad Ebingerdac2f002018-04-03 15:17:52 -07008577 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008578 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8579 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8580 @NonNull String[] args) {
8581 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8582 this, in.getFileDescriptor(), out.getFileDescriptor(),
8583 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008584 }
8585
Jack Yueb89b242016-06-22 13:27:47 -07008586 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008587 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008588 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008589 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008590 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008591 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008592 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008593 */
8594 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008595 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008596 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008597 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8598 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8599 try {
8600 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008601 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008602 } catch (SecurityException se) {
8603 enforceModifyPermission();
8604 }
8605 } else {
8606 enforceModifyPermission();
8607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008608
8609 final long identity = Binder.clearCallingIdentity();
8610 try {
8611 Phone phone = getPhone(subId);
8612 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008613 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8614 phone.carrierActionSetMeteredApnsEnabled(enabled);
8615 } else {
Jack Yu7968c6d2022-07-31 00:43:21 -07008616 phone.getDataSettingsManager().setDataEnabled(
8617 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008619 }
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008622 }
8623 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008624
8625 /**
8626 * Get Client request stats
8627 * @return List of Client Request Stats
8628 * @hide
8629 */
8630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008631 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8632 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008634 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008635 return null;
8636 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008637 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008639 final long identity = Binder.clearCallingIdentity();
8640 try {
8641 if (phone != null) {
8642 return phone.getClientRequestStats();
8643 }
8644
8645 return null;
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008649 }
8650
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008651 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008652 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008653 if (uid == Process.ROOT_UID && packageName == null) {
8654 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8655 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8656 // exception. ROOT_UID seems not to have a valid package name returned by
8657 // PackageManager, so just fake it here to avoid issues when running telephony shell
8658 // commands that plumb through the RIL as root, like so:
8659 // $ adb root
8660 // $ adb shell cmd phone ...
8661 packageName = "root";
8662 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008663 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008664 }
Jack Yueb4124c2017-02-16 15:32:43 -08008665
8666 /**
Grace Chen70990072017-03-24 17:21:30 -07008667 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008668 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008669 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008670 * @param state State of SIM (power down, power up, pass through)
8671 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8672 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8673 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008674 *
8675 **/
8676 @Override
Grace Chen70990072017-03-24 17:21:30 -07008677 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008678 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008679 Phone phone = PhoneFactory.getPhone(slotIndex);
8680
vagdeviaf9a5b92018-08-15 16:01:53 -07008681 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8682
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008686 phone.setSimPowerState(state, null, workSource);
8687 }
8688 } finally {
8689 Binder.restoreCallingIdentity(identity);
8690 }
8691 }
8692
8693 /**
8694 * Set SIM card power state.
8695 *
8696 * @param slotIndex SIM slot id.
8697 * @param state State of SIM (power down, power up, pass through)
8698 * @param callback callback to trigger after success or failure
8699 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8700 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8702 *
8703 **/
8704 @Override
8705 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8706 IIntegerConsumer callback) {
8707 enforceModifyPermission();
8708 Phone phone = PhoneFactory.getPhone(slotIndex);
8709
8710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8711
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 if (phone != null) {
8715 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8716 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008717 }
8718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008720 }
8721 }
Shuo Qiandd210312017-04-12 22:11:33 +00008722
Tyler Gunn65d45c22017-06-05 11:22:26 -07008723 private boolean isUssdApiAllowed(int subId) {
8724 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008725 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008726 if (configManager == null) {
8727 return false;
8728 }
8729 PersistableBundle pb = configManager.getConfigForSubId(subId);
8730 if (pb == null) {
8731 return false;
8732 }
8733 return pb.getBoolean(
8734 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8735 }
8736
Shuo Qiandd210312017-04-12 22:11:33 +00008737 /**
8738 * Check if phone is in emergency callback mode
8739 * @return true if phone is in emergency callback mode
8740 * @param subId sub id
8741 */
goneil9c5f4872017-12-05 14:07:56 -08008742 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008743 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008744 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 if (phone != null) {
8750 return phone.isInEcm();
8751 } else {
8752 return false;
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008756 }
8757 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008758
8759 /**
8760 * Get the current signal strength information for the given subscription.
8761 * Because this information is not updated when the device is in a low power state
8762 * it should not be relied-upon to be current.
8763 * @param subId Subscription index
8764 * @return the most recent cached signal strength info from the modem
8765 */
8766 @Override
8767 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 Phone p = getPhone(subId);
8771 if (p == null) {
8772 return null;
8773 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008775 return p.getSignalStrength();
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008779 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008780
Pengquan Meng77b7f132018-08-22 14:49:57 -07008781 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008782 * Get the current modem radio state for the given slot.
8783 * @param slotIndex slot index.
8784 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008785 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008786 * @return the current radio power state from the modem
8787 */
8788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008789 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008790 Phone phone = PhoneFactory.getPhone(slotIndex);
8791 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8793 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008794 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8795 }
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 return phone.getRadioPowerState();
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
8804 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8805 }
8806
8807 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008808 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8809 *
8810 * <p>Requires one of the following permissions:
8811 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008812 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008813 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8814 * privileges.
8815 *
8816 * @param subId subscription id
8817 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8818 * {@code false}.
8819 */
8820 @Override
8821 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008822 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008823 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008824 try {
8825 mApp.enforceCallingOrSelfPermission(
8826 android.Manifest.permission.ACCESS_NETWORK_STATE,
8827 functionName);
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008828 } catch (SecurityException e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008829 mApp.enforceCallingOrSelfPermission(
8830 permission.READ_BASIC_PHONE_STATE, functionName);
8831 }
Sooraj Sasindran12545cc2022-08-22 14:30:25 -07008832 } catch (SecurityException e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008833 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008834 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008835 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008836
Pengquan Menga1bb6272018-09-06 09:59:22 -07008837 boolean isEnabled = false;
8838 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008839 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008840 Phone phone = getPhone(subId);
8841 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008842 } finally {
8843 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008844 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008845 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008846 }
8847
8848
8849 /**
8850 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8851 *
8852 * <p> Requires permission:
8853 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8854 * privileges.
8855 *
8856 * @param subId subscription id
8857 * @param isEnabled {@code true} means enable, {@code false} means disable.
8858 */
8859 @Override
8860 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8862 mApp, subId, "setDataRoamingEnabled");
8863
Pengquan Menga1bb6272018-09-06 09:59:22 -07008864 final long identity = Binder.clearCallingIdentity();
8865 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008866 Phone phone = getPhone(subId);
8867 if (phone != null) {
8868 phone.setDataRoamingEnabled(isEnabled);
8869 }
8870 } finally {
8871 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008872 }
8873 }
8874
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008875 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008876 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008877 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008878 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008879 mApp, subId, "isManualNetworkSelectionAllowed");
8880
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008881 boolean isAllowed = true;
8882 final long identity = Binder.clearCallingIdentity();
8883 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008884 Phone phone = getPhone(subId);
8885 if (phone != null) {
8886 isAllowed = phone.isCspPlmnEnabled();
8887 }
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 return isAllowed;
8892 }
8893
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008894 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8895 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008896 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008897 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008898 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008899 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8900 if (phone == null) {
8901 return false;
8902 }
8903 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8904 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8905 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008906 }
8907
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008908 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008909 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008910 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008911 mApp.getSystemService(AppOpsManager.class)
8912 .checkPackage(Binder.getCallingUid(), callingPackage);
8913
Jordan Liu1e142fc2019-04-22 15:10:43 -07008914 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008915 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008916 try {
8917 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008918 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008919 } catch (SecurityException e) {
8920 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8921 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008922 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008923 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008924 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008925 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008926 }
sandeepjsb6c87872021-09-27 15:34:44 +00008927 // checking compatibility, if calling app's target SDK is T and beyond.
8928 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8929 Binder.getCallingUid())) {
8930 isIccIdAccessRestricted = true;
8931 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008932 final long identity = Binder.clearCallingIdentity();
8933 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008934 UiccController uiccController = UiccController.getInstance();
8935 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008936 if (hasReadPermission) {
8937 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008938 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008939
8940 // Remove private info if the caller doesn't have access
8941 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8942 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008943 //setting the value after compatibility check
8944 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008945 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8946 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008947 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008948 if (card == null) {
8949 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008950 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008951 continue;
8952 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008953 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8954 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008955 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008956 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008957 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008958 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8959 for (UiccPortInfo portInfo : portInfos) {
8960 UiccPort port = uiccController.getUiccPortForSlot(
8961 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8962 if (port == null) {
8963 // assume no access if port is null
8964 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8965 continue;
8966 }
8967 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8968 uiccPortInfos.add(portInfo);
8969 } else {
8970 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8971 }
8972 }
8973 filteredInfos.add(new UiccCardInfo(
8974 cardInfo.isEuicc(),
8975 cardInfo.getCardId(),
8976 null,
8977 cardInfo.getPhysicalSlotIndex(),
8978 cardInfo.isRemovable(),
8979 cardInfo.isMultipleEnabledProfilesSupported(),
8980 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008981 }
8982 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
sandeepjsb6c87872021-09-27 15:34:44 +00008988 /**
8989 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8990 * generally private and require carrier privileges to view.
8991 *
8992 * @hide
8993 */
8994 @NonNull
8995 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8996 List<UiccPortInfo> portinfo = new ArrayList<>();
8997 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8998 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8999 }
9000 return new UiccCardInfo(
9001 cardInfo.isEuicc(),
9002 cardInfo.getCardId(),
9003 null,
9004 cardInfo.getPhysicalSlotIndex(),
9005 cardInfo.isRemovable(),
9006 cardInfo.isMultipleEnabledProfilesSupported(),
9007 portinfo
9008 );
9009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009010
sandeepjsb6c87872021-09-27 15:34:44 +00009011 /**
9012 * @hide
9013 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
9014 * These values are generally private and require carrier privileges to view.
9015 */
9016 @NonNull
9017 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
9018 return new UiccPortInfo(
9019 UiccPortInfo.ICCID_REDACTED,
9020 portInfo.getPortIndex(),
9021 portInfo.getLogicalSlotIndex(),
9022 portInfo.isActive()
9023 );
9024 }
9025 @Override
9026 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00009027 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00009028 mApp.getSystemService(AppOpsManager.class)
9029 .checkPackage(Binder.getCallingUid(), callingPackage);
9030
sandeepjsb6c87872021-09-27 15:34:44 +00009031 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00009032
Aman Guptaf3c90b32022-03-17 04:54:16 +00009033 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
9034 // we are reading iccId which is PII data.
9035 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00009036
9037 // checking compatibility, if calling app's target SDK is T and beyond.
9038 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
9039 Binder.getCallingUid())) {
9040 isLogicalSlotAccessRestricted = true;
9041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00009045 if (slots == null || slots.length == 0) {
9046 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009047 return null;
9048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009049 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
9050 for (int i = 0; i < slots.length; i++) {
9051 UiccSlot slot = slots[i];
9052 if (slot == null) {
9053 continue;
9054 }
9055
Jordan Liu7be7e652019-05-06 18:55:02 +00009056 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009057 UiccCard card = slot.getUiccCard();
9058 if (card != null) {
9059 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00009060 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07009061 cardId = slot.getEid();
9062 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00009063 // If cardId is null, use iccId of default port as cardId.
9064 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07009065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009066 }
9067
Jordan Liu857451f2019-05-09 16:35:35 -07009068 if (cardId != null) {
9069 // if cardId is an ICCID, strip off trailing Fs before exposing to user
9070 // if cardId is an EID, it's all digits so this is fine
9071 cardId = IccUtils.stripTrailingFs(cardId);
9072 }
9073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009074 int cardState = 0;
9075 switch (slot.getCardState()) {
9076 case CARDSTATE_ABSENT:
9077 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
9078 break;
9079 case CARDSTATE_PRESENT:
9080 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
9081 break;
9082 case CARDSTATE_ERROR:
9083 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
9084 break;
9085 case CARDSTATE_RESTRICTED:
9086 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
9087 break;
9088 default:
9089 break;
9090
9091 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009092 List<UiccPortInfo> portInfos = new ArrayList<>();
9093 int[] portIndexes = slot.getPortList();
9094 for (int portIdx : portIndexes) {
9095 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00009096 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00009097 portInfos.add(new UiccPortInfo(iccId, portIdx,
9098 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009100 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009101 slot.isEuicc(),
9102 cardId,
9103 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08009104 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009105 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00009106 //setting the value after compatibility check
9107 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009108 }
9109 return infos;
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07009112 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009113 }
9114
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009115 /* Returns null if doesn't have read permission or carrier privilege access. */
9116 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
9117 boolean hasReadPermission) {
9118 String iccId = slot.getIccId(portIndex);
9119 if (hasReadPermission) { // if has read permission
9120 return iccId;
9121 } else {
9122 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
9123 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9124 // if no read permission, checking carrier privilege access
9125 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9126 return iccId;
9127 }
9128 }
9129 }
9130 // No read permission or carrier privilege access.
9131 return UiccPortInfo.ICCID_REDACTED;
9132 }
9133
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009134 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009135 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009136 public boolean switchSlots(int[] physicalSlots) {
9137 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009138
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009141 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9142 for (int i = 0; i < physicalSlots.length; i++) {
9143 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9144 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9145 physicalSlots[i], i));
9146 }
9147 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009151 }
Jack Yu4c988042018-02-27 15:30:01 -08009152
9153 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009154 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9155 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9156 enforceModifyPermission();
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009160 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009167 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 return UiccController.getInstance().getCardIdForDefaultEuicc();
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
Pengquan Meng85728fb2018-03-12 16:31:21 -07009176 /**
goneil47ffb6e2018-04-06 15:40:58 -07009177 * A test API to reload the UICC profile.
9178 *
9179 * <p>Requires that the calling app has permission
9180 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9181 * @hide
9182 */
9183 @Override
9184 public void refreshUiccProfile(int subId) {
9185 enforceModifyPermission();
9186
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
9189 Phone phone = getPhone(subId);
9190 if (phone == null) {
9191 return;
9192 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009193 UiccPort uiccPort = phone.getUiccPort();
9194 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009195 return;
9196 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009197 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009198 if (uiccProfile == null) {
9199 return;
9200 }
9201 uiccProfile.refresh();
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
9207 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009208 * Returns false if the mobile data is disabled by default, otherwise return true.
9209 */
9210 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009211 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009212 }
9213
9214 /**
9215 * Returns true if the data roaming is enabled by default, i.e the system property
9216 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9217 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9218 */
9219 private boolean getDefaultDataRoamingEnabled(int subId) {
9220 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009221 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009222 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009223 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9224 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9225 return isDataRoamingEnabled;
9226 }
9227
9228 /**
9229 * Returns the default network type for the given {@code subId}, if the default network type is
9230 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9231 */
9232 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009233 List<Integer> list = TelephonyProperties.default_network();
9234 int phoneId = mSubscriptionController.getPhoneId(subId);
9235 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9236 return list.get(phoneId);
9237 }
9238 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009239 }
fionaxua13278b2018-03-21 00:08:13 -07009240
9241 @Override
9242 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009243 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009244 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009245
9246 final long identity = Binder.clearCallingIdentity();
9247 try {
9248 final Phone phone = getPhone(subId);
9249 if (phone == null) {
9250 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9251 return;
9252 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009253 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9254 if (cpt != null) {
9255 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9256 }
9257 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009258 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9259 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009260 if (carrierPrivilegeRules == null) {
9261 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9262 } else {
9263 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009265 } finally {
9266 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009267 }
fionaxua13278b2018-03-21 00:08:13 -07009268 }
9269
9270 @Override
9271 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009272 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 final Phone phone = getPhone(subId);
9277 if (phone == null) {
9278 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9279 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9280 }
9281 return phone.getCarrierIdListVersion();
9282 } finally {
9283 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009284 }
fionaxua13278b2018-03-21 00:08:13 -07009285 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009286
9287 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009288 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9289 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009291 mApp, subId, callingPackage, callingFeatureId,
9292 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009293 return -1;
9294 }
9295
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
9298 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009303
9304 @Override
9305 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009306 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009307 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009308 mApp, subId, "getCdmaRoamingMode");
9309
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
9316 }
9317
9318 @Override
9319 public boolean setCdmaRoamingMode(int subId, int mode) {
9320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9321 mApp, subId, "setCdmaRoamingMode");
9322
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
9330
9331 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009332 public int getCdmaSubscriptionMode(int subId) {
9333 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009334 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009335 mApp, subId, "getCdmaSubscriptionMode");
9336
9337 final long identity = Binder.clearCallingIdentity();
9338 try {
9339 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9340 } finally {
9341 Binder.restoreCallingIdentity(identity);
9342 }
9343 }
9344
9345 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009346 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9348 mApp, subId, "setCdmaSubscriptionMode");
9349
9350 final long identity = Binder.clearCallingIdentity();
9351 try {
9352 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009357
sqianc5eccab2018-10-19 18:46:41 -07009358 @Override
sqian8c685422019-02-22 15:55:18 -08009359 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009360 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009362 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9363 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009364 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9365 }
9366 final long identity = Binder.clearCallingIdentity();
9367 try {
sqian854d44b2018-12-12 16:48:18 -08009368 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9369 for (Phone phone: PhoneFactory.getPhones()) {
9370 if (phone.getEmergencyNumberTracker() != null
9371 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9372 emergencyNumberListInternal.put(
9373 phone.getSubId(),
9374 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9375 }
sqian11b7a0e2018-12-05 18:48:28 -08009376 }
sqian854d44b2018-12-12 16:48:18 -08009377 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009378 } finally {
9379 Binder.restoreCallingIdentity(identity);
9380 }
sqianc5eccab2018-10-19 18:46:41 -07009381 }
9382
9383 @Override
sqian8c685422019-02-22 15:55:18 -08009384 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009385 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009386 if (!exactMatch) {
9387 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009388 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009389 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009390 }
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
sqian854d44b2018-12-12 16:48:18 -08009393 for (Phone phone: PhoneFactory.getPhones()) {
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009394 //Note: we ignore passed in param exactMatch. We can remove it once
9395 // TelephonyManager#isPotentialEmergencyNumber is removed completely
sqian854d44b2018-12-12 16:48:18 -08009396 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009397 && phone.getEmergencyNumberTracker()
Chinmay Dhodapkard521bb12022-08-16 15:49:54 -07009398 .isEmergencyNumber(number)) {
Taesu Leee050c002020-10-13 17:19:35 +09009399 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009400 }
sqian11b7a0e2018-12-05 18:48:28 -08009401 }
9402 return false;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
sqianf4ca7ed2019-01-15 18:32:07 -08009408 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009409 * Start emergency callback mode for GsmCdmaPhone for testing.
9410 */
9411 @Override
9412 public void startEmergencyCallbackMode() {
9413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9414 "startEmergencyCallbackMode");
9415 enforceModifyPermission();
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 for (Phone phone : PhoneFactory.getPhones()) {
9419 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9420 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9421 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9422 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9423 gsmCdmaPhone.obtainMessage(
9424 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9425 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9426 }
9427 }
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
9433 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009434 * Update emergency number list for test mode.
9435 */
9436 @Override
9437 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9438 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9439 "updateEmergencyNumberListTestMode");
9440
9441 final long identity = Binder.clearCallingIdentity();
9442 try {
9443 for (Phone phone: PhoneFactory.getPhones()) {
9444 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9445 if (tracker != null) {
9446 tracker.executeEmergencyNumberTestModeCommand(action, num);
9447 }
9448 }
9449 } finally {
9450 Binder.restoreCallingIdentity(identity);
9451 }
9452 }
9453
9454 /**
9455 * Get the full emergency number list for test mode.
9456 */
9457 @Override
9458 public List<String> getEmergencyNumberListTestMode() {
9459 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9460 "getEmergencyNumberListTestMode");
9461
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 Set<String> emergencyNumbers = new HashSet<>();
9465 for (Phone phone: PhoneFactory.getPhones()) {
9466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9467 if (tracker != null) {
9468 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9469 emergencyNumbers.add(num.getNumber());
9470 }
9471 }
9472 }
9473 return new ArrayList<>(emergencyNumbers);
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478
chen xud6b45bd2018-10-30 22:27:10 -07009479 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009480 public int getEmergencyNumberDbVersion(int subId) {
9481 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9482
9483 final long identity = Binder.clearCallingIdentity();
9484 try {
9485 final Phone phone = getPhone(subId);
9486 if (phone == null) {
9487 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9488 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9489 }
9490 return phone.getEmergencyNumberDbVersion();
9491 } finally {
9492 Binder.restoreCallingIdentity(identity);
9493 }
9494 }
9495
9496 @Override
9497 public void notifyOtaEmergencyNumberDbInstalled() {
9498 enforceModifyPermission();
9499
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 for (Phone phone: PhoneFactory.getPhones()) {
9503 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9504 if (tracker != null) {
9505 tracker.updateOtaEmergencyNumberDatabase();
9506 }
9507 }
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009514 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009515 enforceActiveEmergencySessionPermission();
9516
9517 final long identity = Binder.clearCallingIdentity();
9518 try {
9519 for (Phone phone: PhoneFactory.getPhones()) {
9520 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9521 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009522 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9523 }
9524 }
9525 } finally {
9526 Binder.restoreCallingIdentity(identity);
9527 }
9528 }
9529
9530 @Override
9531 public void resetOtaEmergencyNumberDbFilePath() {
9532 enforceActiveEmergencySessionPermission();
9533
9534 final long identity = Binder.clearCallingIdentity();
9535 try {
9536 for (Phone phone: PhoneFactory.getPhones()) {
9537 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9538 if (tracker != null) {
9539 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009540 }
9541 }
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009548 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9549 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9550 Phone phone = getPhone(subId);
9551 if (phone == null) {
9552 return null;
9553 }
9554 final long identity = Binder.clearCallingIdentity();
9555 try {
9556 UiccProfile profile = UiccController.getInstance()
9557 .getUiccProfileForPhone(phone.getPhoneId());
9558 if (profile != null) {
9559 return profile.getCertsFromCarrierPrivilegeAccessRules();
9560 }
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 return null;
9565 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009566
9567 /**
9568 * Enable or disable a modem stack.
9569 */
9570 @Override
9571 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9572 enforceModifyPermission();
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 Phone phone = PhoneFactory.getPhone(slotIndex);
9577 if (phone == null) {
9578 return false;
9579 } else {
9580 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9581 }
9582 } finally {
9583 Binder.restoreCallingIdentity(identity);
9584 }
9585 }
Michelecea4cf22018-12-21 15:00:11 -08009586
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009587 /**
9588 * Whether a modem stack is enabled or not.
9589 */
9590 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009591 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9592 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009593 Phone phone = PhoneFactory.getPhone(slotIndex);
9594 if (phone == null) return false;
9595
9596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009597 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9598 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009599 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9600 }
9601
9602 final long identity = Binder.clearCallingIdentity();
9603 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009604 try {
9605 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9606 } catch (NoSuchElementException ex) {
9607 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9608 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009609 } finally {
9610 Binder.restoreCallingIdentity(identity);
9611 }
9612 }
9613
Michelecea4cf22018-12-21 15:00:11 -08009614 @Override
Michele0ea7d782019-03-19 14:58:42 -07009615 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009616 enforceModifyPermission();
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009621 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009622 .commit();
9623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 @Override
Michele0ea7d782019-03-19 14:58:42 -07009629 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009630 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009632 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9633 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009634 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009635 }
Michelecea4cf22018-12-21 15:00:11 -08009636
9637 final long identity = Binder.clearCallingIdentity();
9638 try {
Michele0ea7d782019-03-19 14:58:42 -07009639 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009644
Michele0ea7d782019-03-19 14:58:42 -07009645 @TelephonyManager.IsMultiSimSupportedResult
9646 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009647 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9648 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9649 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009650 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9651 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009652 }
9653 // Check if the hardware supports multisim functionality. If usage of multisim is not
9654 // supported by the modem, indicate that it is restricted.
9655 PhoneCapability staticCapability =
9656 mPhoneConfigurationManager.getStaticPhoneCapability();
9657 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009658 loge("isMultiSimSupportedInternal: no static configuration available");
9659 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009660 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009661 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009662 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9663 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009664 }
9665 // Check if support of multiple SIMs is restricted by carrier
9666 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009667 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009668 }
9669
Michele0ea7d782019-03-19 14:58:42 -07009670 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009671 }
9672
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009673 /**
9674 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009675 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9676 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9677 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009678 * @param numOfSims number of active sims we want to switch to
9679 */
9680 @Override
9681 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009682 if (numOfSims == 1) {
9683 enforceModifyPermission();
9684 } else {
9685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9686 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9687 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009688 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009689
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009690 try {
Michele30b57b22019-03-01 12:01:14 -08009691 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009692 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009693 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9694 return;
9695 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009696 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009702 @Override
9703 public boolean isApplicationOnUicc(int subId, int appType) {
9704 enforceReadPrivilegedPermission("isApplicationOnUicc");
9705 Phone phone = getPhone(subId);
9706 if (phone == null) {
9707 return false;
9708 }
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009711 UiccPort uiccPort = phone.getUiccPort();
9712 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009713 return false;
9714 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009715 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009716 if (uiccProfile == null) {
9717 return false;
9718 }
9719 if (TelephonyManager.APPTYPE_SIM <= appType
9720 && appType <= TelephonyManager.APPTYPE_ISIM) {
9721 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9722 }
9723 return false;
9724 } finally {
9725 Binder.restoreCallingIdentity(identity);
9726 }
9727 }
9728
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009729 /**
chen xub4baa772019-04-03 10:23:41 -07009730 * Get whether making changes to modem configurations will trigger reboot.
9731 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009732 */
9733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009734 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9735 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009737 mApp, subId, callingPackage, callingFeatureId,
9738 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009739 return false;
9740 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009741 final long identity = Binder.clearCallingIdentity();
9742 try {
9743 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
Nathan Harold29f5f052019-02-15 13:41:57 -08009749 private void updateModemStateMetrics() {
9750 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9751 // TODO: check the state for each modem if the api is ready.
9752 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9753 }
9754
Pengquan Meng3889a572019-01-23 11:16:29 -08009755 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009756 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009757 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009758 // Verify that the callingPackage belongs to the calling UID
9759 mApp.getSystemService(AppOpsManager.class)
9760 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009761 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009762 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009763 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009764 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9765 if (slotInfos != null) {
9766 for (int i = 0; i < slotInfos.length; i++) {
9767 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9768 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9769 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9770 portInfo.getLogicalSlotIndex()));
9771 }
9772 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009773 }
9774 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009775 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009776 } finally {
9777 Binder.restoreCallingIdentity(identity);
9778 }
9779 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009780
9781 /**
9782 * Get the IRadio HAL Version
9783 */
9784 @Override
9785 public int getRadioHalVersion() {
9786 Phone phone = getDefaultPhone();
9787 if (phone == null) return -1;
9788 HalVersion hv = phone.getHalVersion();
9789 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9790 return hv.major * 100 + hv.minor;
9791 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009792
9793 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009794 * Get the current calling package name.
9795 * @return the current calling package name
9796 */
9797 @Override
9798 public String getCurrentPackageName() {
9799 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9800 }
9801
9802 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009803 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9804 * corresponding network requests on a subId.
9805 *
9806 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009807 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009808 * 2) APN is un-metered for this subscription, or
9809 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009810 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009811 *
9812 * @return whether data is allowed for a apn type.
9813 *
9814 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009815 */
9816 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009817 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009818 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9819 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009820
9821 // Now that all security checks passes, perform the operation as ourselves.
9822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 Phone phone = getPhone(subId);
9825 if (phone == null) return false;
9826
Jack Yu27422a52022-03-21 10:38:05 -07009827 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009828 boolean isDataEnabled;
Jack Yu7968c6d2022-07-31 00:43:21 -07009829 isMetered = phone.getDataNetworkController().getDataConfigManager()
9830 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9831 phone.getServiceState().getDataRoaming());
9832 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009833 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009834 } finally {
9835 Binder.restoreCallingIdentity(identity);
9836 }
9837 }
9838
9839 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009840 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009841 enforceReadPrivilegedPermission("isApnMetered");
9842
9843 // Now that all security checks passes, perform the operation as ourselves.
9844 final long identity = Binder.clearCallingIdentity();
9845 try {
9846 Phone phone = getPhone(subId);
9847 if (phone == null) return true; // By default return true.
Jack Yu7968c6d2022-07-31 00:43:21 -07009848 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9849 DataUtils.apnTypeToNetworkCapability(apnType),
9850 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009855
9856 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009857 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9858 int subscriptionId, IBooleanConsumer resultCallback) {
9859 enforceModifyPermission();
9860 long token = Binder.clearCallingIdentity();
9861 try {
9862 Phone phone = getPhone(subscriptionId);
9863 if (phone == null) {
9864 try {
9865 if (resultCallback != null) {
9866 resultCallback.accept(false);
9867 }
9868 } catch (RemoteException e) {
9869 // ignore
9870 }
9871 return;
9872 }
9873 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9874 Pair.create(specifiers, (x) -> {
9875 try {
9876 if (resultCallback != null) {
9877 resultCallback.accept(x);
9878 }
9879 } catch (RemoteException e) {
9880 // ignore
9881 }
9882 });
9883 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9884 } finally {
9885 Binder.restoreCallingIdentity(token);
9886 }
9887 }
9888
9889 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009890 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9891 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009892 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009893 mApp, subId, "getSystemSelectionChannels");
9894 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009897 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9898 if (result instanceof IllegalStateException) {
9899 throw (IllegalStateException) result;
9900 }
9901 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009902 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9903 return specifiers;
9904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
9908
9909 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009910 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009911 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009912 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009913 }
9914
9915 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009916 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9917 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009918 if (callingPackage == null) {
9919 callingPackage = getCurrentPackageName();
9920 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009921 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9922 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009923 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9924 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009925 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9926 }
9927 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9928 Intent intent = new Intent();
9929 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9930 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9931 // Bring up choose default SMS subscription dialog right now
9932 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9933 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9934 mApp.startActivity(intent);
9935 }
chen xud5ca2d52019-05-28 15:20:57 -07009936
9937 @Override
9938 public String getMmsUAProfUrl(int subId) {
9939 //TODO investigate if this API should require proper permission check in R b/133791609
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009942 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9943 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9944 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9945 return carrierUAProfUrl;
9946 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009947 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9948 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009949 } finally {
9950 Binder.restoreCallingIdentity(identity);
9951 }
9952 }
9953
9954 @Override
9955 public String getMmsUserAgent(int subId) {
9956 //TODO investigate if this API should require proper permission check in R b/133791609
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009959 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9960 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9961 if (!TextUtils.isEmpty(carrierUserAgent)) {
9962 return carrierUserAgent;
9963 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009964 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9965 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009966 } finally {
9967 Binder.restoreCallingIdentity(identity);
9968 }
9969 }
Jack Yub07d4972019-05-28 16:12:25 -07009970
9971 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009972 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9973 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009974
Jack Yub07d4972019-05-28 16:12:25 -07009975 final long identity = Binder.clearCallingIdentity();
9976 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009977 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009978 if (phone == null) return false;
9979
Ling Maf188d502022-09-16 15:22:36 -07009980 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
9986 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009987 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009988 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009989 enforceModifyPermission();
9990
changbettyd5c246e2019-12-24 15:40:37 +08009991 final long identity = Binder.clearCallingIdentity();
9992 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009993 Phone phone = getPhone(subscriptionId);
9994 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009995
Ling Maf188d502022-09-16 15:22:36 -07009996 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
10001
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010002 /**
Hall Liu746e03c2020-09-25 11:13:49 -070010003 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -070010004 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
10005 * otherwise.
10006 */
10007 @Override
10008 public void setCepEnabled(boolean isCepEnabled) {
10009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
10010
10011 final long identity = Binder.clearCallingIdentity();
10012 try {
10013 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
10014 for (Phone phone : PhoneFactory.getPhones()) {
10015 Phone defaultPhone = phone.getImsPhone();
10016 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
10017 ImsPhone imsPhone = (ImsPhone) defaultPhone;
10018 ImsPhoneCallTracker imsPhoneCallTracker =
10019 (ImsPhoneCallTracker) imsPhone.getCallTracker();
10020 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
10021 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
10022 + imsPhone.getMsisdn());
10023 }
10024 }
10025 } finally {
10026 Binder.restoreCallingIdentity(identity);
10027 }
10028 }
allenwtsu46dcc572020-01-08 18:24:03 +080010029
10030 /**
10031 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
10032 *
10033 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
10034 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
10035 * before being read.
10036 */
10037 @Override
10038 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
10039 isCompressed) {
10040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10041 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +000010042 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10043 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10044 }
10045 if (!isImsAvailableOnDevice()) {
10046 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10047 "IMS not available on device.");
10048 }
10049
10050 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +080010051 try {
Hui Wang761a6682020-10-31 05:12:53 +000010052 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
10053 } finally {
10054 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +080010055 }
10056 }
zoey chene02881a2019-12-30 16:11:23 +080010057
10058 @Override
10059 public boolean isIccLockEnabled(int subId) {
10060 enforceReadPrivilegedPermission("isIccLockEnabled");
10061
10062 // Now that all security checks passes, perform the operation as ourselves.
10063 final long identity = Binder.clearCallingIdentity();
10064 try {
10065 Phone phone = getPhone(subId);
10066 if (phone != null && phone.getIccCard() != null) {
10067 return phone.getIccCard().getIccLockEnabled();
10068 } else {
10069 return false;
10070 }
10071 } finally {
10072 Binder.restoreCallingIdentity(identity);
10073 }
10074 }
10075
10076 /**
10077 * Set the ICC pin lock enabled or disabled.
10078 *
10079 * @return an integer representing the status of IccLock enabled or disabled in the following
10080 * three cases:
10081 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
10082 * successfully.
10083 * - Positive number and zero for remaining password attempts.
10084 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10085 *
10086 */
10087 @Override
10088 public int setIccLockEnabled(int subId, boolean enabled, String password) {
10089 enforceModifyPermission();
10090
10091 Phone phone = getPhone(subId);
10092 if (phone == null) {
10093 return 0;
10094 }
10095 // Now that all security checks passes, perform the operation as ourselves.
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
10098 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
10099 new Pair<Boolean, String>(enabled, password), phone, null);
10100 return attemptsRemaining;
10101
10102 } catch (Exception e) {
10103 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
10104 } finally {
10105 Binder.restoreCallingIdentity(identity);
10106 }
10107 return 0;
10108 }
10109
10110 /**
10111 * Change the ICC password used in ICC pin lock.
10112 *
10113 * @return an integer representing the status of IccLock changed in the following three cases:
10114 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
10115 * - Positive number and zero for remaining password attempts.
10116 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
10117 *
10118 */
10119 @Override
10120 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
10121 enforceModifyPermission();
10122
10123 Phone phone = getPhone(subId);
10124 if (phone == null) {
10125 return 0;
10126 }
10127 // Now that all security checks passes, perform the operation as ourselves.
10128 final long identity = Binder.clearCallingIdentity();
10129 try {
10130 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10131 new Pair<String, String>(oldPassword, newPassword), phone, null);
10132 return attemptsRemaining;
10133
10134 } catch (Exception e) {
10135 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10136 } finally {
10137 Binder.restoreCallingIdentity(identity);
10138 }
10139 return 0;
10140 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010141
10142 /**
10143 * Request for receiving user activity notification
10144 */
10145 @Override
10146 public void requestUserActivityNotification() {
10147 if (!mNotifyUserActivity.get()
10148 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10149 mNotifyUserActivity.set(true);
10150 }
10151 }
10152
10153 /**
10154 * Called when userActivity is signalled in the power manager.
10155 * This is safe to call from any thread, with any window manager locks held or not.
10156 */
10157 @Override
10158 public void userActivity() {
10159 // ***************************************
10160 // * Inherited from PhoneWindowManager *
10161 // ***************************************
10162 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10163 // WITH ITS LOCKS HELD.
10164 //
10165 // This code must be VERY careful about the locks
10166 // it acquires.
10167 // In fact, the current code acquires way too many,
10168 // and probably has lurking deadlocks.
10169
10170 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10171 throw new SecurityException("Only the OS may call notifyUserActivity()");
10172 }
10173
10174 if (mNotifyUserActivity.getAndSet(false)) {
10175 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10176 USER_ACTIVITY_NOTIFICATION_DELAY);
10177 }
10178 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010179
10180 @Override
10181 public boolean canConnectTo5GInDsdsMode() {
10182 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10183 }
Jack Yud10cdd42020-09-28 20:28:01 -070010184
10185 @Override
10186 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10187 String callingFeatureId) {
10188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10189 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10190 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10191 }
10192
10193 Phone phone = getPhone(subId);
10194 if (phone == null) {
10195 throw new RuntimeException("phone is not available");
10196 }
10197 // Now that all security checks passes, perform the operation as ourselves.
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return phone.getEquivalentHomePlmns();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
Daniel Bright59e67312020-11-13 11:49:37 -080010205
10206 @Override
10207 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010208 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10209 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010210 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010211 if (radioInterfaceCapabilities == null) {
10212 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010213 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010214 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010215 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010216
Hui Wang641e81c2020-10-12 12:14:23 -070010217 @Override
10218 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10219 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010220 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10221 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10222 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10223 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10224 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010225 if (DBG) {
10226 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10227 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10228 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10229 }
10230
10231 if (!SubscriptionManager.isValidSubscriptionId(subId)
10232 || appType < TelephonyManager.APPTYPE_UNKNOWN
10233 || appType > TelephonyManager.APPTYPE_ISIM
10234 || nafUrl == null || securityProtocol == null || callback == null) {
10235 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10236 if (callback != null) {
10237 try {
10238 callback.onAuthenticationFailure(
10239 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10240 } catch (RemoteException exception) {
10241 log("Fail to notify onAuthenticationFailure due to " + exception);
10242 }
10243 return;
10244 }
10245 }
10246
10247 final long token = Binder.clearCallingIdentity();
10248 try {
10249 getGbaManager(subId).bootstrapAuthenticationRequest(
10250 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10251 forceBootStrapping, callback));
10252 } finally {
10253 Binder.restoreCallingIdentity(token);
10254 }
10255 }
10256
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010257 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010258 * Attempts to set the radio power state for all phones for thermal reason.
10259 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010260 * requested radio power state will actually be set. See {@link
10261 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10262 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010263 * @param enable {@code true} if trying to turn radio on.
10264 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10265 * false}.
10266 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010267 private boolean setRadioPowerForThermal(boolean enable) {
10268 boolean isPhoneAvailable = false;
10269 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10270 Phone phone = PhoneFactory.getPhone(i);
10271 if (phone != null) {
Thomas Nguyenfd0572f2022-07-15 22:28:49 +000010272 phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL);
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010273 isPhoneAvailable = true;
10274 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010275 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010276
10277 // return true if successfully informed the phone object about the thermal radio power
10278 // request.
10279 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010280 }
10281
10282 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010283 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010284 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10285 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10286 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10287 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10288 throw new IllegalArgumentException("modem does not support data throttling");
10289 }
10290
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010291 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10292 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010293 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010294 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10295 }
10296
Sarah Chinecc78c42022-03-31 21:16:48 -070010297 setDataEnabledForReason(
10298 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010299
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010300 if (isDataThrottlingSupported) {
10301 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010302 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010303 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10304 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10305 } else if (thermalMitigationResult
10306 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010307 log("Modem likely does not support data throttling on secondary carrier. Data " +
10308 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10309 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010310 }
10311 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010312 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010313
10314 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010315 }
10316
Jack Nudelman644b91a2021-03-12 14:09:48 -080010317 private static List<String> getThermalMitigationAllowlist(Context context) {
10318 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10319 for (String pckg : context.getResources()
10320 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10321 sThermalMitigationAllowlistedPackages.add(pckg);
10322 }
10323 }
10324
10325 return sThermalMitigationAllowlistedPackages;
10326 }
10327
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010328 private boolean isAnyPhoneInEmergencyState() {
10329 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10330 if (tm.isInEmergencyCall()) {
10331 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10332 return true;
10333 }
10334 for (Phone phone : PhoneFactory.getPhones()) {
10335 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10336 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10337 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10338 + phone.isInEcm());
10339 return true;
10340 }
10341 }
10342
10343 return false;
10344 }
10345
Jack Nudelman644b91a2021-03-12 14:09:48 -080010346 /**
10347 * Used by shell commands to add an authorized package name for thermal mitigation.
10348 * @param packageName name of package to be allowlisted
10349 * @param context
10350 */
10351 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10352 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10353 sThermalMitigationAllowlistedPackages.add(packageName);
10354 }
10355
10356 /**
10357 * Used by shell commands to remove an authorized package name for thermal mitigation.
10358 * @param packageName name of package to remove from allowlist
10359 * @param context
10360 */
10361 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10362 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10363 sThermalMitigationAllowlistedPackages.remove(packageName);
10364 }
10365
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010366 /**
10367 * Thermal mitigation request to control functionalities at modem.
10368 *
10369 * @param subId the id of the subscription.
10370 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010371 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010372 *
10373 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10374 */
10375 @Override
10376 @ThermalMitigationResult
10377 public int sendThermalMitigationRequest(
10378 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010379 ThermalMitigationRequest thermalMitigationRequest,
10380 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010381 enforceModifyPermission();
10382
Jack Nudelman644b91a2021-03-12 14:09:48 -080010383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10384 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10385 .contains(callingPackage)) {
10386 throw new SecurityException("Calling package must be configured in the device config. "
10387 + "calling package: " + callingPackage);
10388 }
10389
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10391 final long identity = Binder.clearCallingIdentity();
10392
10393 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10394 try {
10395 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10396 switch (thermalMitigationAction) {
10397 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10398 thermalMitigationResult =
10399 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010400 thermalMitigationRequest.getDataThrottlingRequest(),
10401 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010402 break;
10403 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10404 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10405 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10406 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10407 }
10408
10409 // Ensure that radio is on. If not able to power on due to phone being
10410 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010411 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010412 thermalMitigationResult =
10413 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10414 break;
10415 }
10416
10417 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010418 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010419 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10420 break;
10421 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10422 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10423 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10424 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10425 }
10426
10427 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10428 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010429 Phone phone = getPhone(subId);
10430 if (phone == null) {
10431 thermalMitigationResult =
10432 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10433 break;
10434 }
10435
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010436 TelephonyConnectionService service =
10437 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010438 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010439 Log.e(LOG_TAG, "An emergency call is pending");
10440 thermalMitigationResult =
10441 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10442 break;
10443 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010444 thermalMitigationResult =
10445 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10446 break;
10447 }
10448 } else {
10449 thermalMitigationResult =
10450 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10451 break;
10452 }
10453
10454 // Turn radio off. If not able to power off due to phone being unavailable,
10455 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010456 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010457 thermalMitigationResult =
10458 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10459 break;
10460 }
10461 thermalMitigationResult =
10462 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10463 break;
10464 default:
10465 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10466 + "not exist. Requested action: " + thermalMitigationAction);
10467 }
10468 } catch (IllegalArgumentException e) {
10469 throw e;
10470 } catch (Exception e) {
10471 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10472 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476
10477 if (DBG) {
10478 log("thermalMitigationRequest returning with thermalMitigationResult: "
10479 + thermalMitigationResult);
10480 }
10481
10482 return thermalMitigationResult;
10483 }
Hui Wang641e81c2020-10-12 12:14:23 -070010484
10485 /**
10486 * Set the GbaService Package Name that Telephony will bind to.
10487 *
10488 * @param subId The sim that the GbaService is associated with.
10489 * @param packageName The name of the package to be replaced with.
10490 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10491 */
10492 @Override
10493 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10494 enforceModifyPermission();
10495
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 return getGbaManager(subId).overrideServicePackage(packageName);
10499 } finally {
10500 Binder.restoreCallingIdentity(identity);
10501 }
10502 }
10503
10504 /**
10505 * Return the package name of the currently bound GbaService.
10506 *
10507 * @param subId The sim that the GbaService is associated with.
10508 * @return the package name of the GbaService configuration, null if GBA is not supported.
10509 */
10510 @Override
10511 public String getBoundGbaService(int subId) {
10512 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10513
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 return getGbaManager(subId).getServicePackage();
10517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
10521
10522 /**
10523 * Set the release time for telephony to unbind GbaService.
10524 *
10525 * @param subId The sim that the GbaService is associated with.
10526 * @param interval The release time to unbind GbaService by millisecond.
10527 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10528 */
10529 @Override
10530 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10531 enforceModifyPermission();
10532
10533 final long identity = Binder.clearCallingIdentity();
10534 try {
10535 return getGbaManager(subId).overrideReleaseTime(interval);
10536 } finally {
10537 Binder.restoreCallingIdentity(identity);
10538 }
10539 }
10540
10541 /**
10542 * Return the release time for telephony to unbind GbaService.
10543 *
10544 * @param subId The sim that the GbaService is associated with.
10545 * @return The release time to unbind GbaService by millisecond.
10546 */
10547 @Override
10548 public int getGbaReleaseTime(int subId) {
10549 enforceReadPrivilegedPermission("getGbaReleaseTime");
10550
10551 final long identity = Binder.clearCallingIdentity();
10552 try {
10553 return getGbaManager(subId).getReleaseTime();
10554 } finally {
10555 Binder.restoreCallingIdentity(identity);
10556 }
10557 }
10558
10559 private GbaManager getGbaManager(int subId) {
10560 GbaManager instance = GbaManager.getInstance(subId);
10561 if (instance == null) {
10562 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10563 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10564 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10565 }
10566 return instance;
10567 }
Hui Wang761a6682020-10-31 05:12:53 +000010568
10569 /**
10570 * indicate whether the device and the carrier can support
10571 * RCS VoLTE single registration.
10572 */
10573 @Override
10574 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010575 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10576 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10577 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10578 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010579
10580 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10581 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10582 }
10583
10584 final long identity = Binder.clearCallingIdentity();
10585 try {
10586 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10587 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010588 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10589 if (isCapable != null) {
10590 return isCapable;
10591 }
Hui Wang761a6682020-10-31 05:12:53 +000010592 }
Hui Wang67af90e2021-06-04 16:57:15 -070010593 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10594 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010595 } finally {
10596 Binder.restoreCallingIdentity(identity);
10597 }
10598 }
10599
10600 /**
10601 * Register RCS provisioning callback.
10602 */
10603 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010604 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010605 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010606 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010607 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010608 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10609 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010610
10611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10612 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10613 }
10614 if (!isImsAvailableOnDevice()) {
10615 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10616 "IMS not available on device.");
10617 }
10618
10619 final long identity = Binder.clearCallingIdentity();
10620 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010621 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010622 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010623 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10624 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010625 }
Hui Wang761a6682020-10-31 05:12:53 +000010626 } finally {
10627 Binder.restoreCallingIdentity(identity);
10628 }
10629 }
10630
10631 /**
10632 * Unregister RCS provisioning callback.
10633 */
10634 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010635 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010636 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010637 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010638 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010639 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10640 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010641
10642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10643 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10644 }
10645 if (!isImsAvailableOnDevice()) {
10646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10647 "IMS not available on device.");
10648 }
10649
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010652 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010653 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
10659 /**
10660 * trigger RCS reconfiguration.
10661 */
10662 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010663 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10664 "triggerRcsReconfiguration",
10665 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010666
10667 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10668 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10669 }
10670 if (!isImsAvailableOnDevice()) {
10671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10672 "IMS not available on device.");
10673 }
10674
10675 final long identity = Binder.clearCallingIdentity();
10676 try {
10677 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10678 } finally {
10679 Binder.restoreCallingIdentity(identity);
10680 }
10681 }
10682
10683 /**
10684 * Provide the client configuration parameters of the RCS application.
10685 */
10686 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010687 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10688 "setRcsClientConfiguration",
10689 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010690
10691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10692 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10693 }
10694 if (!isImsAvailableOnDevice()) {
10695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10696 "IMS not available on device.");
10697 }
10698
10699 final long identity = Binder.clearCallingIdentity();
10700
10701 try {
10702 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10703 if (configBinder == null) {
10704 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010705 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10706 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010707 } else {
10708 configBinder.setRcsClientConfiguration(rcc);
10709 }
joonhunshin3e154242021-09-17 06:33:39 +000010710
10711 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10712 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010713 } catch (RemoteException e) {
10714 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010715 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10716 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
10722 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010723 * Enables or disables the test mode for RCS VoLTE single registration.
10724 */
10725 @Override
10726 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10728 "setRcsSingleRegistrationTestModeEnabled");
10729
10730 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10731 }
10732
10733 /**
10734 * Gets the test mode for RCS VoLTE single registration.
10735 */
10736 @Override
10737 public boolean getRcsSingleRegistrationTestModeEnabled() {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10739 "getRcsSingleRegistrationTestModeEnabled");
10740
10741 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10742 }
10743
10744 /**
Hui Wang761a6682020-10-31 05:12:53 +000010745 * Overrides the config of RCS VoLTE single registration enabled for the device.
10746 */
10747 @Override
10748 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10750 "setDeviceSingleRegistrationEnabledOverride");
10751 enforceModifyPermission();
10752
10753 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10754 : Boolean.parseBoolean(enabledStr);
10755 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010756 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010757 }
10758
10759 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010760 * Sends a device to device communication message. Only usable via shell.
10761 * @param message message to send.
10762 * @param value message value.
10763 */
10764 @Override
10765 public void sendDeviceToDeviceMessage(int message, int value) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010767 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010768 enforceModifyPermission();
10769
10770 final long identity = Binder.clearCallingIdentity();
10771 try {
10772 TelephonyConnectionService service =
10773 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10774 if (service == null) {
10775 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10776 return;
10777 }
10778 service.sendTestDeviceToDeviceMessage(message, value);
10779 } finally {
10780 Binder.restoreCallingIdentity(identity);
10781 }
10782 }
10783
Tyler Gunnbabbda02021-02-10 11:05:02 -080010784 /**
10785 * Sets the specified device to device transport active.
10786 * @param transport The transport to set active.
10787 */
10788 @Override
10789 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10790 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10791 "setActiveDeviceToDeviceTransport");
10792 enforceModifyPermission();
10793
10794 final long identity = Binder.clearCallingIdentity();
10795 try {
10796 TelephonyConnectionService service =
10797 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10798 if (service == null) {
10799 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10800 return;
10801 }
10802 service.setActiveDeviceToDeviceTransport(transport);
10803 } finally {
10804 Binder.restoreCallingIdentity(identity);
10805 }
10806 }
Tyler Gunn92479152021-01-20 16:30:10 -080010807
Tyler Gunnd4339262021-05-03 14:46:49 -070010808 @Override
10809 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10810 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10811 "setDeviceToDeviceForceEnabled");
10812
10813 final long identity = Binder.clearCallingIdentity();
10814 try {
10815 Arrays.stream(PhoneFactory.getPhones()).forEach(
10816 p -> {
10817 Phone thePhone = p.getImsPhone();
10818 if (thePhone != null && thePhone instanceof ImsPhone) {
10819 ImsPhone imsPhone = (ImsPhone) thePhone;
10820 CallTracker tracker = imsPhone.getCallTracker();
10821 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10822 ImsPhoneCallTracker imsPhoneCallTracker =
10823 (ImsPhoneCallTracker) tracker;
10824 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10825 }
10826 }
10827 }
10828 );
10829 } finally {
10830 Binder.restoreCallingIdentity(identity);
10831 }
10832 }
10833
Tyler Gunn92479152021-01-20 16:30:10 -080010834 /**
Hui Wang761a6682020-10-31 05:12:53 +000010835 * Gets the config of RCS VoLTE single registration enabled for the device.
10836 */
10837 @Override
10838 public boolean getDeviceSingleRegistrationEnabled() {
10839 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10840 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10841 }
10842
10843 /**
10844 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10845 */
10846 @Override
10847 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10848 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10849 "setCarrierSingleRegistrationEnabledOverride");
10850 enforceModifyPermission();
10851
10852 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10853 : Boolean.parseBoolean(enabledStr);
10854 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10855 subId, enabled);
10856 }
10857
10858 /**
10859 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10860 */
10861 @Override
10862 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10863 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10864 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10865 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010866
10867 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010868 * Overrides the ims feature validation result
10869 */
10870 @Override
10871 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10872 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10873 "setImsFeatureValidationOverride");
10874
10875 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10876 : Boolean.parseBoolean(enabledStr);
10877 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10878 subId, enabled);
10879 }
10880
10881 /**
10882 * Gets the ims feature validation override value
10883 */
10884 @Override
10885 public boolean getImsFeatureValidationOverride(int subId) {
10886 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10887 "getImsFeatureValidationOverride");
10888 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10889 }
10890
10891 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010892 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10893 * their mobile plan.
10894 */
10895 @Override
10896 public String getMobileProvisioningUrl() {
10897 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
10900 return getDefaultPhone().getMobileProvisioningUrl();
10901 } finally {
10902 Binder.restoreCallingIdentity(identity);
10903 }
10904 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010905
James.cf Linbcdf8b32021-01-14 16:44:13 +080010906 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010907 * Get the EAB contact from the EAB database.
10908 */
10909 @Override
10910 public String getContactFromEab(String contact) {
10911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10912 enforceModifyPermission();
10913 final long identity = Binder.clearCallingIdentity();
10914 try {
10915 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10916 } finally {
10917 Binder.restoreCallingIdentity(identity);
10918 }
10919 }
10920
10921 /**
Calvin Pana1434322021-07-01 19:27:01 +080010922 * Get the EAB capability from the EAB database.
10923 */
10924 @Override
10925 public String getCapabilityFromEab(String contact) {
10926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10927 enforceModifyPermission();
10928 final long identity = Binder.clearCallingIdentity();
10929 try {
10930 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10931 } finally {
10932 Binder.restoreCallingIdentity(identity);
10933 }
10934 }
10935
10936 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010937 * Remove the EAB contacts from the EAB database.
10938 */
10939 @Override
10940 public int removeContactFromEab(int subId, String contacts) {
10941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10942 enforceModifyPermission();
10943 final long identity = Binder.clearCallingIdentity();
10944 try {
10945 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10946 } finally {
10947 Binder.restoreCallingIdentity(identity);
10948 }
10949 }
10950
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010951 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010952 public boolean getDeviceUceEnabled() {
10953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10954 final long identity = Binder.clearCallingIdentity();
10955 try {
10956 return mApp.getDeviceUceEnabled();
10957 } finally {
10958 Binder.restoreCallingIdentity(identity);
10959 }
10960 }
10961
10962 @Override
10963 public void setDeviceUceEnabled(boolean isEnabled) {
10964 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10965 final long identity = Binder.clearCallingIdentity();
10966 try {
10967 mApp.setDeviceUceEnabled(isEnabled);
10968 } finally {
10969 Binder.restoreCallingIdentity(identity);
10970 }
10971 }
10972
Brad Ebinger14d467f2021-02-12 06:18:28 +000010973 /**
10974 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10975 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10976 */
10977 // Used for SHELL command only right now.
10978 @Override
10979 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10980 List<String> featureTags) {
10981 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10982 "addUceRegistrationOverrideShell");
10983 final long identity = Binder.clearCallingIdentity();
10984 try {
10985 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10986 new ArraySet<>(featureTags));
10987 } catch (ImsException e) {
10988 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10989 } finally {
10990 Binder.restoreCallingIdentity(identity);
10991 }
10992 }
10993
10994 /**
10995 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10996 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10997 */
10998 // Used for SHELL command only right now.
10999 @Override
11000 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
11001 List<String> featureTags) {
11002 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11003 "removeUceRegistrationOverrideShell");
11004 final long identity = Binder.clearCallingIdentity();
11005 try {
11006 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
11007 new ArraySet<>(featureTags));
11008 } catch (ImsException e) {
11009 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11010 } finally {
11011 Binder.restoreCallingIdentity(identity);
11012 }
11013 }
11014
11015 /**
11016 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
11017 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11018 */
11019 // Used for SHELL command only right now.
11020 @Override
11021 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
11022 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11023 "clearUceRegistrationOverrideShell");
11024 final long identity = Binder.clearCallingIdentity();
11025 try {
11026 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
11027 } catch (ImsException e) {
11028 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11029 } finally {
11030 Binder.restoreCallingIdentity(identity);
11031 }
11032 }
11033
11034 /**
11035 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
11036 */
11037 // Used for SHELL command only right now.
11038 @Override
11039 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
11040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
11041 "getLatestRcsContactUceCapabilityShell");
11042 final long identity = Binder.clearCallingIdentity();
11043 try {
11044 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
11045 } catch (ImsException e) {
11046 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11047 } finally {
11048 Binder.restoreCallingIdentity(identity);
11049 }
11050 }
11051
11052 /**
11053 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
11054 * device does not have an active PUBLISH.
11055 */
11056 // Used for SHELL command only right now.
11057 @Override
11058 public String getLastUcePidfXmlShell(int subId) {
11059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
11060 final long identity = Binder.clearCallingIdentity();
11061 try {
11062 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
11063 } catch (ImsException e) {
11064 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11065 } finally {
11066 Binder.restoreCallingIdentity(identity);
11067 }
11068 }
11069
James.cf Line8713a42021-04-29 16:04:26 +080011070 /**
11071 * Remove UCE requests cannot be sent to the network status.
11072 */
11073 // Used for SHELL command only right now.
11074 @Override
11075 public boolean removeUceRequestDisallowedStatus(int subId) {
11076 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
11080 } catch (ImsException e) {
11081 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11082 } finally {
11083 Binder.restoreCallingIdentity(identity);
11084 }
11085 }
11086
James.cf Lin18bb9002021-05-25 01:37:38 +080011087 /**
11088 * Remove UCE requests cannot be sent to the network status.
11089 */
11090 // Used for SHELL command only.
11091 @Override
11092 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
11093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
11094 final long identity = Binder.clearCallingIdentity();
11095 try {
11096 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
11097 } catch (ImsException e) {
11098 throw new ServiceSpecificException(e.getCode(), e.getMessage());
11099 } finally {
11100 Binder.restoreCallingIdentity(identity);
11101 }
11102 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000011103
James.cf Lin4b784aa2021-01-31 03:25:15 +080011104 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011105 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11106 String callingPackage) {
11107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11108 mApp, subId, "setSignalStrengthUpdateRequest");
11109
11110 final int callingUid = Binder.getCallingUid();
11111 // Verify that tha callingPackage belongs to the calling UID
11112 mApp.getSystemService(AppOpsManager.class)
11113 .checkPackage(callingUid, callingPackage);
11114
Rambo Wang3607f502021-02-01 21:51:40 -080011115 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011116
11117 final long identity = Binder.clearCallingIdentity();
11118 try {
11119 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
11120 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11121
11122 if (result instanceof IllegalStateException) {
11123 throw (IllegalStateException) result;
11124 }
11125 } finally {
11126 Binder.restoreCallingIdentity(identity);
11127 }
11128 }
11129
11130 @Override
11131 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11132 String callingPackage) {
11133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11134 mApp, subId, "clearSignalStrengthUpdateRequest");
11135
11136 final int callingUid = Binder.getCallingUid();
11137 // Verify that tha callingPackage belongs to the calling UID
11138 mApp.getSystemService(AppOpsManager.class)
11139 .checkPackage(callingUid, callingPackage);
11140
11141 final long identity = Binder.clearCallingIdentity();
11142 try {
11143 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11144 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11145
11146 if (result instanceof IllegalStateException) {
11147 throw (IllegalStateException) result;
11148 }
11149 } finally {
11150 Binder.restoreCallingIdentity(identity);
11151 }
11152 }
11153
Rambo Wang3607f502021-02-01 21:51:40 -080011154 private static void validateSignalStrengthUpdateRequest(Context context,
11155 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011156 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11157 // phone/system process do not have further restriction on request
11158 return;
11159 }
11160
11161 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011162 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011163 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011164 context.enforceCallingOrSelfPermission(
11165 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11166 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011167 }
11168
11169 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11170 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11171 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11172 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11173 || info.isEnabled()) {
11174 throw new IllegalArgumentException(
11175 "Only system can set hide fields in SignalThresholdInfo");
11176 }
11177
11178 // Thresholds length for each RAN need in range. This has been validated in
11179 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11180 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11181 final int[] thresholds = info.getThresholds();
11182 Objects.requireNonNull(thresholds);
11183 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11184 || thresholds.length
11185 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11186 throw new IllegalArgumentException(
11187 "thresholds length is out of range: " + thresholds.length);
11188 }
11189 }
11190 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011191
11192 /**
11193 * Gets the current phone capability.
11194 *
11195 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11196 * @return the PhoneCapability which describes the data connection capability of modem.
11197 * It's used to evaluate possible phone config change, for example from single
11198 * SIM device to multi-SIM device.
11199 */
11200 @Override
11201 public PhoneCapability getPhoneCapability() {
11202 enforceReadPrivilegedPermission("getPhoneCapability");
11203 final long identity = Binder.clearCallingIdentity();
11204 try {
11205 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11206 } finally {
11207 Binder.restoreCallingIdentity(identity);
11208 }
11209 }
Michele Berionne5e411512020-11-13 02:36:59 +000011210
11211 /**
11212 * Prepare TelephonyManager for an unattended reboot. The reboot is
11213 * required to be done shortly after the API is invoked.
11214 */
11215 @Override
11216 @TelephonyManager.PrepareUnattendedRebootResult
11217 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011219 enforceRebootPermission();
11220
11221 final long identity = Binder.clearCallingIdentity();
11222 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011223 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011224 } finally {
11225 Binder.restoreCallingIdentity(identity);
11226 }
11227 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011228
11229 /**
11230 * Request to get the current slicing configuration including URSP rules and
11231 * NSSAIs (configured, allowed and rejected).
11232 *
11233 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11234 */
11235 @Override
11236 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011237 TelephonyPermissions
11238 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11239 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011240
11241 final long identity = Binder.clearCallingIdentity();
11242 try {
11243 Phone phone = getDefaultPhone();
11244 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11245 } finally {
11246 Binder.restoreCallingIdentity(identity);
11247 }
11248 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011249
11250 /**
Sarah Chin2ec39f62022-08-31 17:03:26 -070011251 * Check whether the given premium capability is available for purchase from the carrier.
11252 *
11253 * @param capability The premium capability to check.
11254 * @param subId The subId to check the premium capability for.
11255 *
11256 * @return Whether the given premium capability is available to purchase.
11257 */
11258 @Override
11259 public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) {
11260 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11261 mApp, "isPremiumCapabilityAvailableForPurchase")) {
11262 log("Premium capability "
11263 + TelephonyManager.convertPremiumCapabilityToString(capability)
11264 + " is not available for purchase due to missing permissions.");
11265 throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires "
11266 + "permission READ_BASIC_PHONE_STATE.");
11267 }
11268
11269 Phone phone = getPhone(subId);
11270 final long identity = Binder.clearCallingIdentity();
11271 try {
11272 return SliceStore.getInstance(phone)
11273 .isPremiumCapabilityAvailableForPurchase(capability);
11274 } finally {
11275 Binder.restoreCallingIdentity(identity);
11276 }
11277 }
11278
11279 /**
11280 * Purchase the given premium capability from the carrier.
11281 *
11282 * @param capability The premium capability to purchase.
11283 * @param callback The result of the purchase request.
11284 * @param subId The subId to purchase the premium capability for.
11285 */
11286 @Override
11287 public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) {
11288 log("purchasePremiumCapability: capability="
11289 + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller="
11290 + getCurrentPackageName());
11291
11292 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
11293 mApp, "purchasePremiumCapability")) {
11294 log("purchasePremiumCapability "
11295 + TelephonyManager.convertPremiumCapabilityToString(capability)
11296 + " failed due to missing permissions.");
11297 throw new SecurityException("purchasePremiumCapability requires permission "
11298 + "READ_BASIC_PHONE_STATE.");
11299 }
11300
11301 Phone phone = getPhone(subId);
Sarah Chin71b3a852022-09-28 15:54:19 -070011302 String appName;
11303 try {
11304 appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager()
11305 .getApplicationInfo(getCurrentPackageName(), 0)).toString();
11306 } catch (PackageManager.NameNotFoundException e) {
11307 appName = "An application";
11308 }
11309 sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY,
11310 new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null);
Sarah Chin2ec39f62022-08-31 17:03:26 -070011311 }
11312
11313 /**
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011314 * Register an IMS connection state callback
11315 */
11316 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011317 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11318 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011319 if (feature == ImsFeature.FEATURE_MMTEL) {
11320 // ImsMmTelManager
11321 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11322 TelephonyPermissions
11323 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11324 mApp, subId, "registerImsStateCallback");
11325 } else if (feature == ImsFeature.FEATURE_RCS) {
11326 // ImsRcsManager or SipDelegateManager
11327 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11328 Binder.getCallingUid(), "registerImsStateCallback",
11329 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11330 Manifest.permission.READ_PRECISE_PHONE_STATE,
11331 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11332 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11333 }
11334
11335 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11336 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11337 "IMS not available on device.");
11338 }
11339
11340 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11341 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11342 }
11343
11344 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11345 if (controller == null) {
11346 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11347 "IMS not available on device.");
11348 }
11349
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011350 if (callingPackage == null) {
11351 callingPackage = getCurrentPackageName();
11352 }
11353
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011354 final long token = Binder.clearCallingIdentity();
11355 try {
11356 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011357 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011358 } catch (ImsException e) {
11359 throw new ServiceSpecificException(e.getCode());
11360 } finally {
11361 Binder.restoreCallingIdentity(token);
11362 }
11363 }
11364
11365 /**
11366 * Unregister an IMS connection state callback
11367 */
11368 @Override
11369 public void unregisterImsStateCallback(IImsStateCallback cb) {
11370 final long token = Binder.clearCallingIdentity();
11371 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11372 if (controller == null) {
11373 return;
11374 }
11375 try {
11376 controller.unregisterImsStateCallback(cb);
11377 } finally {
11378 Binder.restoreCallingIdentity(token);
11379 }
11380 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011381
11382 /**
11383 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11384 *
11385 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11386 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11387 * SecurityException.
11388 * If there is current registered network this value will be same as the registered cell
11389 * identity. If the device goes out of service the previous cell identity is cached and
11390 * will be returned. If the cache age of the Cell identity is more than 24 hours
11391 * it will be cleared and null will be returned.
11392 *
11393 */
11394 @Override
11395 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11396 String callingFeatureId) {
11397 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11398 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11399 LocationAccessPolicy.checkLocationPermission(mApp,
11400 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11401 .setCallingPackage(callingPackage)
11402 .setCallingFeatureId(callingFeatureId)
11403 .setCallingPid(Binder.getCallingPid())
11404 .setCallingUid(Binder.getCallingUid())
11405 .setMethod("getLastKnownCellIdentity")
11406 .setLogAsInfo(true)
11407 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11408 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11409 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11410 .build());
11411
11412 boolean hasFinePermission =
11413 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11414 if (!hasFinePermission
11415 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11416 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011417 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011418 }
11419
11420 final long identity = Binder.clearCallingIdentity();
11421 try {
11422 Phone phone = getPhone(subId);
11423 if (phone == null) return null;
11424 ServiceStateTracker sst = phone.getServiceStateTracker();
11425 if (sst == null) return null;
11426 return sst.getLastKnownCellIdentity();
11427 } finally {
11428 Binder.restoreCallingIdentity(identity);
11429 }
11430 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011431
jimsun3b9ccac2021-10-26 15:01:23 +080011432 /**
11433 * Sets the modem service class Name that Telephony will bind to.
11434 *
11435 * @param serviceName The class name of the modem service.
11436 * @return true if the operation is succeed, otherwise false.
11437 */
11438 public boolean setModemService(String serviceName) {
11439 Log.d(LOG_TAG, "setModemService - " + serviceName);
11440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11442 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11443 "setModemService");
11444 return mPhoneConfigurationManager.setModemService(serviceName);
11445 }
11446
11447 /**
11448 * Return the class name of the currently bounded modem service.
11449 *
11450 * @return the class name of the modem service.
11451 */
11452 public String getModemService() {
11453 String result;
11454 Log.d(LOG_TAG, "getModemService");
11455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11456 TelephonyPermissions
11457 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11458 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11459 "getModemService");
11460 result = mPhoneConfigurationManager.getModemService();
11461 Log.d(LOG_TAG, "result = " + result);
11462 return result;
11463 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011464
11465 @Override
11466 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11467 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11468 mApp.enforceCallingOrSelfPermission(
11469 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11471
11472 final long identity = Binder.clearCallingIdentity();
11473 try {
11474 Phone phone = getPhone(subId);
11475 if (phone == null) return;
11476 phone.setVoiceServiceStateOverride(hasService);
11477 } finally {
11478 Binder.restoreCallingIdentity(identity);
11479 }
11480 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011481
11482 /**
11483 * set removable eSIM as default eUICC.
11484 *
11485 * @hide
11486 */
11487 @Override
11488 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11489 enforceModifyPermission();
11490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11491
11492 final long identity = Binder.clearCallingIdentity();
11493 try {
11494 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11495 } finally {
11496 Binder.restoreCallingIdentity(identity);
11497 }
11498 }
11499
11500 /**
11501 * Returns whether the removable eSIM is default eUICC or not.
11502 *
11503 * @hide
11504 */
11505 @Override
11506 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11507 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11509
11510 final long identity = Binder.clearCallingIdentity();
11511 try {
11512 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11513 } finally {
11514 Binder.restoreCallingIdentity(identity);
11515 }
11516 }
11517
11518
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011519}