blob: ccace4cf2ffa565d4b240230a1565d5ab287b4f6 [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 hsue9360cd2022-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;
Shuo Qian4a594052020-01-23 11:59:30 -080081import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070082import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080083import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070084import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080085import android.telephony.CellIdentityCdma;
86import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070088import android.telephony.CellInfoGsm;
89import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070090import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080091import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070092import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070093import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070094import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080095import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080097import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070098import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080099import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -0800100import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -0800104import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800105import android.telephony.SignalStrengthUpdateRequest;
106import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -0800107import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800109import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700110import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700111import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800112import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800113import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800114import android.telephony.UiccCardInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000115import android.telephony.UiccPortInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000116import android.telephony.UiccSlotInfo;
sandeepjsb6c87872021-09-27 15:34:44 +0000117import android.telephony.UiccSlotMapping;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700118import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700119import android.telephony.VisualVoicemailSmsFilterSettings;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800120import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800121import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700122import android.telephony.gba.GbaAuthRequest;
123import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700124import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000126import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000127import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700128import android.telephony.ims.RegistrationManager;
joonhunshincffb7fc2021-11-28 07:32:01 +0000129import android.telephony.ims.aidl.IFeatureProvisioningCallback;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700130import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800131import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700132import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800133import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700134import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000135import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700136import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800137import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800138import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800140import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700141import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800143import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800144
Andrew Lee312e8172014-10-23 17:01:36 -0700145import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800146import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800147import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800148import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800149import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700151import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700152import com.android.internal.telephony.CallTracker;
Rambo Wang9c9ffdd2022-01-13 21:51:44 -0800153import com.android.internal.telephony.CarrierPrivilegesTracker;
chen xu651eec72018-11-11 19:03:44 -0800154import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700155import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800157import com.android.internal.telephony.CommandsInterface;
Hui Wang641e81c2020-10-12 12:14:23 -0700158import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800159import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800160import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800161import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700162import com.android.internal.telephony.ICallForwardingInfoCallback;
Hunsuk Choi3b742d62021-10-25 19:48:34 +0000163import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800165import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700166import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800167import com.android.internal.telephony.IccCard;
Rambo Wanga1782702021-11-10 20:15:19 -0800168import com.android.internal.telephony.IccLogicalChannelRequest;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700170import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700173import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800174import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700175import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700176import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700177import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700178import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800179import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800180import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700181import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700182import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700183import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800184import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800185import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800186import com.android.internal.telephony.TelephonyPermissions;
Jack Yu27422a52022-03-21 10:38:05 -0700187import com.android.internal.telephony.data.DataUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700189import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800190import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700191import com.android.internal.telephony.imsphone.ImsPhone;
192import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
joonhunshin3e154242021-09-17 06:33:39 +0000193import com.android.internal.telephony.metrics.RcsStats;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800194import com.android.internal.telephony.metrics.TelephonyMetrics;
Jack Yudf049d72022-12-02 22:48:35 -0800195import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
196import com.android.internal.telephony.subscription.SubscriptionManagerService;
Meng Wangafbc5852019-09-19 17:37:13 -0700197import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198import com.android.internal.telephony.uicc.IccIoResult;
199import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800200import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700201import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800202import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000204import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800205import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000206import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800207import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700208import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700209import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800210import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800211import com.android.phone.callcomposer.CallComposerPictureManager;
212import com.android.phone.callcomposer.CallComposerPictureTransfer;
213import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700214import com.android.phone.settings.PickSmsSubscriptionActivity;
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;
Hall Liu82694d52020-12-11 18:22:04 -0800240import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800241import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800242import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700243
244/**
245 * Implementation of the ITelephony interface.
246 */
Santos Cordon117fee72014-05-16 17:56:12 -0700247public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 private static final String LOG_TAG = "PhoneInterfaceManager";
249 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
250 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800251 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253 // Message codes used with mMainThreadHandler
254 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700255 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
256 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700257 private static final int CMD_OPEN_CHANNEL = 9;
258 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
259 private static final int CMD_CLOSE_CHANNEL = 11;
260 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800261 private static final int CMD_NV_READ_ITEM = 13;
262 private static final int EVENT_NV_READ_ITEM_DONE = 14;
263 private static final int CMD_NV_WRITE_ITEM = 15;
264 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
265 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
266 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700267 private static final int CMD_RESET_MODEM_CONFIG = 19;
268 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800269 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
270 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800271 private static final int CMD_SEND_ENVELOPE = 25;
272 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000273 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
274 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700275 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
276 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
277 private static final int CMD_EXCHANGE_SIM_IO = 31;
278 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
280 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700281 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
282 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700283 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
284 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700285 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
286 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
287 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
288 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700289 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
290 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
291 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
292 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700293 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800294 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
295 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000296 private static final int CMD_SWITCH_SLOTS = 50;
297 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700298 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
299 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
300 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
301 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
302 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
303 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
304 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
305 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700306 private static final int CMD_GET_ALL_CELL_INFO = 60;
307 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
308 private static final int CMD_GET_CELL_LOCATION = 62;
309 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700310 private static final int CMD_MODEM_REBOOT = 64;
311 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700312 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
313 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800314 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
315 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700316 private static final int CMD_GET_MODEM_STATUS = 70;
317 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700318 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
319 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700320 private static final int CMD_ERASE_MODEM_CONFIG = 74;
321 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800322 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
323 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
324 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
325 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800326 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
327 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800328 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800329 private static final int CMD_GET_CALL_FORWARDING = 83;
330 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
331 private static final int CMD_SET_CALL_FORWARDING = 85;
332 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
333 private static final int CMD_GET_CALL_WAITING = 87;
334 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
335 private static final int CMD_SET_CALL_WAITING = 89;
336 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700337 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
338 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
339 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
340 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700341 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
342 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800343 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
344 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800345 private static final int CMD_SET_DATA_THROTTLING = 99;
346 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800347 private static final int CMD_SET_SIM_POWER = 101;
348 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800349 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
350 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
351 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
352 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800353 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
354 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000355 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800356 private static final int CMD_GET_SLICING_CONFIG = 110;
357 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800358 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700359 private static final int CMD_ENABLE_VONR = 113;
360 private static final int EVENT_ENABLE_VONR_DONE = 114;
361 private static final int CMD_IS_VONR_ENABLED = 115;
362 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800364 // Parameters of select command.
365 private static final int SELECT_COMMAND = 0xA4;
366 private static final int SELECT_P1 = 0x04;
367 private static final int SELECT_P2 = 0;
368 private static final int SELECT_P3 = 0x10;
369
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 /** The singleton instance. */
371 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800372 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373
Wink Saville3ab207e2014-11-20 13:07:20 -0800374 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800375 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800376 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700377 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800378 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700379 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800380 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800381 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800382 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700383 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800384 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Gil Cukierman6dac5eb2022-09-19 16:09:04 +0000385 private final Telephony2gUpdater mTelephony2gUpdater;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386
Peter Wangdafb9ac2020-01-15 14:13:38 -0800387 /** User Activity */
388 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800389 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
390
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700391 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
392
Derek Tan97ebb422014-09-05 16:55:38 -0700393 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
394 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800395 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800396 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700397
Michelecea4cf22018-12-21 15:00:11 -0800398 // String to store multi SIM allowed
399 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
400
Derek Tan740e1672017-06-27 14:56:27 -0700401 // The AID of ISD-R.
402 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
403
yinxub1bed742017-04-17 11:45:04 -0700404 private NetworkScanRequestTracker mNetworkScanRequestTracker;
405
David Kelly5e06a7f2018-03-12 14:10:59 +0000406 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
407 private static final int MANUFACTURER_CODE_LENGTH = 8;
408
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800409 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800410 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800411
Derek Tan89e89d42014-07-08 17:00:10 -0700412 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700413 * Experiment flag to enable erase modem config on reset network, default value is false
414 */
415 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
416 "reset_network_erase_modem_config_enabled";
417
Rambo Wang0f050d82021-02-12 11:43:36 -0800418 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
Chen Xu540470b2021-12-14 17:15:47 -0800419
sandeepjsb6c87872021-09-27 15:34:44 +0000420 /**
421 * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than
422 * one ICCID active at the same time.
423 * Apps should use below API signatures if targeting SDK is T and beyond.
424 *
425 * @hide
426 */
427 @ChangeId
428 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
429 public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L;
Rambo Wang0f050d82021-02-12 11:43:36 -0800430
Naina Nallurid63128d2019-09-17 14:10:30 -0700431 /**
Chen Xu540470b2021-12-14 17:15:47 -0800432 * Apps targeting on Android T and beyond will get exception whenever icc close channel
433 * operation fails.
434 */
435 @ChangeId
436 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
437 public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L;
438
439 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 * A request object to use for transmitting data to an ICC.
441 */
442 private static final class IccAPDUArgument {
443 public int channel, cla, command, p1, p2, p3;
444 public String data;
445
446 public IccAPDUArgument(int channel, int cla, int command,
447 int p1, int p2, int p3, String data) {
448 this.channel = channel;
449 this.cla = cla;
450 this.command = command;
451 this.p1 = p1;
452 this.p2 = p2;
453 this.p3 = p3;
454 this.data = data;
455 }
456 }
457
458 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700459 * A request object to use for transmitting data to an ICC.
460 */
461 private static final class ManualNetworkSelectionArgument {
462 public OperatorInfo operatorInfo;
463 public boolean persistSelection;
464
465 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
466 this.operatorInfo = operatorInfo;
467 this.persistSelection = persistSelection;
468 }
469 }
470
471 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
473 * request after sending. The main thread will notify the request when it is complete.
474 */
475 private static final class MainThreadRequest {
476 /** The argument to use for the request */
477 public Object argument;
478 /** The result of the request that is run on the main thread */
479 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800480 // The subscriber id that this request applies to. Defaults to
481 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
482 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483
Nathan Harold92bed182018-10-12 18:16:49 -0700484 // In cases where subId is unavailable, the caller needs to specify the phone.
485 public Phone phone;
486
vagdeviaf9a5b92018-08-15 16:01:53 -0700487 public WorkSource workSource;
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 public MainThreadRequest(Object argument) {
490 this.argument = argument;
491 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800492
Nathan Harold92bed182018-10-12 18:16:49 -0700493 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
494 this.argument = argument;
495 if (phone != null) {
496 this.phone = phone;
497 }
498 this.workSource = workSource;
499 }
500
vagdeviaf9a5b92018-08-15 16:01:53 -0700501 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800502 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800503 if (subId != null) {
504 this.subId = subId;
505 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700506 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700508 }
509
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800510 private static final class IncomingThirdPartyCallArgs {
511 public final ComponentName component;
512 public final String callId;
513 public final String callerDisplayName;
514
515 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
516 String callerDisplayName) {
517 this.component = component;
518 this.callId = callId;
519 this.callerDisplayName = callerDisplayName;
520 }
521 }
522
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 /**
524 * A handler that processes messages on the main thread in the phone process. Since many
525 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
526 * inbound binder threads to the main thread in the phone process. The Binder thread
527 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
528 * on, which will be notified when the operation completes and will contain the result of the
529 * request.
530 *
531 * <p>If a MainThreadRequest object is provided in the msg.obj field,
532 * note that request.result must be set to something non-null for the calling thread to
533 * unblock.
534 */
535 private final class MainThreadHandler extends Handler {
536 @Override
537 public void handleMessage(Message msg) {
538 MainThreadRequest request;
539 Message onCompleted;
540 AsyncResult ar;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000541 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800543 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
545 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 case CMD_HANDLE_USSD_REQUEST: {
547 request = (MainThreadRequest) msg.obj;
548 final Phone phone = getPhoneFromRequest(request);
549 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
Chen Xue9d737e2022-01-01 23:41:31 -0800550 String ussdRequest = ussdObject.first;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700552
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 if (!isUssdApiAllowed(request.subId)) {
554 // Carrier does not support use of this API, return failure.
555 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
556 UssdResponse response = new UssdResponse(ussdRequest, null);
557 Bundle returnData = new Bundle();
558 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
559 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700560
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 request.result = true;
562 notifyRequester(request);
563 return;
564 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700565
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 try {
567 request.result = phone != null
568 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
569 } catch (CallStateException cse) {
570 request.result = false;
571 }
572 // Wake up the requesting thread
573 notifyRequester(request);
574 break;
pkanwar32d516d2016-10-14 19:37:38 -0700575 }
576
Yorke Lee716f67e2015-06-17 15:39:16 -0700577 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700578 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700579 final Phone phone = getPhoneFromRequest(request);
580 request.result = phone != null ?
581 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
582 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700583 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700585 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700587
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000591 uiccPort = getUiccPortFromRequest(request);
592 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 loge("iccTransmitApduLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800594 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800598 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000599 uiccPort.iccTransmitApduLogicalChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800600 iccArgument.channel, iccArgument.cla, iccArgument.command,
601 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
602 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 break;
605
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 ar = (AsyncResult) msg.obj;
608 request = (MainThreadRequest) ar.userObj;
609 if (ar.exception == null && ar.result != null) {
610 request.result = ar.result;
611 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800612 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.result == null) {
614 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800615 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800617 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
619 loge("iccTransmitApduLogicalChannel: Unknown exception");
620 }
621 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
627 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000628 uiccPort = getUiccPortFromRequest(request);
629 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 loge("iccTransmitApduBasicChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800631 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
Chen Xue9d737e2022-01-01 23:41:31 -0800635 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000636 uiccPort.iccTransmitApduBasicChannel(
Chen Xue9d737e2022-01-01 23:41:31 -0800637 iccArgument.cla, iccArgument.command, iccArgument.p1,
638 iccArgument.p2,
639 iccArgument.p3, iccArgument.data, onCompleted);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 break;
642
643 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800649 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.result == null) {
651 loge("iccTransmitApduBasicChannel: Empty response");
652 } else if (ar.exception instanceof CommandException) {
653 loge("iccTransmitApduBasicChannel: CommandException: " +
654 ar.exception);
655 } else {
656 loge("iccTransmitApduBasicChannel: Unknown exception");
657 }
658 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700659 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700660 break;
661
662 case CMD_EXCHANGE_SIM_IO:
663 request = (MainThreadRequest) msg.obj;
664 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000665 uiccPort = getUiccPortFromRequest(request);
666 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 loge("iccExchangeSimIO: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800668 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 } else {
671 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
672 request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000673 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
675 iccArgument.data, onCompleted);
676 }
677 break;
678
679 case EVENT_EXCHANGE_SIM_IO_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result;
684 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800685 request.result = new IccIoResult(0x6f, 0, (byte[]) null);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700686 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 break;
689
Derek Tan4d5e5c12014-02-04 11:54:58 -0800690 case CMD_SEND_ENVELOPE:
691 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000692 uiccPort = getUiccPortFromRequest(request);
693 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 loge("sendEnvelopeWithStatus: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800695 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Chen Xue9d737e2022-01-01 23:41:31 -0800699 uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800701 break;
702
703 case EVENT_SEND_ENVELOPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800708 } else {
Chen Xue9d737e2022-01-01 23:41:31 -0800709 request.result = new IccIoResult(0x6F, 0, (byte[]) null);
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700710 if (ar.result == null) {
711 loge("sendEnvelopeWithStatus: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("sendEnvelopeWithStatus: CommandException: " +
714 ar.exception);
715 } else {
716 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
717 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800720 break;
721
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 case CMD_OPEN_CHANNEL:
723 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000724 uiccPort = getUiccPortFromRequest(request);
Rambo Wanga1782702021-11-10 20:15:19 -0800725 IccLogicalChannelRequest openChannelRequest =
726 (IccLogicalChannelRequest) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000727 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800729 request.result = new IccOpenLogicalChannelResponse(-1,
Chen Xue9d737e2022-01-01 23:41:31 -0800730 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Rambo Wanga1782702021-11-10 20:15:19 -0800734 uiccPort.iccOpenLogicalChannel(openChannelRequest.aid,
735 openChannelRequest.p2, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case EVENT_OPEN_CHANNEL_DONE:
740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700742 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700744 int[] result = (int[]) ar.result;
745 int channelId = result[0];
746 byte[] selectResponse = null;
747 if (result.length > 1) {
748 selectResponse = new byte[result.length - 1];
749 for (int i = 1; i < result.length; ++i) {
750 selectResponse[i - 1] = (byte) result[i];
751 }
752 }
753 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Chen Xue9d737e2022-01-01 23:41:31 -0800754 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800755
756 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700757 if (uiccPort == null) {
758 loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null");
759 } else {
760 IccLogicalChannelRequest channelRequest =
761 (IccLogicalChannelRequest) request.argument;
762 channelRequest.channel = channelId;
763 uiccPort.onLogicalChannelOpened(channelRequest);
764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 if (ar.result == null) {
767 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700769 if (ar.exception != null) {
770 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
771 }
772
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700773 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700774 if (ar.exception instanceof CommandException) {
775 CommandException.Error error =
Chen Xue9d737e2022-01-01 23:41:31 -0800776 ((CommandException) (ar.exception)).getCommandError();
Junda Liua754ba12015-05-20 01:17:52 -0700777 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700778 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700779 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700780 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700781 }
782 }
783 openChannelResp = new IccOpenLogicalChannelResponse(
Chen Xue9d737e2022-01-01 23:41:31 -0800784 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700786 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700787 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700788 break;
789
790 case CMD_CLOSE_CHANNEL:
791 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000792 uiccPort = getUiccPortFromRequest(request);
793 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700794 loge("iccCloseLogicalChannel: No UICC");
Chen Xua8f0dff2022-02-12 00:34:15 -0800795 request.result = new IllegalArgumentException(
Chen Xue9d737e2022-01-01 23:41:31 -0800796 "iccCloseLogicalChannel: No UICC");
Chen Xue9d737e2022-01-01 23:41:31 -0800797 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700798 } else {
799 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +0000800 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700801 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700802 break;
803
804 case EVENT_CLOSE_CHANNEL_DONE:
Chen Xu540470b2021-12-14 17:15:47 -0800805 ar = (AsyncResult) msg.obj;
806 request = (MainThreadRequest) ar.userObj;
807 if (ar.exception == null) {
808 request.result = true;
Rambo Wang3b77c4c2021-11-10 20:15:19 -0800809 uiccPort = getUiccPortFromRequest(request);
Rambo Wange53e07d2022-05-10 13:01:13 -0700810 if (uiccPort == null) {
811 loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null");
812 } else {
813 final int channelId = (Integer) request.argument;
814 uiccPort.onLogicalChannelClosed(channelId);
815 }
Chen Xu540470b2021-12-14 17:15:47 -0800816 } else {
817 request.result = false;
Chen Xue9d737e2022-01-01 23:41:31 -0800818 Exception exception = null;
Chen Xu540470b2021-12-14 17:15:47 -0800819 if (ar.exception instanceof CommandException) {
820 loge("iccCloseLogicalChannel: CommandException: " + ar.exception);
821 CommandException.Error error =
822 ((CommandException) (ar.exception)).getCommandError();
Chen Xue9d737e2022-01-01 23:41:31 -0800823 if (error == CommandException.Error.INVALID_ARGUMENTS) {
824 // should only throw exceptions from the binder threads.
825 exception = new IllegalArgumentException(
Chen Xu540470b2021-12-14 17:15:47 -0800826 "iccCloseLogicalChannel: invalid argument ");
827 }
828 } else {
829 loge("iccCloseLogicalChannel: Unknown exception");
830 }
Chen Xua8f0dff2022-02-12 00:34:15 -0800831 request.result = (exception != null) ? exception :
832 new IllegalStateException(
833 "exception from modem to close iccLogical Channel");
Chen Xu540470b2021-12-14 17:15:47 -0800834 }
835 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -0800836 break;
837
838 case CMD_NV_READ_ITEM:
839 request = (MainThreadRequest) msg.obj;
840 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800841 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
842 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800843 break;
844
845 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700846 ar = (AsyncResult) msg.obj;
847 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800848 if (ar.exception == null && ar.result != null) {
849 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700850 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800851 request.result = "";
852 if (ar.result == null) {
853 loge("nvReadItem: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("nvReadItem: CommandException: " +
856 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700857 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800858 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700859 }
860 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700861 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700862 break;
863
Jake Hambye994d462014-02-03 13:10:13 -0800864 case CMD_NV_WRITE_ITEM:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
867 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800868 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700869 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800870 break;
871
872 case EVENT_NV_WRITE_ITEM_DONE:
873 handleNullReturnEvent(msg, "nvWriteItem");
874 break;
875
876 case CMD_NV_WRITE_CDMA_PRL:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800879 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800880 break;
881
882 case EVENT_NV_WRITE_CDMA_PRL_DONE:
883 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
884 break;
885
chen xu6dac5ab2018-10-26 17:39:23 -0700886 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800887 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700888 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800889 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800890 break;
891
chen xu6dac5ab2018-10-26 17:39:23 -0700892 case EVENT_RESET_MODEM_CONFIG_DONE:
893 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800894 break;
895
Sooraj Sasindran37444802020-08-11 10:40:43 -0700896 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
897 request = (MainThreadRequest) msg.obj;
898 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
899 request);
900 Phone phone = getPhoneFromRequest(request);
901 if (phone != null) {
902 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
903 } else {
904 loge("isNRDualConnectivityEnabled: No phone object");
905 request.result = false;
906 notifyRequester(request);
907 }
908 break;
909 }
910
911 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
917 // request.result must be set to something non-null
918 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700919 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700920 request.result = ar.result;
921 } else {
922 request.result = false;
923 }
924 if (ar.result == null) {
925 loge("isNRDualConnectivityEnabled: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("isNRDualConnectivityEnabled: CommandException: "
928 + ar.exception);
929 } else {
930 loge("isNRDualConnectivityEnabled: Unknown exception");
931 }
932 }
933 notifyRequester(request);
934 break;
935
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700936 case CMD_IS_VONR_ENABLED: {
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
939 request);
940 Phone phone = getPhoneFromRequest(request);
941 if (phone != null) {
942 phone.isVoNrEnabled(onCompleted, request.workSource);
943 } else {
944 loge("isVoNrEnabled: No phone object");
945 request.result = false;
946 notifyRequester(request);
947 }
948 break;
949 }
950
951 case EVENT_IS_VONR_ENABLED_DONE:
952 ar = (AsyncResult) msg.obj;
953 request = (MainThreadRequest) ar.userObj;
954 if (ar.exception == null && ar.result != null) {
955 request.result = ar.result;
956 } else {
957 // request.result must be set to something non-null
958 // for the calling thread to unblock
959 if (ar.result != null) {
960 request.result = ar.result;
961 } else {
962 request.result = false;
963 }
964 if (ar.result == null) {
965 loge("isVoNrEnabled: Empty response");
966 } else if (ar.exception instanceof CommandException) {
967 loge("isVoNrEnabled: CommandException: "
968 + ar.exception);
969 } else {
970 loge("isVoNrEnabled: Unknown exception");
971 }
972 }
973 notifyRequester(request);
974 break;
975
Sooraj Sasindran37444802020-08-11 10:40:43 -0700976 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
979 Phone phone = getPhoneFromRequest(request);
980 if (phone != null) {
981 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
982 request.workSource);
983 } else {
984 loge("enableNrDualConnectivity: No phone object");
985 request.result =
986 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
987 notifyRequester(request);
988 }
989 break;
990 }
991
992 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception == null) {
996 request.result =
997 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
998 } else {
999 request.result =
1000 TelephonyManager
1001 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
1002 if (ar.exception instanceof CommandException) {
1003 CommandException.Error error =
1004 ((CommandException) (ar.exception)).getCommandError();
1005 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1006 request.result =
1007 TelephonyManager
1008 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +00001009 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1010 request.result =
1011 TelephonyManager
1012 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -07001013 }
1014 loge("enableNrDualConnectivity" + ": CommandException: "
1015 + ar.exception);
1016 } else {
1017 loge("enableNrDualConnectivity" + ": Unknown exception");
1018 }
1019 }
1020 notifyRequester(request);
1021 break;
1022 }
1023
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07001024 case CMD_ENABLE_VONR: {
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
1027 Phone phone = getPhoneFromRequest(request);
1028 if (phone != null) {
1029 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
1030 request.workSource);
1031 } else {
1032 loge("setVoNrEnabled: No phone object");
1033 request.result =
1034 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1035 notifyRequester(request);
1036 }
1037 break;
1038 }
1039
1040 case EVENT_ENABLE_VONR_DONE: {
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 if (ar.exception == null) {
1044 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
1045 } else {
1046 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1047 if (ar.exception instanceof CommandException) {
1048 CommandException.Error error =
1049 ((CommandException) (ar.exception)).getCommandError();
1050 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1051 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
1052 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1053 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
1054 } else {
1055 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
1056 }
1057 loge("setVoNrEnabled" + ": CommandException: "
1058 + ar.exception);
1059 } else {
1060 loge("setVoNrEnabled" + ": Unknown exception");
1061 }
1062 }
1063 notifyRequester(request);
1064 break;
1065 }
1066
SongFerngWang3ef3e072020-12-21 16:41:52 +08001067 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -08001068 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001069 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
1070 request);
1071 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001072 break;
1073
SongFerngWang3ef3e072020-12-21 16:41:52 +08001074 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -08001075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
1077 if (ar.exception == null && ar.result != null) {
1078 request.result = ar.result; // Integer
1079 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301080 // request.result must be set to something non-null
1081 // for the calling thread to unblock
1082 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001083 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001084 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001085 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001086 loge("getAllowedNetworkTypesBitmask: CommandException: "
1087 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001088 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001089 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001090 }
1091 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001092 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001093 break;
1094
SongFerngWang3ef3e072020-12-21 16:41:52 +08001095 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001096 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001097 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1098 request);
1099 Pair<Integer, Long> reasonWithNetworkTypes =
1100 (Pair<Integer, Long>) request.argument;
1101 getPhoneFromRequest(request).setAllowedNetworkTypes(
1102 reasonWithNetworkTypes.first,
1103 reasonWithNetworkTypes.second,
1104 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001105 break;
1106
SongFerngWang3ef3e072020-12-21 16:41:52 +08001107 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1108 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001109 break;
1110
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001111 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1112 request = (MainThreadRequest)msg.obj;
1113 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001115 break;
1116
1117 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1118 ar = (AsyncResult)msg.obj;
1119 request = (MainThreadRequest)ar.userObj;
1120 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001121 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001122 break;
1123
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001124 case CMD_SET_VOICEMAIL_NUMBER:
1125 request = (MainThreadRequest) msg.obj;
1126 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1127 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001128 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1129 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001130 break;
1131
1132 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1133 handleNullReturnEvent(msg, "setVoicemailNumber");
1134 break;
1135
Stuart Scott54788802015-03-30 13:18:01 -07001136 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1139 request);
1140 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1141 break;
1142
1143 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1144 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1145 break;
1146
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 case CMD_PERFORM_NETWORK_SCAN:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1150 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1151 break;
1152
Hall Liu27d24262020-09-18 19:04:59 -07001153 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001156 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1157 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1158 request.argument;
1159 int callForwardingReason = args.first;
1160 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001161 break;
Hall Liu27d24262020-09-18 19:04:59 -07001162 }
1163 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001166 TelephonyManager.CallForwardingInfoCallback callback =
1167 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1168 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001169 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001170 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001171 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1172 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1173 // Service Class is a bit mask per 3gpp 27.007. Search for
1174 // any service for voice call.
1175 if ((callForwardInfo.serviceClass
1176 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001177 callForwardingInfo = new CallForwardingInfo(
1178 callForwardInfo.status
1179 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001180 callForwardInfo.reason,
1181 callForwardInfo.number,
1182 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
1184 }
1185 }
1186 // Didn't find a call forward info for voice call.
1187 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001188 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1189 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001190 }
Hall Liu27d24262020-09-18 19:04:59 -07001191 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001192 } else {
1193 if (ar.result == null) {
1194 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1195 }
1196 if (ar.exception != null) {
1197 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1198 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001199 int errorCode = TelephonyManager
1200 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001201 if (ar.exception instanceof CommandException) {
1202 CommandException.Error error =
1203 ((CommandException) (ar.exception)).getCommandError();
1204 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001205 errorCode = TelephonyManager
1206 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001208 errorCode = TelephonyManager
1209 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
1211 }
Hall Liu27d24262020-09-18 19:04:59 -07001212 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001213 }
Shuo Qian4a594052020-01-23 11:59:30 -08001214 break;
Hall Liu27d24262020-09-18 19:04:59 -07001215 }
Shuo Qian4a594052020-01-23 11:59:30 -08001216
Hall Liu27d24262020-09-18 19:04:59 -07001217 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001218 request = (MainThreadRequest) msg.obj;
1219 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001220 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001221 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001222 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1223 request.argument).first;
1224 request.phone.setCallForwardingOption(
1225 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001226 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001227 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001228 callForwardingInfoToSet.getReason(),
1229 callForwardingInfoToSet.getNumber(),
1230 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1231 break;
Hall Liu27d24262020-09-18 19:04:59 -07001232 }
Shuo Qian4a594052020-01-23 11:59:30 -08001233
Hall Liu27d24262020-09-18 19:04:59 -07001234 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001237 Consumer<Integer> callback =
1238 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1239 request.argument).second;
1240 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001241 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001242 int errorCode = TelephonyManager.CallForwardingInfoCallback
1243 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001248 errorCode = TelephonyManager.CallForwardingInfoCallback
1249 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001250 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001251 errorCode = TelephonyManager.CallForwardingInfoCallback
1252 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001253 }
1254 }
1255 callback.accept(errorCode);
1256 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001257 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shuo Qian4a594052020-01-23 11:59:30 -08001261
Hall Liu27d24262020-09-18 19:04:59 -07001262 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001263 request = (MainThreadRequest) msg.obj;
1264 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1265 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1266 break;
Hall Liu27d24262020-09-18 19:04:59 -07001267 }
Shuo Qian4a594052020-01-23 11:59:30 -08001268
Hall Liu27d24262020-09-18 19:04:59 -07001269 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001272 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
SongFerngWangebda2c52022-01-11 15:28:38 +08001273 int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
Shuo Qian4a594052020-01-23 11:59:30 -08001274 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001275 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001276 // Service Class is a bit mask per 3gpp 27.007.
1277 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001278 if (callForwardResults.length > 1
1279 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001280 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001281 callWaitingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001282 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1283 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001284 } else {
SongFerngWangebda2c52022-01-11 15:28:38 +08001285 callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001286 }
1287 } else {
1288 if (ar.result == null) {
1289 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1290 }
1291 if (ar.exception != null) {
1292 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1293 }
1294 if (ar.exception instanceof CommandException) {
1295 CommandException.Error error =
1296 ((CommandException) (ar.exception)).getCommandError();
1297 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
SongFerngWangebda2c52022-01-11 15:28:38 +08001298 callWaitingStatus =
Shuo Qian4a594052020-01-23 11:59:30 -08001299 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
SongFerngWangebda2c52022-01-11 15:28:38 +08001300 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1301 callWaitingStatus =
1302 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001303 }
1304 }
1305 }
SongFerngWangebda2c52022-01-11 15:28:38 +08001306 callback.accept(callWaitingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001307 break;
Hall Liu27d24262020-09-18 19:04:59 -07001308 }
Shuo Qian4a594052020-01-23 11:59:30 -08001309
Hall Liu27d24262020-09-18 19:04:59 -07001310 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001311 request = (MainThreadRequest) msg.obj;
1312 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001313 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1314 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001315 break;
Hall Liu27d24262020-09-18 19:04:59 -07001316 }
Shuo Qian4a594052020-01-23 11:59:30 -08001317
Hall Liu27d24262020-09-18 19:04:59 -07001318 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001319 ar = (AsyncResult) msg.obj;
1320 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001321 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1322 Consumer<Integer> callback =
1323 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1324 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001325 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001326 if (ar.exception instanceof CommandException) {
1327 CommandException.Error error =
1328 ((CommandException) (ar.exception)).getCommandError();
1329 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1330 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
SongFerngWangebda2c52022-01-11 15:28:38 +08001331 } else if (error == CommandException.Error.FDN_CHECK_FAILURE) {
1332 callback.accept(
1333 TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE);
Hall Liu27d24262020-09-18 19:04:59 -07001334 } else {
1335 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1336 }
1337 } else {
1338 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1339 }
1340 } else {
1341 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1342 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001343 }
Shuo Qian4a594052020-01-23 11:59:30 -08001344 break;
Hall Liu27d24262020-09-18 19:04:59 -07001345 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001346 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1347 ar = (AsyncResult) msg.obj;
1348 request = (MainThreadRequest) ar.userObj;
1349 CellNetworkScanResult cellScanResult;
1350 if (ar.exception == null && ar.result != null) {
1351 cellScanResult = new CellNetworkScanResult(
1352 CellNetworkScanResult.STATUS_SUCCESS,
1353 (List<OperatorInfo>) ar.result);
1354 } else {
1355 if (ar.result == null) {
1356 loge("getCellNetworkScanResults: Empty response");
1357 }
1358 if (ar.exception != null) {
1359 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1360 }
1361 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1362 if (ar.exception instanceof CommandException) {
1363 CommandException.Error error =
1364 ((CommandException) (ar.exception)).getCommandError();
1365 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1366 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1367 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1368 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1369 }
1370 }
1371 cellScanResult = new CellNetworkScanResult(errorCode, null);
1372 }
1373 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001375 break;
1376
1377 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1378 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001379 ManualNetworkSelectionArgument selArg =
1380 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001381 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1382 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001383 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1384 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001385 break;
1386
1387 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001388 ar = (AsyncResult) msg.obj;
1389 request = (MainThreadRequest) ar.userObj;
1390 if (ar.exception == null) {
1391 request.result = true;
1392 } else {
1393 request.result = false;
1394 loge("setNetworkSelectionModeManual " + ar.exception);
1395 }
1396 notifyRequester(request);
1397 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001398 break;
1399
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001400 case CMD_GET_MODEM_ACTIVITY_INFO:
1401 request = (MainThreadRequest) msg.obj;
1402 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001403 if (defaultPhone != null) {
1404 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001405 } else {
1406 ResultReceiver result = (ResultReceiver) request.argument;
1407 Bundle bundle = new Bundle();
1408 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001409 new ModemActivityInfo(0, 0, 0,
1410 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001411 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001412 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001413 break;
1414
Hall Liud0f208c2020-10-14 16:54:44 -07001415 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001416 ar = (AsyncResult) msg.obj;
1417 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001418 ResultReceiver result = (ResultReceiver) request.argument;
Hall Liud0f208c2020-10-14 16:54:44 -07001419 int error = 0;
Gary Jian3aa9a762022-01-24 16:41:19 +08001420 if (mLastModemActivityInfo == null) {
1421 mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1];
1422 mLastModemActivitySpecificInfo[0] =
1423 new ActivityStatsTechSpecificInfo(
1424 0,
1425 0,
1426 new int[ModemActivityInfo.getNumTxPowerLevels()],
1427 0);
1428 mLastModemActivityInfo =
1429 new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo);
1430 }
1431
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001432 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001433 // Update the last modem activity info and the result of the request.
1434 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1435 if (isModemActivityInfoValid(info)) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001436 mergeModemActivityInfo(info);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001437 }
Gary Jian3aa9a762022-01-24 16:41:19 +08001438 mLastModemActivityInfo =
1439 new ModemActivityInfo(
1440 mLastModemActivityInfo.getTimestampMillis(),
1441 mLastModemActivityInfo.getSleepTimeMillis(),
1442 mLastModemActivityInfo.getIdleTimeMillis(),
1443 mLastModemActivitySpecificInfo);
1444
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001445 } else {
1446 if (ar.result == null) {
1447 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001448 error = TelephonyManager.ModemActivityInfoException
1449 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001450 } else if (ar.exception instanceof CommandException) {
Gary Jian3aa9a762022-01-24 16:41:19 +08001451 loge("queryModemActivityInfo: CommandException: " + ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001452 error = TelephonyManager.ModemActivityInfoException
1453 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001454 } else {
1455 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001456 error = TelephonyManager.ModemActivityInfoException
1457 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001458 }
1459 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001460 Bundle bundle = new Bundle();
Gary Jian3aa9a762022-01-24 16:41:19 +08001461 if (mLastModemActivityInfo != null) {
1462 bundle.putParcelable(
1463 TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1464 mLastModemActivityInfo);
Hall Liud0f208c2020-10-14 16:54:44 -07001465 } else {
1466 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1467 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001468 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001470 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001471 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001472
Meng Wang1a7c35a2016-05-05 20:56:15 -07001473 case CMD_SET_ALLOWED_CARRIERS:
1474 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001475 CarrierRestrictionRules argument =
1476 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001477 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001478 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001479 break;
1480
1481 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
1484 if (ar.exception == null && ar.result != null) {
1485 request.result = ar.result;
1486 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001487 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1488 if (ar.exception instanceof CommandException) {
1489 loge("setAllowedCarriers: CommandException: " + ar.exception);
1490 CommandException.Error error =
1491 ((CommandException) (ar.exception)).getCommandError();
1492 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1493 request.result =
1494 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1495 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001496 } else {
1497 loge("setAllowedCarriers: Unknown exception");
1498 }
1499 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001501 break;
1502
1503 case CMD_GET_ALLOWED_CARRIERS:
1504 request = (MainThreadRequest) msg.obj;
1505 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001506 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001507 break;
1508
1509 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception == null && ar.result != null) {
1513 request.result = ar.result;
1514 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001515 request.result = new IllegalStateException(
1516 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001517 if (ar.result == null) {
1518 loge("getAllowedCarriers: Empty response");
1519 } else if (ar.exception instanceof CommandException) {
1520 loge("getAllowedCarriers: CommandException: " +
1521 ar.exception);
1522 } else {
1523 loge("getAllowedCarriers: Unknown exception");
1524 }
1525 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001526 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001527 break;
1528
Nathan Haroldb3014052017-01-25 15:57:32 -08001529 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception == null && ar.result != null) {
1533 request.result = ar.result;
1534 } else {
1535 request.result = new IllegalArgumentException(
1536 "Failed to retrieve Forbidden Plmns");
1537 if (ar.result == null) {
1538 loge("getForbiddenPlmns: Empty response");
1539 } else {
1540 loge("getForbiddenPlmns: Unknown exception");
1541 }
1542 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001543 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001544 break;
1545
1546 case CMD_GET_FORBIDDEN_PLMNS:
1547 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001548 uiccPort = getUiccPortFromRequest(request);
1549 if (uiccPort == null) {
1550 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001551 request.result = new IllegalArgumentException(
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001552 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001553 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001554 break;
1555 }
1556 Integer appType = (Integer) request.argument;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001557 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001558 if (uiccApp == null) {
1559 loge("getForbiddenPlmns() no app with specified type -- "
1560 + appType);
1561 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001562 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001563 break;
1564 } else {
1565 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1566 + " specified type -- " + appType);
1567 }
1568 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1569 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1570 onCompleted);
1571 break;
1572
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001573 case CMD_SWITCH_SLOTS:
1574 request = (MainThreadRequest) msg.obj;
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001575 List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001576 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00001577 UiccController.getInstance().switchSlots(slotMapping, onCompleted);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 break;
1579
1580 case EVENT_SWITCH_SLOTS_DONE:
1581 ar = (AsyncResult) msg.obj;
1582 request = (MainThreadRequest) ar.userObj;
1583 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001584 notifyRequester(request);
1585 break;
1586 case CMD_GET_NETWORK_SELECTION_MODE:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1589 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1590 break;
1591
1592 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
1595 if (ar.exception != null) {
1596 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1597 } else {
1598 int mode = ((int[]) ar.result)[0];
1599 if (mode == 0) {
1600 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1601 } else {
1602 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1603 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001605 notifyRequester(request);
1606 break;
1607 case CMD_GET_CDMA_ROAMING_MODE:
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1610 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1611 break;
1612 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1613 ar = (AsyncResult) msg.obj;
1614 request = (MainThreadRequest) ar.userObj;
1615 if (ar.exception != null) {
1616 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1617 } else {
1618 request.result = ((int[]) ar.result)[0];
1619 }
1620 notifyRequester(request);
1621 break;
1622 case CMD_SET_CDMA_ROAMING_MODE:
1623 request = (MainThreadRequest) msg.obj;
1624 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1625 int mode = (int) request.argument;
1626 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1627 break;
1628 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 request.result = ar.exception == null;
1632 notifyRequester(request);
1633 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001634 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1637 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1638 break;
1639 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1640 ar = (AsyncResult) msg.obj;
1641 request = (MainThreadRequest) ar.userObj;
1642 if (ar.exception != null) {
1643 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1644 } else {
1645 request.result = ((int[]) ar.result)[0];
1646 }
1647 notifyRequester(request);
1648 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001649 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1650 request = (MainThreadRequest) msg.obj;
1651 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1652 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001653 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1654 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001655 break;
1656 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 request.result = ar.exception == null;
1660 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001661 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001662 case CMD_GET_ALL_CELL_INFO:
1663 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001664 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001665 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001666 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001667 case EVENT_GET_ALL_CELL_INFO_DONE:
1668 ar = (AsyncResult) msg.obj;
1669 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001670 // If a timeout occurs, the response will be null
1671 request.result = (ar.exception == null && ar.result != null)
1672 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001673 synchronized (request) {
1674 request.notifyAll();
1675 }
1676 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001677 case CMD_REQUEST_CELL_INFO_UPDATE:
1678 request = (MainThreadRequest) msg.obj;
1679 request.phone.requestCellInfoUpdate(request.workSource,
1680 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1681 break;
1682 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1686 try {
1687 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001688 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001689 cb.onError(
1690 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1691 ar.exception.getClass().getName(),
1692 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001693 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001694 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001695 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001696 } else {
1697 // use the result as returned
1698 cb.onCellInfo((List<CellInfo>) ar.result);
1699 }
1700 } catch (RemoteException re) {
1701 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1702 }
1703 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001704 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001705 request = (MainThreadRequest) msg.obj;
1706 WorkSource ws = (WorkSource) request.argument;
1707 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001708 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001709 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001710 }
1711 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 if (ar.exception == null) {
1715 request.result = ar.result;
1716 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001717 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001718 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001719 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001720 }
1721
1722 synchronized (request) {
1723 request.notifyAll();
1724 }
1725 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001726 }
chen xu6dac5ab2018-10-26 17:39:23 -07001727 case CMD_MODEM_REBOOT:
1728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001730 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001731 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001732 case EVENT_CMD_MODEM_REBOOT_DONE:
1733 handleNullReturnEvent(msg, "rebootModem");
1734 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001735 case CMD_REQUEST_ENABLE_MODEM:
1736 request = (MainThreadRequest) msg.obj;
1737 boolean enable = (boolean) request.argument;
1738 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001739 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001740 PhoneConfigurationManager.getInstance()
1741 .enablePhone(request.phone, enable, onCompleted);
1742 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001743 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001744 ar = (AsyncResult) msg.obj;
1745 request = (MainThreadRequest) ar.userObj;
1746 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001747 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001748 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001749 if ((boolean) request.result) {
1750 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1751 updateModemStateMetrics();
1752 } else {
1753 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1754 + ar.exception);
1755 }
1756 notifyRequester(request);
1757 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001758 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001759 case CMD_GET_MODEM_STATUS:
1760 request = (MainThreadRequest) msg.obj;
1761 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1762 PhoneConfigurationManager.getInstance()
1763 .getPhoneStatusFromModem(request.phone, onCompleted);
1764 break;
1765 case EVENT_GET_MODEM_STATUS_DONE:
1766 ar = (AsyncResult) msg.obj;
1767 request = (MainThreadRequest) ar.userObj;
1768 int id = request.phone.getPhoneId();
1769 if (ar.exception == null && ar.result != null) {
1770 request.result = ar.result;
1771 //update the cache as modem status has changed
1772 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1773 (boolean) request.result);
1774 } else {
1775 // Return true if modem status cannot be retrieved. For most cases,
1776 // modem status is on. And for older version modems, GET_MODEM_STATUS
1777 // and disable modem are not supported. Modem is always on.
1778 // TODO: this should be fixed in R to support a third
1779 // status UNKNOWN b/131631629
1780 request.result = true;
1781 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1782 + ar.exception);
1783 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001784 notifyRequester(request);
1785 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001786 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1787 request = (MainThreadRequest) msg.obj;
1788 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1789 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1790 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1791 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1792 break;
1793 }
1794 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1795 ar = (AsyncResult) msg.obj;
1796 request = (MainThreadRequest) ar.userObj;
1797 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1798 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1799 args.second.accept(ar.exception == null);
1800 notifyRequester(request);
1801 break;
1802 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001803 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1804 request = (MainThreadRequest) msg.obj;
1805 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1806 Phone phone = getPhoneFromRequest(request);
1807 if (phone != null) {
1808 phone.getSystemSelectionChannels(onCompleted);
1809 } else {
1810 loge("getSystemSelectionChannels: No phone object");
1811 request.result = new ArrayList<RadioAccessSpecifier>();
1812 notifyRequester(request);
1813 }
1814 break;
1815 }
1816 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1817 ar = (AsyncResult) msg.obj;
1818 request = (MainThreadRequest) ar.userObj;
1819 if (ar.exception == null && ar.result != null) {
1820 request.result = ar.result;
1821 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001822 request.result = new IllegalStateException(
1823 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001824 if (ar.result == null) {
1825 loge("getSystemSelectionChannels: Empty response");
1826 } else {
1827 loge("getSystemSelectionChannels: Unknown exception");
1828 }
1829 }
1830 notifyRequester(request);
1831 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001832 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1833 ar = (AsyncResult) msg.obj;
1834 request = (MainThreadRequest) ar.userObj;
1835 if (ar.exception == null && ar.result != null) {
1836 request.result = ar.result;
1837 } else {
1838 request.result = -1;
1839 loge("Failed to set Forbidden Plmns");
1840 if (ar.result == null) {
1841 loge("setForbidenPlmns: Empty response");
1842 } else if (ar.exception != null) {
1843 loge("setForbiddenPlmns: Exception: " + ar.exception);
1844 request.result = -1;
1845 } else {
1846 loge("setForbiddenPlmns: Unknown exception");
1847 }
1848 }
1849 notifyRequester(request);
1850 break;
1851 case CMD_SET_FORBIDDEN_PLMNS:
1852 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001853 uiccPort = getUiccPortFromRequest(request);
1854 if (uiccPort == null) {
1855 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001856 request.result = -1;
1857 notifyRequester(request);
1858 break;
1859 }
1860 Pair<Integer, List<String>> setFplmnsArgs =
1861 (Pair<Integer, List<String>>) request.argument;
1862 appType = setFplmnsArgs.first;
1863 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00001864 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001865 if (uiccApp == null) {
1866 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1867 request.result = -1;
1868 loge("Failed to get UICC App");
1869 notifyRequester(request);
1870 } else {
1871 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1872 ((SIMRecords) uiccApp.getIccRecords())
1873 .setForbiddenPlmns(onCompleted, fplmns);
1874 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001875 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001876 case CMD_ERASE_MODEM_CONFIG:
1877 request = (MainThreadRequest) msg.obj;
1878 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1879 defaultPhone.eraseModemConfig(onCompleted);
1880 break;
1881 case EVENT_ERASE_MODEM_CONFIG_DONE:
1882 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001883 break;
zoey chene02881a2019-12-30 16:11:23 +08001884
Kai Shif70f46f2021-03-03 13:59:46 -08001885 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1886 request = (MainThreadRequest) msg.obj;
1887 request.result = defaultPhone.eraseDataInSharedPreferences();
1888 notifyRequester(request);
1889 break;
1890
zoey chene02881a2019-12-30 16:11:23 +08001891 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1892 request = (MainThreadRequest) msg.obj;
1893 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1894 Pair<String, String> changed = (Pair<String, String>) request.argument;
1895 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1896 changed.first, changed.second, onCompleted);
1897 break;
1898 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 if (ar.exception == null) {
1902 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001903 // If the operation is successful, update the PIN storage
1904 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1905 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-10-06 20:53:09 +00001906 UiccController.getInstance().getPinStorage()
1907 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001908 } else {
1909 request.result = msg.arg1;
1910 }
1911 notifyRequester(request);
1912 break;
1913
Michele Berionne5e411512020-11-13 02:36:59 +00001914 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001915 request = (MainThreadRequest) msg.obj;
1916 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1917 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1918 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1919 enabled.first, enabled.second, onCompleted);
1920 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001921 }
zoey chene02881a2019-12-30 16:11:23 +08001922 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 if (ar.exception == null) {
1926 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001927 // If the operation is successful, update the PIN storage
1928 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1929 int phoneId = getPhoneFromRequest(request).getPhoneId();
1930 if (enabled.first) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00001931 UiccController.getInstance().getPinStorage()
1932 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001933 } else {
1934 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1935 }
zoey chene02881a2019-12-30 16:11:23 +08001936 } else {
1937 request.result = msg.arg1;
1938 }
Michele Berionne5e411512020-11-13 02:36:59 +00001939
1940
zoey chene02881a2019-12-30 16:11:23 +08001941 notifyRequester(request);
1942 break;
1943
Peter Wangdafb9ac2020-01-15 14:13:38 -08001944 case MSG_NOTIFY_USER_ACTIVITY:
1945 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001946 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001947 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1948 getDefaultPhone().getContext().sendBroadcastAsUser(
1949 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1950 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001951
1952 case CMD_SET_DATA_THROTTLING: {
1953 request = (MainThreadRequest) msg.obj;
1954 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1955 DataThrottlingRequest dataThrottlingRequest =
1956 (DataThrottlingRequest) request.argument;
1957 Phone phone = getPhoneFromRequest(request);
1958 if (phone != null) {
1959 phone.setDataThrottling(onCompleted,
1960 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1961 dataThrottlingRequest.getCompletionDurationMillis());
1962 } else {
1963 loge("setDataThrottling: No phone object");
1964 request.result =
1965 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1966 notifyRequester(request);
1967 }
1968
1969 break;
1970 }
1971 case EVENT_SET_DATA_THROTTLING_DONE:
1972 ar = (AsyncResult) msg.obj;
1973 request = (MainThreadRequest) ar.userObj;
1974
1975 if (ar.exception == null) {
1976 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1977 } else if (ar.exception instanceof CommandException) {
1978 loge("setDataThrottling: CommandException: " + ar.exception);
1979 CommandException.Error error =
1980 ((CommandException) (ar.exception)).getCommandError();
1981
1982 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1983 request.result = TelephonyManager
1984 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1985 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1986 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001987 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1988 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001989 } else {
1990 request.result =
1991 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1992 }
1993 } else {
1994 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1995 }
1996 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1997 notifyRequester(request);
1998 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001999
2000 case CMD_SET_SIM_POWER: {
2001 request = (MainThreadRequest) msg.obj;
2002 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
2003 request = (MainThreadRequest) msg.obj;
2004 int stateToSet =
2005 ((Pair<Integer, IIntegerConsumer>)
2006 request.argument).first;
2007 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
2008 break;
2009 }
2010 case EVENT_SET_SIM_POWER_DONE: {
2011 ar = (AsyncResult) msg.obj;
2012 request = (MainThreadRequest) ar.userObj;
2013 IIntegerConsumer callback =
2014 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
2015 if (ar.exception != null) {
2016 loge("setSimPower exception: " + ar.exception);
2017 int errorCode = TelephonyManager.CallForwardingInfoCallback
2018 .RESULT_ERROR_UNKNOWN;
2019 if (ar.exception instanceof CommandException) {
2020 CommandException.Error error =
2021 ((CommandException) (ar.exception)).getCommandError();
2022 if (error == CommandException.Error.SIM_ERR) {
2023 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
2024 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
2025 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
2026 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
2027 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
2028 } else {
2029 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
2030 }
2031 }
2032 try {
2033 callback.accept(errorCode);
2034 } catch (RemoteException e) {
2035 // Ignore if the remote process is no longer available to call back.
2036 Log.w(LOG_TAG, "setSimPower: callback not available.");
2037 }
2038 } else {
2039 try {
2040 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
2041 } catch (RemoteException e) {
2042 // Ignore if the remote process is no longer available to call back.
2043 Log.w(LOG_TAG, "setSimPower: callback not available.");
2044 }
2045 }
2046 break;
2047 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002048 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2049 request = (MainThreadRequest) msg.obj;
2050
2051 final Phone phone = getPhoneFromRequest(request);
2052 if (phone == null || phone.getServiceStateTracker() == null) {
2053 request.result = new IllegalStateException("Phone or SST is null");
2054 notifyRequester(request);
2055 break;
2056 }
2057
2058 Pair<Integer, SignalStrengthUpdateRequest> pair =
2059 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2060 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2061 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002062 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002063 request.subId, pair.first /*callingUid*/,
2064 pair.second /*request*/, onCompleted);
2065 break;
2066 }
2067 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2068 ar = (AsyncResult) msg.obj;
2069 request = (MainThreadRequest) ar.userObj;
2070 // request.result will be the exception of ar if present, true otherwise.
2071 // Be cautious not to leave result null which will wait() forever
2072 request.result = ar.exception != null ? ar.exception : true;
2073 notifyRequester(request);
2074 break;
2075 }
2076 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
2077 request = (MainThreadRequest) msg.obj;
2078
2079 Phone phone = getPhoneFromRequest(request);
2080 if (phone == null || phone.getServiceStateTracker() == null) {
2081 request.result = new IllegalStateException("Phone or SST is null");
2082 notifyRequester(request);
2083 break;
2084 }
2085
2086 Pair<Integer, SignalStrengthUpdateRequest> pair =
2087 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2088 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2089 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002090 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002091 request.subId, pair.first /*callingUid*/,
2092 pair.second /*request*/, onCompleted);
2093 break;
2094 }
2095 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2096 ar = (AsyncResult) msg.obj;
2097 request = (MainThreadRequest) ar.userObj;
2098 request.result = ar.exception != null ? ar.exception : true;
2099 notifyRequester(request);
2100 break;
2101 }
Jordan Liu109698e2020-11-24 14:50:34 -08002102
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002103 case CMD_GET_SLICING_CONFIG: {
2104 request = (MainThreadRequest) msg.obj;
2105 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2106 request.phone.getSlicingConfig(onCompleted);
2107 break;
2108 }
2109 case EVENT_GET_SLICING_CONFIG_DONE: {
2110 ar = (AsyncResult) msg.obj;
2111 request = (MainThreadRequest) ar.userObj;
2112 ResultReceiver result = (ResultReceiver) request.argument;
2113
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002114 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002115 Bundle bundle = new Bundle();
2116 int resultCode = 0;
2117 if (ar.exception != null) {
2118 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2119 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002120 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002121 } else if (ar.result == null) {
2122 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002123 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002124 } else {
2125 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002126 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2127 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002128 }
2129
2130 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002131 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002132 }
2133 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2134 result.send(resultCode, bundle);
2135 notifyRequester(request);
2136 break;
2137 }
2138
Michele Berionne5e411512020-11-13 02:36:59 +00002139 case CMD_PREPARE_UNATTENDED_REBOOT:
2140 request = (MainThreadRequest) msg.obj;
2141 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002142 UiccController.getInstance().getPinStorage()
2143 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002144 notifyRequester(request);
2145 break;
2146
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 default:
2148 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2149 break;
2150 }
2151 }
Jake Hambye994d462014-02-03 13:10:13 -08002152
Pengquan Menga1bb6272018-09-06 09:59:22 -07002153 private void notifyRequester(MainThreadRequest request) {
2154 synchronized (request) {
2155 request.notifyAll();
2156 }
2157 }
2158
Jake Hambye994d462014-02-03 13:10:13 -08002159 private void handleNullReturnEvent(Message msg, String command) {
2160 AsyncResult ar = (AsyncResult) msg.obj;
2161 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2162 if (ar.exception == null) {
2163 request.result = true;
2164 } else {
2165 request.result = false;
2166 if (ar.exception instanceof CommandException) {
2167 loge(command + ": CommandException: " + ar.exception);
2168 } else {
2169 loge(command + ": Unknown exception");
2170 }
2171 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002172 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 }
2175
2176 /**
2177 * Posts the specified command to be executed on the main thread,
2178 * waits for the request to complete, and returns the result.
2179 * @see #sendRequestAsync
2180 */
2181 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2183 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002184 }
2185
2186 /**
2187 * Posts the specified command to be executed on the main thread,
2188 * waits for the request to complete, and returns the result.
2189 * @see #sendRequestAsync
2190 */
2191 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2192 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002193 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
2196 /**
2197 * Posts the specified command to be executed on the main thread,
2198 * waits for the request to complete, and returns the result.
2199 * @see #sendRequestAsync
2200 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002201 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002202 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2203 }
2204
2205 /**
2206 * Posts the specified command to be executed on the main thread,
2207 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2208 * if not timeout or null otherwise.
2209 * @see #sendRequestAsync
2210 */
2211 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2212 long timeoutInMs) {
2213 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002214 }
2215
2216 /**
2217 * Posts the specified command to be executed on the main thread,
2218 * waits for the request to complete, and returns the result.
2219 * @see #sendRequestAsync
2220 */
Nathan Harold92bed182018-10-12 18:16:49 -07002221 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002222 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002223 }
2224
2225 /**
2226 * Posts the specified command to be executed on the main thread,
2227 * waits for the request to complete, and returns the result.
2228 * @see #sendRequestAsync
2229 */
2230 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002231 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2232 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002233 }
2234
2235 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002236 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2237 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2238 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002239 * @see #sendRequestAsync
2240 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002241 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2242 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2244 throw new RuntimeException("This method will deadlock if called from the main thread.");
2245 }
2246
Nathan Harold92bed182018-10-12 18:16:49 -07002247 MainThreadRequest request = null;
2248 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2249 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2250 } else if (phone != null) {
2251 request = new MainThreadRequest(argument, phone, workSource);
2252 } else {
2253 request = new MainThreadRequest(argument, subId, workSource);
2254 }
2255
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 Message msg = mMainThreadHandler.obtainMessage(command, request);
2257 msg.sendToTarget();
2258
Rambo Wang0f050d82021-02-12 11:43:36 -08002259
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002261 if (timeoutInMs >= 0) {
2262 // Wait for at least timeoutInMs before returning null request result
2263 long now = SystemClock.elapsedRealtime();
2264 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002265 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002266 try {
2267 request.wait(deadline - now);
2268 } catch (InterruptedException e) {
2269 // Do nothing, go back and check if request is completed or timeout
2270 } finally {
2271 now = SystemClock.elapsedRealtime();
2272 }
2273 }
2274 } else {
2275 // Wait for the request to complete
2276 while (request.result == null) {
2277 try {
2278 request.wait();
2279 } catch (InterruptedException e) {
2280 // Do nothing, go back and wait until the request is complete
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283 }
2284 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002285 if (request.result == null) {
2286 Log.wtf(LOG_TAG,
2287 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 return request.result;
2290 }
2291
2292 /**
2293 * Asynchronous ("fire and forget") version of sendRequest():
2294 * Posts the specified command to be executed on the main thread, and
2295 * returns immediately.
2296 * @see #sendRequest
2297 */
2298 private void sendRequestAsync(int command) {
2299 mMainThreadHandler.sendEmptyMessage(command);
2300 }
2301
2302 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002303 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002304 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002305 */
2306 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002307 sendRequestAsync(command, argument, null, null);
2308 }
2309
2310 /**
2311 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2312 * @see {@link #sendRequest(int,Object)}
2313 */
2314 private void sendRequestAsync(
2315 int command, Object argument, Phone phone, WorkSource workSource) {
2316 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002317 Message msg = mMainThreadHandler.obtainMessage(command, request);
2318 msg.sendToTarget();
2319 }
2320
2321 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 * Initialize the singleton PhoneInterfaceManager instance.
2323 * This is only done once, at startup, from PhoneApp.onCreate().
2324 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002325 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 synchronized (PhoneInterfaceManager.class) {
2327 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002328 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 } else {
2330 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2331 }
2332 return sInstance;
2333 }
2334 }
2335
2336 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002337 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002340 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002341 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002343 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002345 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002346 mTelephonySharedPreferences =
2347 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002348 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002349 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002350 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002351 mNotifyUserActivity = new AtomicBoolean(false);
Tyler Gunn64144d92022-03-17 14:16:41 -07002352 PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID);
Gil Cukiermand6cae882022-12-29 12:02:31 -05002353 mTelephony2gUpdater = new Telephony2gUpdater(mApp);
Gil Cukierman6dac5eb2022-09-19 16:09:04 +00002354 mTelephony2gUpdater.init();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 publish();
2356 }
2357
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002358 private Phone getDefaultPhone() {
2359 Phone thePhone = getPhone(getDefaultSubscription());
2360 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2361 }
2362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 private void publish() {
2364 if (DBG) log("publish: " + this);
2365
Peter Wangc035ce42020-01-08 21:00:22 -08002366 TelephonyFrameworkInitializer
2367 .getTelephonyServiceManager()
2368 .getTelephonyServiceRegisterer()
2369 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
2371
Stuart Scott584921c2015-01-15 17:10:34 -08002372 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002373 if (request.phone != null) {
2374 return request.phone;
2375 } else {
2376 return getPhoneFromSubId(request.subId);
2377 }
2378 }
2379
2380 private Phone getPhoneFromSubId(int subId) {
2381 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2382 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002383 }
2384
Rambo Wange53e07d2022-05-10 13:01:13 -07002385 @Nullable
2386 private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 Phone phone = getPhoneFromRequest(request);
2388 return phone == null ? null :
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00002389 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 }
2391
Wink Saville36469e72014-06-11 15:17:00 -07002392 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002393 private Phone getPhone(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08002394 return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396
Kai Shif70f46f2021-03-03 13:59:46 -08002397 private void sendEraseModemConfig(@NonNull Phone phone) {
2398 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2399 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2400 }
2401
2402 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2403 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2404 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002405 }
2406
Peter Wang44b186e2020-01-13 23:33:09 -08002407 private boolean isImsAvailableOnDevice() {
2408 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2409 if (pm == null) {
2410 // For some reason package manger is not available.. This will fail internally anyway,
2411 // so do not throw error and allow.
2412 return true;
2413 }
2414 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2415 }
2416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002418 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002419 }
2420
Wink Savilleb564aae2014-10-23 10:18:09 -07002421 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 if (DBG) log("dial: " + number);
2423 // No permission check needed here: This is just a wrapper around the
2424 // ACTION_DIAL intent, which is available to any app since it puts up
2425 // the UI before it does anything.
2426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 String url = createTelUrl(number);
2430 if (url == null) {
2431 return;
2432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 // PENDING: should we just silently fail if phone is offhook or ringing?
2435 PhoneConstants.State state = mCM.getState(subId);
2436 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2437 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2439 mApp.startActivity(intent);
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444 }
2445
2446 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002447 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
2449
Wink Savilleb564aae2014-10-23 10:18:09 -07002450 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 if (DBG) log("call: " + number);
2452
2453 // This is just a wrapper around the ACTION_CALL intent, but we still
2454 // need to do a permission check since we're calling startActivity()
2455 // from the context of the phone app.
2456 enforceCallPermission();
2457
Jordan Liu1617b712019-07-10 15:06:26 -07002458 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459 != AppOpsManager.MODE_ALLOWED) {
2460 return;
2461 }
2462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 String url = createTelUrl(number);
2466 if (url == null) {
2467 return;
2468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 boolean isValid = false;
2471 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2472 if (slist != null) {
2473 for (SubscriptionInfo subInfoRecord : slist) {
2474 if (subInfoRecord.getSubscriptionId() == subId) {
2475 isValid = true;
2476 break;
2477 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002478 }
Wink Saville08874612014-08-31 19:19:58 -07002479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480 if (!isValid) {
2481 return;
2482 }
Wink Saville08874612014-08-31 19:19:58 -07002483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2485 intent.putExtra(SUBSCRIPTION_KEY, subId);
2486 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2487 mApp.startActivity(intent);
2488 } finally {
2489 Binder.restoreCallingIdentity(identity);
2490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 }
2492
Wink Savilleb564aae2014-10-23 10:18:09 -07002493 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002494 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002495 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2496 }
2497
Wink Savilleb564aae2014-10-23 10:18:09 -07002498 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002499 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002500 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2501 }
2502
Wink Savilleb564aae2014-10-23 10:18:09 -07002503 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002508 Phone phone = getPhone(subId);
2509 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 checkSimPin.start();
2511 return checkSimPin.unlockSim(null, pin);
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
2514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Wink Savilleb564aae2014-10-23 10:18:09 -07002517 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002522 Phone phone = getPhone(subId);
2523 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002524 checkSimPuk.start();
2525 return checkSimPuk.unlockSim(puk, pin);
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
2528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
2530
2531 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002532 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002533 * a synchronous one.
2534 */
2535 private static class UnlockSim extends Thread {
2536
2537 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002538 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539
2540 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002541 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2542 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543
2544 // For replies from SimCard interface
2545 private Handler mHandler;
2546
2547 // For async handler to identify request type
2548 private static final int SUPPLY_PIN_COMPLETE = 100;
2549
Michele Berionne5e411512020-11-13 02:36:59 +00002550 UnlockSim(int phoneId, IccCard simCard) {
2551 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 mSimCard = simCard;
2553 }
2554
2555 @Override
2556 public void run() {
2557 Looper.prepare();
2558 synchronized (UnlockSim.this) {
2559 mHandler = new Handler() {
2560 @Override
2561 public void handleMessage(Message msg) {
2562 AsyncResult ar = (AsyncResult) msg.obj;
2563 switch (msg.what) {
2564 case SUPPLY_PIN_COMPLETE:
2565 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2566 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002567 mRetryCount = msg.arg1;
2568 if (ar.exception != null) {
2569 if (ar.exception instanceof CommandException &&
2570 ((CommandException)(ar.exception)).getCommandError()
2571 == CommandException.Error.PASSWORD_INCORRECT) {
2572 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002573 } //When UiccCardApp dispose,handle message and return exception
2574 else if (ar.exception instanceof CommandException &&
2575 ((CommandException) (ar.exception)).getCommandError()
2576 == CommandException.Error.ABORTED) {
2577 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002578 } else {
2579 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2580 }
2581 } else {
2582 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 mDone = true;
2585 UnlockSim.this.notifyAll();
2586 }
2587 break;
2588 }
2589 }
2590 };
2591 UnlockSim.this.notifyAll();
2592 }
2593 Looper.loop();
2594 }
2595
2596 /*
2597 * Use PIN or PUK to unlock SIM card
2598 *
2599 * If PUK is null, unlock SIM card with PIN
2600 *
2601 * If PUK is not null, unlock SIM card with PUK and set PIN code
2602 */
Wink Saville9de0f752013-10-22 19:04:03 -07002603 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604
2605 while (mHandler == null) {
2606 try {
2607 wait();
2608 } catch (InterruptedException e) {
2609 Thread.currentThread().interrupt();
2610 }
2611 }
2612 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2613
2614 if (puk == null) {
2615 mSimCard.supplyPin(pin, callback);
2616 } else {
2617 mSimCard.supplyPuk(puk, pin, callback);
2618 }
2619
2620 while (!mDone) {
2621 try {
2622 Log.d(LOG_TAG, "wait for done");
2623 wait();
2624 } catch (InterruptedException e) {
2625 // Restore the interrupted status
2626 Thread.currentThread().interrupt();
2627 }
2628 }
2629 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002630 int[] resultArray = new int[2];
2631 resultArray[0] = mResult;
2632 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002633
2634 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002635 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002636 }
2637
Wink Saville9de0f752013-10-22 19:04:03 -07002638 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640 }
2641
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002642 /**
2643 * This method has been removed due to privacy and stability concerns.
2644 */
2645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002647 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2648 return;
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Nathan Harold1f889d82020-06-04 17:05:26 -07002651 @Override
2652 public void updateServiceLocationWithPackageName(String callingPackage) {
2653 mApp.getSystemService(AppOpsManager.class)
2654 .checkPackage(Binder.getCallingUid(), callingPackage);
2655
Nathan Haroldf096d982020-11-18 17:18:06 -08002656 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002657 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2658 // Callers targeting S have no business invoking this method.
2659 return;
2660 }
2661
2662 LocationAccessPolicy.LocationPermissionResult locationResult =
2663 LocationAccessPolicy.checkLocationPermission(mApp,
2664 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2665 .setCallingPackage(callingPackage)
2666 .setCallingFeatureId(null)
2667 .setCallingPid(Binder.getCallingPid())
2668 .setCallingUid(Binder.getCallingUid())
2669 .setMethod("updateServiceLocation")
2670 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2671 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2672 .build());
2673 // Apps that lack location permission have no business calling this method;
2674 // however, because no permission was declared in the public API, denials must
2675 // all be "soft".
2676 switch (locationResult) {
2677 case DENIED_HARD: /* fall through */
2678 case DENIED_SOFT:
2679 return;
2680 }
2681
2682 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002685 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002687 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 }
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002694 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002695 @Override
2696 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002697 return isRadioOnWithFeature(callingPackage, null);
2698 }
2699
2700
2701 @Override
2702 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2703 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2704 callingFeatureId);
2705 }
2706
2707 @Deprecated
2708 @Override
2709 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2710 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002714 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2715 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002716 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002717 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002718 return false;
2719 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720
2721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 return isRadioOnForSubscriber(subId);
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
2726 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002727 }
2728
2729 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null) {
2734 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2735 } else {
2736 return false;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
Wink Saville36469e72014-06-11 15:17:00 -07002746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone != null) {
2754 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Wink Saville36469e72014-06-11 15:17:00 -07002759 }
2760
2761 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002762 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002763 }
2764
Wink Savilleb564aae2014-10-23 10:18:09 -07002765 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002766 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone == null) {
2772 return false;
2773 }
2774 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2775 toggleRadioOnOffForSubscriber(subId);
2776 }
2777 return true;
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
Wink Saville36469e72014-06-11 15:17:00 -07002782
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002783 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002784 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002785 /*
2786 * If any of the Radios are available, it will need to be
2787 * shutdown. So return true if any Radio is available.
2788 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2792 Phone phone = PhoneFactory.getPhone(i);
2793 if (phone != null && phone.isRadioAvailable()) return true;
2794 }
2795 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2796 return false;
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002799 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002800 }
2801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002803 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 enforceModifyPermission();
2805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2809 logv("Shutting down Phone " + i);
2810 shutdownRadioUsingPhoneId(i);
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002814 }
2815 }
2816
2817 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002818 Phone phone = PhoneFactory.getPhone(phoneId);
2819 if (phone != null && phone.isRadioAvailable()) {
2820 phone.shutdownRadio();
2821 }
2822 }
2823
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002825 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826
2827 final long identity = Binder.clearCallingIdentity();
2828 try {
2829 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2830 if (defaultPhone != null) {
2831 defaultPhone.setRadioPower(turnOn);
2832 return true;
2833 } else {
2834 loge("There's no default phone.");
2835 return false;
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002839 }
Wink Saville36469e72014-06-11 15:17:00 -07002840 }
2841
Wink Savilleb564aae2014-10-23 10:18:09 -07002842 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 final Phone phone = getPhone(subId);
2848 if (phone != null) {
2849 phone.setRadioPower(turnOn);
2850 return true;
2851 } else {
2852 return false;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
Wink Saville36469e72014-06-11 15:17:00 -07002859 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002861 public boolean enableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
2864 final long identity = Binder.clearCallingIdentity();
2865 try {
Jack Yudf049d72022-12-02 22:48:35 -08002866 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002869 phone.getDataSettingsManager().setDataEnabled(
2870 TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 return true;
2872 } else {
2873 return false;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
Wink Saville36469e72014-06-11 15:17:00 -07002880 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07002882 public boolean disableDataConnectivity(String callingPackage) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884
2885 final long identity = Binder.clearCallingIdentity();
2886 try {
Jack Yudf049d72022-12-02 22:48:35 -08002887 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002888 final Phone phone = getPhone(subId);
2889 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07002890 phone.getDataSettingsManager().setDataEnabled(
2891 TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return true;
2893 } else {
2894 return false;
2895 }
2896 } finally {
2897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002898 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 }
2900
Sanket Padawe356d7632015-06-22 14:03:32 -07002901 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002902 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 final Phone phone = getPhone(subId);
2906 if (phone != null) {
Jack Yu59824e12022-03-23 01:42:44 -07002907 return phone.isDataAllowed();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 } else {
2909 return false;
2910 }
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915
2916 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002917 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002918 }
2919
pkanwarae03a6b2016-11-06 20:37:09 -08002920 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 enforceCallPermission();
2922
2923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2926 return;
2927 }
2928 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2929 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
pkanwar32d516d2016-10-14 19:37:38 -07002933 };
2934
Wink Savilleb564aae2014-10-23 10:18:09 -07002935 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937
2938 final long identity = Binder.clearCallingIdentity();
2939 try {
2940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2941 return false;
2942 }
2943 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002949 /**
2950 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2951 * tag on getCallState Binder call.
2952 */
2953 @Deprecated
2954 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002956 if (CompatChanges.isChangeEnabled(
2957 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2958 Binder.getCallingUid())) {
2959 // Do not allow this API to be called on API version 31+, it should only be
2960 // called on old apps using this Binder call directly.
2961 throw new SecurityException("This method can only be used for applications "
2962 + "targeting API version 30 or less.");
2963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964 final long identity = Binder.clearCallingIdentity();
2965 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002966 Phone phone = getPhone(getDefaultSubscription());
2967 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2968 PhoneConstantConversions.convertCallState(phone.getState());
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
2972 }
2973
2974 @Override
2975 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2976 if (CompatChanges.isChangeEnabled(
2977 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2978 Binder.getCallingUid())) {
2979 // Check READ_PHONE_STATE for API version 31+
2980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2981 featureId, "getCallStateForSubscription")) {
2982 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2983 + "targeting API level 31+.");
2984 }
2985 }
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2990 PhoneConstantConversions.convertCallState(phone.getState());
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 }
2995
Sanket Padawe356d7632015-06-22 14:03:32 -07002996 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002997 public int getDataState() {
Jack Yudf049d72022-12-02 22:48:35 -08002998 return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07002999 }
3000
3001 @Override
3002 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003003 final long identity = Binder.clearCallingIdentity();
3004 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003005 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006 if (phone != null) {
Jack Yuabb10902022-07-31 00:43:21 -07003007 return phone.getDataNetworkController().getInternetDataNetworkState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008 } else {
3009 return PhoneConstantConversions.convertDataState(
3010 PhoneConstants.DataState.DISCONNECTED);
3011 }
3012 } finally {
3013 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003014 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 }
3016
Sanket Padawe356d7632015-06-22 14:03:32 -07003017 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003018 public @DataActivityType int getDataActivity() {
Jack Yudf049d72022-12-02 22:48:35 -08003019 return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId());
Nathan Haroldc4689b12019-06-14 16:58:30 -07003020 }
3021
3022 @Override
Jack Yu0eda6842022-04-18 00:34:46 -07003023 public @DataActivityType int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 final long identity = Binder.clearCallingIdentity();
3025 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07003026 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027 if (phone != null) {
Jack Yu0eda6842022-04-18 00:34:46 -07003028 return phone.getDataActivityState();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 } else {
3030 return TelephonyManager.DATA_ACTIVITY_NONE;
3031 }
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003034 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036
3037 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08003038 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003039 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003040 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003041
3042 LocationAccessPolicy.LocationPermissionResult locationResult =
3043 LocationAccessPolicy.checkLocationPermission(mApp,
3044 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3045 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003046 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003047 .setCallingPid(Binder.getCallingPid())
3048 .setCallingUid(Binder.getCallingUid())
3049 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08003050 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003051 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3052 .build());
3053 switch (locationResult) {
3054 case DENIED_HARD:
3055 throw new SecurityException("Not allowed to access cell location");
3056 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08003057 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
3058 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003061 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 if (DBG_LOC) log("getCellLocation: is active user");
Jack Yudf049d72022-12-02 22:48:35 -08003065 int subId = SubscriptionManager.getDefaultDataSubscriptionId();
Meng Wanga10e89e2019-12-09 13:13:01 -08003066 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067 } finally {
3068 Binder.restoreCallingIdentity(identity);
3069 }
Svetoslav64fad262015-04-14 14:35:21 -07003070 }
3071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003072 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08003073 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003074 // Reporting the correct network country is ambiguous when IWLAN could conflict with
3075 // registered cell info, so return a NULL country instead.
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07003078 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
3079 // Get default phone in this case.
3080 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
3081 }
Jack Yudf049d72022-12-02 22:48:35 -08003082 final int subId = SubscriptionManager.getSubscriptionId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003084 if (phone == null) return "";
3085 ServiceStateTracker sst = phone.getServiceStateTracker();
3086 if (sst == null) return "";
3087 LocaleTracker lt = sst.getLocaleTracker();
3088 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003089 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003093 }
3094
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003095 /**
3096 * This method was removed due to potential issues caused by performing partial
3097 * updates of service state, and lack of a credible use case.
3098 *
3099 * This has the ability to break the telephony implementation by disabling notification of
3100 * changes in device connectivity. DO NOT USE THIS!
3101 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003102 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 public void enableLocationUpdates() {
3104 mApp.enforceCallingOrSelfPermission(
3105 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003106 }
3107
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003108 /**
3109 * This method was removed due to potential issues caused by performing partial
3110 * updates of service state, and lack of a credible use case.
3111 *
3112 * This has the ability to break the telephony implementation by disabling notification of
3113 * changes in device connectivity. DO NOT USE THIS!
3114 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003115 @Override
3116 public void disableLocationUpdates() {
3117 mApp.enforceCallingOrSelfPermission(
3118 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003119 }
3120
3121 @Override
3122 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003123 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3124 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003125 try {
3126 mApp.getSystemService(AppOpsManager.class)
3127 .checkPackage(Binder.getCallingUid(), callingPackage);
3128 } catch (SecurityException e) {
3129 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3130 throw e;
3131 }
3132
Nathan Haroldf096d982020-11-18 17:18:06 -08003133 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003134 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3135 throw new SecurityException(
3136 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3137 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003138
Jordan Liu1617b712019-07-10 15:06:26 -07003139 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3141 return null;
3142 }
Svetoslav64fad262015-04-14 14:35:21 -07003143
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003144 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003145
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003146 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003147 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003148
Nathan Haroldf180aac2018-06-01 18:43:55 -07003149 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3150 for (CellInfo ci : info) {
3151 if (ci instanceof CellInfoGsm) {
3152 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3153 } else if (ci instanceof CellInfoWcdma) {
3154 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003157 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003160 private List<CellInfo> getCachedCellInfo() {
3161 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3162 for (Phone phone : PhoneFactory.getPhones()) {
3163 List<CellInfo> info = phone.getAllCellInfo();
3164 if (info != null) cellInfos.addAll(info);
3165 }
3166 return cellInfos;
3167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168
3169 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003170 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003171 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003172 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003173
3174 LocationAccessPolicy.LocationPermissionResult locationResult =
3175 LocationAccessPolicy.checkLocationPermission(mApp,
3176 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3177 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003178 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003179 .setCallingPid(Binder.getCallingPid())
3180 .setCallingUid(Binder.getCallingUid())
3181 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003182 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003183 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3184 .build());
3185 switch (locationResult) {
3186 case DENIED_HARD:
3187 throw new SecurityException("Not allowed to access cell info");
3188 case DENIED_SOFT:
3189 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Nathan Haroldf096d982020-11-18 17:18:06 -08003192 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003193 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3194 return getCachedCellInfo();
3195 }
3196
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003197 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003198 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3202 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003203 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003204 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205 if (info != null) cellInfos.addAll(info);
3206 }
3207 return cellInfos;
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 }
3211 }
3212
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003213 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003214 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3215 String callingFeatureId) {
3216 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3217 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003218 }
3219
3220 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003221 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3222 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003223 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003224 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003225 }
3226
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003227 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3228 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003229 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003230 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003231
3232 LocationAccessPolicy.LocationPermissionResult locationResult =
3233 LocationAccessPolicy.checkLocationPermission(mApp,
3234 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3235 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003236 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003237 .setCallingPid(Binder.getCallingPid())
3238 .setCallingUid(Binder.getCallingUid())
3239 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003240 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3241 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003242 .build());
3243 switch (locationResult) {
3244 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003245 if (TelephonyPermissions
3246 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003247 // Safetynet logging for b/154934934
3248 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3249 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003250 throw new SecurityException("Not allowed to access cell info");
3251 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003252 if (TelephonyPermissions
3253 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003254 // Safetynet logging for b/154934934
3255 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3256 }
Nathan Harold5320c422019-05-09 10:26:08 -07003257 try {
3258 cb.onCellInfo(new ArrayList<CellInfo>());
3259 } catch (RemoteException re) {
3260 // Drop without consequences
3261 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003262 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003263 }
3264
Nathan Harolda939a962019-05-09 10:13:47 -07003265
3266 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003267 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3268
3269 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3270 }
3271
3272 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003274 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003276
3277 final long identity = Binder.clearCallingIdentity();
3278 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 }
3284
Shishir Agrawala9f32182016-04-12 12:00:16 -07003285 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003286 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 Phone phone = PhoneFactory.getPhone(slotIndex);
3288 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 return null;
3290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003291 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003292 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003293 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003294 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003295 return null;
3296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 return phone.getImei();
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003304 }
3305
3306 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003307 public String getTypeAllocationCodeForSlot(int slotIndex) {
3308 Phone phone = PhoneFactory.getPhone(slotIndex);
3309 String tac = null;
3310 if (phone != null) {
3311 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003312 try {
3313 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3314 } catch (IndexOutOfBoundsException e) {
3315 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3316 return null;
3317 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003318 }
3319 return tac;
3320 }
3321
3322 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003323 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003324 try {
3325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3326 } catch (SecurityException se) {
3327 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3328 throw new SecurityException("Package " + callingPackage + " does not belong to "
3329 + Binder.getCallingUid());
3330 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003331 Phone phone = PhoneFactory.getPhone(slotIndex);
3332 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003333 return null;
3334 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335
Jeff Davidson913390f2018-02-23 17:11:49 -08003336 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003337 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003338 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003339 return null;
3340 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 return phone.getMeid();
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
Jack Yu2af8d712017-03-15 17:14:14 -07003348 }
3349
3350 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003351 public String getManufacturerCodeForSlot(int slotIndex) {
3352 Phone phone = PhoneFactory.getPhone(slotIndex);
3353 String manufacturerCode = null;
3354 if (phone != null) {
3355 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003356 try {
3357 manufacturerCode =
3358 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3359 } catch (IndexOutOfBoundsException e) {
3360 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3361 return null;
3362 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003363 }
3364 return manufacturerCode;
3365 }
3366
3367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003368 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3369 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003370 Phone phone = PhoneFactory.getPhone(slotIndex);
3371 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003372 return null;
3373 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003374 int subId = phone.getSubId();
3375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003376 mApp, subId, callingPackage, callingFeatureId,
3377 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003378 return null;
3379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 return phone.getDeviceSvn();
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003387 }
3388
fionaxu43304da2017-11-27 22:51:16 -08003389 @Override
3390 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
3393 final Phone phone = getPhone(subId);
3394 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
fionaxu43304da2017-11-27 22:51:16 -08003398 }
3399
3400 @Override
3401 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 final Phone phone = getPhone(subId);
3405 return phone == null ? null : phone.getCarrierName();
3406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
fionaxu43304da2017-11-27 22:51:16 -08003409 }
3410
calvinpanffe225e2018-11-01 19:43:06 +08003411 @Override
chen xu0026ca62019-03-06 15:28:50 -08003412 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003413 final long identity = Binder.clearCallingIdentity();
3414 try {
3415 final Phone phone = getPhone(subId);
3416 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003417 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003418 } finally {
3419 Binder.restoreCallingIdentity(identity);
3420 }
3421 }
3422
3423 @Override
chen xu0026ca62019-03-06 15:28:50 -08003424 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003428 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
chen xu651eec72018-11-11 19:03:44 -08003434 @Override
chen xu864e11c2018-12-06 22:10:03 -08003435 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3436 if (!isSubscriptionMccMnc) {
3437 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3438 }
chen xu651eec72018-11-11 19:03:44 -08003439 final Phone phone = PhoneFactory.getPhone(slotIndex);
3440 if (phone == null) {
3441 return TelephonyManager.UNKNOWN_CARRIER_ID;
3442 }
3443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3446 } finally {
3447 Binder.restoreCallingIdentity(identity);
3448 }
3449 }
3450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 //
3452 // Internal helper methods.
3453 //
3454
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003455 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003456 * Make sure the caller is the calling package itself
3457 *
3458 * @throws SecurityException if the caller is not the calling package
3459 */
3460 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3461 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003462 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3463 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003464 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003465 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003466 } catch (PackageManager.NameNotFoundException e) {
3467 // packageUid is -1
3468 }
3469 if (packageUid != callingUid) {
3470 throw new SecurityException(message + ": Package " + callingPackage
3471 + " does not belong to " + callingUid);
3472 }
3473 }
3474
3475 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3477 *
3478 * @throws SecurityException if the caller does not have the required permission
3479 */
3480 private void enforceModifyPermission() {
3481 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3482 }
3483
Shuo Qian3b6ee772019-11-13 17:43:31 -08003484 private void enforceActiveEmergencySessionPermission() {
3485 mApp.enforceCallingOrSelfPermission(
3486 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3487 }
3488
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 /**
3490 * Make sure the caller has the CALL_PHONE permission.
3491 *
3492 * @throws SecurityException if the caller does not have the required permission
3493 */
3494 private void enforceCallPermission() {
3495 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3496 }
3497
paulhu5a773602019-08-23 19:17:33 +08003498 private void enforceSettingsPermission() {
3499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003500 }
3501
Michele Berionne5e411512020-11-13 02:36:59 +00003502 private void enforceRebootPermission() {
3503 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3504 }
3505
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 private String createTelUrl(String number) {
3507 if (TextUtils.isEmpty(number)) {
3508 return null;
3509 }
3510
Jake Hambye994d462014-02-03 13:10:13 -08003511 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003512 }
3513
Ihab Awadf9e92732013-12-05 18:02:52 -08003514 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003515 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3516 }
3517
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003518 private static void logv(String msg) {
3519 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3520 }
3521
Ihab Awadf9e92732013-12-05 18:02:52 -08003522 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3524 }
3525
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003527 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003528 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003529 }
3530
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003532 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = PhoneFactory.getPhone(slotIndex);
3536 if (phone == null) {
3537 return PhoneConstants.PHONE_TYPE_NONE;
3538 } else {
3539 return phone.getPhoneType();
3540 }
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
3545
3546 /**
3547 * Returns the CDMA ERI icon index to display
3548 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003550 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3551 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3552 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003553 }
3554
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003556 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3557 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003559 mApp, subId, callingPackage, callingFeatureId,
3560 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 return -1;
3562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
3567 if (phone != null) {
3568 return phone.getCdmaEriIconIndex();
3569 } else {
3570 return -1;
3571 }
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 }
3576
3577 /**
3578 * Returns the CDMA ERI icon mode,
3579 * 0 - ON
3580 * 1 - FLASHING
3581 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003583 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3584 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3585 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003586 }
3587
Sanket Padawe356d7632015-06-22 14:03:32 -07003588 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003589 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3590 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003592 mApp, subId, callingPackage, callingFeatureId,
3593 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003594 return -1;
3595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 final Phone phone = getPhone(subId);
3600 if (phone != null) {
3601 return phone.getCdmaEriIconMode();
3602 } else {
3603 return -1;
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003608 }
3609
3610 /**
3611 * Returns the CDMA ERI text,
3612 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003614 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3615 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3616 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003617 }
3618
Sanket Padawe356d7632015-06-22 14:03:32 -07003619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003620 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3621 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003623 mApp, subId, callingPackage, callingFeatureId,
3624 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003625 return null;
3626 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 final Phone phone = getPhone(subId);
3631 if (phone != null) {
3632 return phone.getCdmaEriText();
3633 } else {
3634 return null;
3635 }
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 }
3640
3641 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003642 * Returns the CDMA MDN.
3643 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003644 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003645 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3647 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 return phone.getLine1Number();
3654 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003656 return null;
3657 }
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003660 }
3661 }
3662
3663 /**
3664 * Returns the CDMA MIN.
3665 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003666 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003667 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3669 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 final Phone phone = getPhone(subId);
3674 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3675 return phone.getCdmaMin();
3676 } else {
3677 return null;
3678 }
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003681 }
3682 }
3683
Hall Liud892bec2018-11-30 14:51:45 -08003684 @Override
3685 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3686 INumberVerificationCallback callback, String callingPackage) {
3687 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3688 != PERMISSION_GRANTED) {
3689 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3690 }
3691 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3692
3693 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3694 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003695 throw new SecurityException("Calling package must be configured in the device config: "
3696 + "calling package: " + callingPackage
3697 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003698 }
3699
3700 if (range == null) {
3701 throw new NullPointerException("Range must be non-null");
3702 }
3703
3704 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003705 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003706
3707 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3708 }
3709
Junda Liuca05d5d2014-08-14 22:36:34 -07003710 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003711 * Returns true if CDMA provisioning needs to run.
3712 */
3713 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 final long identity = Binder.clearCallingIdentity();
3715 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003720 }
3721
3722 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003723 * Sets the voice mail number of a given subId.
3724 */
3725 @Override
3726 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003727 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3728 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
3732 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3733 new Pair<String, String>(alphaTag, number), new Integer(subId));
3734 return success;
3735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003738 }
3739
Ta-wei Yen87c49842016-05-13 21:19:52 -07003740 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003741 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003743 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3744 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003745 if (!TextUtils.equals(callingPackage, systemDialer)) {
3746 throw new SecurityException("caller must be system dialer");
3747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748
3749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3752 if (phoneAccountHandle == null) {
3753 return null;
3754 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003758 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003759 }
3760
3761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003762 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3763 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003764 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003766 mApp, subId, callingPackage, callingFeatureId,
3767 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003768 return null;
3769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003771 final long identity = Binder.clearCallingIdentity();
3772 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003774 } finally {
3775 Binder.restoreCallingIdentity(identity);
3776 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003777 }
3778
3779 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003780 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3781 VisualVoicemailSmsFilterSettings settings) {
3782 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003783
3784 final long identity = Binder.clearCallingIdentity();
3785 try {
3786 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003791 }
3792
3793 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003794 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 } finally {
3802 Binder.restoreCallingIdentity(identity);
3803 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003804 }
3805
3806 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003807 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3808 String callingPackage, int subId) {
3809 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810
3811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003814 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 } finally {
3816 Binder.restoreCallingIdentity(identity);
3817 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003818 }
3819
3820 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003821 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823
3824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003827 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003831 }
3832
3833 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003834 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3835 String callingAttributionTag, int subId, String number, int port, String text,
3836 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003838 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003839 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003840 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003841 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3842 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003843 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003844
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003845 /**
fionaxu0152e512016-11-14 13:36:14 -08003846 * Sets the voice activation state of a given subId.
3847 */
3848 @Override
3849 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3851 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 final Phone phone = getPhone(subId);
3856 if (phone != null) {
3857 phone.setVoiceActivationState(activationState);
3858 } else {
3859 loge("setVoiceActivationState fails with invalid subId: " + subId);
3860 }
3861 } finally {
3862 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003863 }
3864 }
3865
3866 /**
3867 * Sets the data activation state of a given subId.
3868 */
3869 @Override
3870 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3872 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003873
3874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = getPhone(subId);
3877 if (phone != null) {
3878 phone.setDataActivationState(activationState);
3879 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003880 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 }
3882 } finally {
3883 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003884 }
3885 }
3886
3887 /**
3888 * Returns the voice activation state of a given subId.
3889 */
3890 @Override
3891 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893
fionaxu0152e512016-11-14 13:36:14 -08003894 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 if (phone != null) {
3898 return phone.getVoiceActivationState();
3899 } else {
3900 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3901 }
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003904 }
3905 }
3906
3907 /**
3908 * Returns the data activation state of a given subId.
3909 */
3910 @Override
3911 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913
fionaxu0152e512016-11-14 13:36:14 -08003914 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 if (phone != null) {
3918 return phone.getDataActivationState();
3919 } else {
3920 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3921 }
3922 } finally {
3923 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003924 }
3925 }
3926
3927 /**
Wink Saville36469e72014-06-11 15:17:00 -07003928 * Returns the unread count of voicemails for a subId
3929 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003930 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003931 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3932 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003934 mApp, subId, callingPackage, callingFeatureId,
3935 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003936 return 0;
3937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 final Phone phone = getPhone(subId);
3941 if (phone != null) {
3942 return phone.getVoiceMessageCount();
3943 } else {
3944 return 0;
3945 }
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003949 }
3950
3951 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003952 * returns true, if the device is in a state where both voice and data
3953 * are supported simultaneously. This can change based on location or network condition.
3954 */
3955 @Override
3956 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 final long identity = Binder.clearCallingIdentity();
3958 try {
3959 final Phone phone = getPhone(subId);
3960 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003964 }
3965
3966 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003967 * Send the dialer code if called from the current default dialer or the caller has
3968 * carrier privilege.
3969 * @param inputCode The dialer code to send
3970 */
3971 @Override
3972 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003973 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003974 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003975 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3976 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003977 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003979 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003981
3982 final long identity = Binder.clearCallingIdentity();
3983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003984 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
fionaxu235cc5e2017-03-06 22:25:57 -08003988 }
3989
Pengquan Menga1bb6272018-09-06 09:59:22 -07003990 @Override
3991 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003992 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003993 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003994 mApp, subId, "getNetworkSelectionMode");
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 if (!isActiveSubscription(subId)) {
3998 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3999 }
4000 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
4001 } finally {
4002 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07004003 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07004004 }
4005
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07004007 public boolean isInEmergencySmsMode() {
4008 enforceReadPrivilegedPermission("isInEmergencySmsMode");
4009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 for (Phone phone : PhoneFactory.getPhones()) {
4012 if (phone.isInEmergencySmsMode()) {
4013 return true;
4014 }
4015 }
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
4019 return false;
4020 }
4021
shilu366312e2019-12-17 09:28:10 -08004022 /**
4023 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4024 * @param subId The subscription to use to check the configuration.
4025 * @param c The callback that will be used to send the result.
4026 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07004027 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004028 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
4029 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004030 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004031 mApp, subId, "registerImsRegistrationCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004032
4033 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4034 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4035 "IMS not available on device.");
4036 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 final long token = Binder.clearCallingIdentity();
4038 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004039 int slotId = getSlotIndexOrException(subId);
4040 verifyImsMmTelConfiguredOrThrow(slotId);
4041 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (ImsException e) {
4043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 } finally {
4045 Binder.restoreCallingIdentity(token);
4046 }
4047 }
4048
shilu366312e2019-12-17 09:28:10 -08004049 /**
4050 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4051 * @param subId The subscription to use to check the configuration.
4052 * @param c The callback that will be used to send the result.
4053 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004055 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004056 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004057 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004058 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4059 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4060 }
Meng Wangafbc5852019-09-19 17:37:13 -07004061 final long token = Binder.clearCallingIdentity();
4062 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004063 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4064 .removeRegistrationCallbackForSubscription(c, subId);
4065 } catch (ImsException e) {
4066 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
4067 + "is inactive, ignoring unregister.");
4068 // If the subscription is no longer active, just return, since the callback
4069 // will already have been removed internally.
4070 } finally {
4071 Binder.restoreCallingIdentity(token);
4072 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 }
4074
Brad Ebingera34a6c22019-10-22 17:36:18 -07004075 /**
4076 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4077 */
4078 @Override
4079 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4080 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4081 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4082 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4083 "IMS not available on device.");
4084 }
4085 final long token = Binder.clearCallingIdentity();
4086 try {
4087 Phone phone = getPhone(subId);
4088 if (phone == null) {
4089 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4090 + subId + "'");
4091 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4092 }
4093 phone.getImsRegistrationState(regState -> {
4094 try {
4095 consumer.accept((regState == null)
4096 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4097 } catch (RemoteException e) {
4098 // Ignore if the remote process is no longer available to call back.
4099 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4100 }
4101 });
4102 } finally {
4103 Binder.restoreCallingIdentity(token);
4104 }
4105 }
4106
4107 /**
4108 * Get the transport type for the IMS service registration state.
4109 */
4110 @Override
4111 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004112 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004113 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004114 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4115 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4116 "IMS not available on device.");
4117 }
4118 final long token = Binder.clearCallingIdentity();
4119 try {
4120 Phone phone = getPhone(subId);
4121 if (phone == null) {
4122 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4123 + subId + "'");
4124 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4125 }
4126 phone.getImsRegistrationTech(regTech -> {
4127 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4128 int regTechConverted = (regTech == null)
4129 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4130 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4131 regTechConverted);
4132 try {
4133 consumer.accept(regTechConverted);
4134 } catch (RemoteException e) {
4135 // Ignore if the remote process is no longer available to call back.
4136 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4137 }
4138 });
4139 } finally {
4140 Binder.restoreCallingIdentity(token);
4141 }
4142 }
4143
shilu366312e2019-12-17 09:28:10 -08004144 /**
4145 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4146 * @param subId The subscription to use to check the configuration.
4147 * @param c The callback that will be used to send the result.
4148 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004150 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4151 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004152 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004153 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingera2628302022-02-18 03:44:55 +00004154 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4155 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4156 "IMS not available on device.");
4157 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 final long token = Binder.clearCallingIdentity();
4159 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004160 int slotId = getSlotIndexOrException(subId);
4161 verifyImsMmTelConfiguredOrThrow(slotId);
4162 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004163 } catch (ImsException e) {
4164 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 } finally {
4166 Binder.restoreCallingIdentity(token);
4167 }
4168 }
4169
shilu366312e2019-12-17 09:28:10 -08004170 /**
4171 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4172 * @param subId The subscription to use to check the configuration.
4173 * @param c The callback that will be used to send the result.
4174 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004176 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004177 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004178 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004179 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4180 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4181 }
Meng Wangafbc5852019-09-19 17:37:13 -07004182
4183 final long token = Binder.clearCallingIdentity();
4184 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004185 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004186 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004187 } catch (ImsException e) {
4188 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4189 + "is inactive, ignoring unregister.");
4190 // If the subscription is no longer active, just return, since the callback
4191 // will already have been removed internally.
4192 } finally {
4193 Binder.restoreCallingIdentity(token);
4194 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 }
4196
4197 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004198 public boolean isCapable(int subId, int capability, int regTech) {
4199 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 final long token = Binder.clearCallingIdentity();
4201 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004202 int slotId = getSlotIndexOrException(subId);
4203 verifyImsMmTelConfiguredOrThrow(slotId);
4204 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
4205 } catch (com.android.ims.ImsException e) {
4206 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4207 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004209 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4210 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 } finally {
4212 Binder.restoreCallingIdentity(token);
4213 }
4214 }
4215
4216 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004217 public boolean isAvailable(int subId, int capability, int regTech) {
4218 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 final long token = Binder.clearCallingIdentity();
4220 try {
4221 Phone phone = getPhone(subId);
4222 if (phone == null) return false;
4223 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004224 } catch (com.android.ims.ImsException e) {
4225 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4226 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(token);
4229 }
4230 }
4231
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004232 /**
4233 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4234 * subscription.
4235 * @param subId The subscription to use to check the configuration.
4236 * @param callback The callback that will be used to send the result.
4237 * @param capability The MmTelFeature capability that will be used to send the result.
4238 * @param transportType The transport type of the MmTelFeature capability.
4239 */
4240 @Override
4241 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4242 int transportType) {
4243 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
Brad Ebingera2628302022-02-18 03:44:55 +00004244 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4245 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4246 "IMS not available on device.");
4247 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004248 final long token = Binder.clearCallingIdentity();
4249 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004250 int slotId = getSlotIndex(subId);
4251 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4252 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4253 + subId + "'");
4254 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4255 }
4256 verifyImsMmTelConfiguredOrThrow(slotId);
4257 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4258 transportType, aBoolean -> {
4259 try {
4260 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4261 } catch (RemoteException e) {
4262 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4263 + "running. Ignore");
4264 }
4265 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004266 } catch (ImsException e) {
4267 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004268 } finally {
4269 Binder.restoreCallingIdentity(token);
4270 }
4271 }
4272
shilu366312e2019-12-17 09:28:10 -08004273 /**
4274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4275 * @param subId The subscription to use to check the configuration.
4276 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004277 @Override
4278 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004279 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004280 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004281
Brad Ebinger35c841c2018-10-01 10:40:55 -07004282 final long token = Binder.clearCallingIdentity();
4283 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004284 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004285 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004287 } catch (ImsException e) {
4288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 } finally {
4290 Binder.restoreCallingIdentity(token);
4291 }
4292 }
4293
4294 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004295 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 final long identity = Binder.clearCallingIdentity();
4299 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004301 // This setting doesn't require an active ImsService connection, so do not verify. The
4302 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004303 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004304 } catch (ImsException e) {
4305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
4309 }
4310
shilu366312e2019-12-17 09:28:10 -08004311 /**
4312 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4313 * @param subId The subscription to use to check the configuration.
4314 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004316 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004317 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004318 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 final long identity = Binder.clearCallingIdentity();
4320 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004322 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004332 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004334 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 final long identity = Binder.clearCallingIdentity();
4336 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004337 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004338 // This setting doesn't require an active ImsService connection, so do not verify. The
4339 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004340 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004341 } catch (ImsException e) {
4342 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
shilu366312e2019-12-17 09:28:10 -08004348 /**
4349 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4350 * @param subId The subscription to use to check the configuration.
4351 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 @Override
4353 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004354 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004355 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004369 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting doesn't require an active ImsService connection, so do not verify. The
4376 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
4379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
shilu366312e2019-12-17 09:28:10 -08004385 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004386 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4387 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4388 * @param subId The subscription to use to check the configuration.
4389 */
4390 @Override
4391 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004392 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004393 mApp, subId, "isCrossSimCallingEnabledByUser");
4394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004396 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004397 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004399 } catch (ImsException e) {
4400 throw new ServiceSpecificException(e.getCode());
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 /**
4407 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4408 * Requires MODIFY_PHONE_STATE permission.
4409 * @param subId The subscription to use to check the configuration.
4410 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4411 * false otherwise
4412 */
4413 @Override
4414 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4416 "setCrossSimCallingEnabled");
4417 final long identity = Binder.clearCallingIdentity();
4418 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004420 // This setting doesn't require an active ImsService connection, so do not verify. The
4421 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004423 } catch (ImsException e) {
4424 throw new ServiceSpecificException(e.getCode());
4425 } finally {
4426 Binder.restoreCallingIdentity(identity);
4427 }
4428 }
4429
4430 /**
shilu366312e2019-12-17 09:28:10 -08004431 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4432 * @param subId The subscription to use to check the configuration.
4433 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004434 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004435
Brad Ebinger35c841c2018-10-01 10:40:55 -07004436 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004437 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004438 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 final long identity = Binder.clearCallingIdentity();
4440 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004442 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004444 } catch (ImsException e) {
4445 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
4449 }
4450
4451 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004452 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004454 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 final long identity = Binder.clearCallingIdentity();
4456 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004457 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004458 // This setting doesn't require an active ImsService connection, so do not verify. The
4459 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004461 } catch (ImsException e) {
4462 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
4469 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4471 "setVoWiFiNonPersistent");
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004474 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004475 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004477 } catch (ImsException e) {
4478 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483
shilu366312e2019-12-17 09:28:10 -08004484 /**
4485 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4486 * @param subId The subscription to use to check the configuration.
4487 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 @Override
4489 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004490 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004491 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004494 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004495 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004496 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004497 } catch (ImsException e) {
4498 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
4502 }
4503
4504 @Override
4505 public void setVoWiFiModeSetting(int subId, int mode) {
4506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4507 "setVoWiFiModeSetting");
4508 final long identity = Binder.clearCallingIdentity();
4509 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004511 // This setting doesn't require an active ImsService connection, so do not verify. The
4512 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004513 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (ImsException e) {
4515 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 }
4520
4521 @Override
4522 public int getVoWiFiRoamingModeSetting(int subId) {
4523 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4524 final long identity = Binder.clearCallingIdentity();
4525 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004526 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004527 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004528 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004529 } catch (ImsException e) {
4530 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
4534 }
4535
4536 @Override
4537 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4539 "setVoWiFiRoamingModeSetting");
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004542 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004543 // This setting doesn't require an active ImsService connection, so do not verify. The
4544 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004545 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004546 } catch (ImsException e) {
4547 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
4551 }
4552
4553 @Override
4554 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4556 "setRttCapabilityEnabled");
4557 final long identity = Binder.clearCallingIdentity();
4558 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004559 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004560 // This setting doesn't require an active ImsService connection, so do not verify. The
4561 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004562 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004563 } catch (ImsException e) {
4564 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
4568 }
4569
shilu366312e2019-12-17 09:28:10 -08004570 /**
4571 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4572 * @param subId The subscription to use to check the configuration.
4573 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004574 @Override
4575 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004576 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004577 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004578 final long identity = Binder.clearCallingIdentity();
4579 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004580 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004581 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004582 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004583 } catch (ImsException e) {
4584 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
4588 }
4589
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004590 @Override
4591 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4592 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004593
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004594 final long identity = Binder.clearCallingIdentity();
4595 try {
Brad Ebingera2628302022-02-18 03:44:55 +00004596 if (!isImsAvailableOnDevice()) {
4597 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4598 "IMS not available on device.");
4599 }
4600 int slotId = getSlotIndexOrException(subId);
4601 verifyImsMmTelConfiguredOrThrow(slotId);
4602 ImsManager.getInstance(mApp, slotId)
4603 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (ImsException e) {
4605 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 } finally {
4607 Binder.restoreCallingIdentity(identity);
4608 }
4609 }
4610
4611 @Override
4612 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4613 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
joonhunshincffb7fc2021-11-28 07:32:01 +00004614
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004615 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4617 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4618 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004619 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004620 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004621 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004622 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004623 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4624 + "is inactive, ignoring unregister.");
4625 // If the subscription is no longer active, just return, since the callback will already
4626 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
joonhunshincffb7fc2021-11-28 07:32:01 +00004632 @Override
4633 public void registerFeatureProvisioningChangedCallback(int subId,
4634 IFeatureProvisioningCallback callback) {
4635 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4636 mApp, subId, "registerFeatureProvisioningChangedCallback");
4637
4638 final long identity = Binder.clearCallingIdentity();
4639 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4640 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4641 }
4642
joonhunshin91bc1952022-04-29 08:47:15 +00004643 try {
4644 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4645 if (controller == null) {
4646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4647 "Device does not support IMS");
4648 }
4649 controller.addFeatureProvisioningChangedCallback(subId, callback);
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004653 }
4654
4655 @Override
4656 public void unregisterFeatureProvisioningChangedCallback(int subId,
4657 IFeatureProvisioningCallback callback) {
4658 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4659 mApp, subId, "unregisterFeatureProvisioningChangedCallback");
4660
4661 final long identity = Binder.clearCallingIdentity();
4662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4663 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4664 }
4665
joonhunshin91bc1952022-04-29 08:47:15 +00004666 try {
4667 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4668 if (controller == null) {
4669 loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS");
4670 return;
4671 }
4672 controller.removeFeatureProvisioningChangedCallback(subId, callback);
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004676 }
allenwtsu99c623b2020-01-03 18:24:23 +08004677
4678 private void checkModifyPhoneStatePermission(int subId, String message) {
4679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4680 message);
4681 }
4682
allenwtsu99c623b2020-01-03 18:24:23 +08004683 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004684 public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech,
allenwtsu99c623b2020-01-03 18:24:23 +08004685 boolean isProvisioned) {
4686 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4687
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004690 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4691 if (controller == null) {
4692 loge("setRcsProvisioningStatusForCapability: Device does not support IMS");
4693 return;
4694 }
4695 controller.setRcsProvisioningStatusForCapability(
4696 subId, capability, tech, isProvisioned);
allenwtsu99c623b2020-01-03 18:24:23 +08004697 } finally {
4698 Binder.restoreCallingIdentity(identity);
4699 }
allenwtsu99c623b2020-01-03 18:24:23 +08004700 }
4701
4702
4703 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004704 public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) {
4705 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4706 mApp, subId, "getRcsProvisioningStatusForCapability");
4707
allenwtsu99c623b2020-01-03 18:24:23 +08004708 final long identity = Binder.clearCallingIdentity();
4709 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004710 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4711 if (controller == null) {
4712 loge("getRcsProvisioningStatusForCapability: Device does not support IMS");
4713
4714 // device does not support IMS, this method will return true always.
4715 return true;
4716 }
4717 return controller.getRcsProvisioningStatusForCapability(subId, capability, tech);
allenwtsu99c623b2020-01-03 18:24:23 +08004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
4720 }
4721 }
4722
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004723 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4725 boolean isProvisioned) {
allenwtsu99c623b2020-01-03 18:24:23 +08004726 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
joonhunshincffb7fc2021-11-28 07:32:01 +00004727
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004730 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4731 if (controller == null) {
4732 loge("setImsProvisioningStatusForCapability: Device does not support IMS");
4733 return;
4734 }
4735 controller.setImsProvisioningStatusForCapability(
4736 subId, capability, tech, isProvisioned);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
4739 }
4740 }
4741
4742 @Override
4743 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
joonhunshincffb7fc2021-11-28 07:32:01 +00004744 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4745 mApp, subId, "getProvisioningStatusForCapability");
4746
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004747 final long identity = Binder.clearCallingIdentity();
4748 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004749 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4750 if (controller == null) {
4751 loge("getImsProvisioningStatusForCapability: Device does not support IMS");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752
joonhunshin91bc1952022-04-29 08:47:15 +00004753 // device does not support IMS, this method will return true always.
4754 return true;
4755 }
4756 return controller.getImsProvisioningStatusForCapability(subId, capability, tech);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004763 public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) {
4764 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4765 mApp, subId, "isProvisioningRequiredForCapability");
4766
4767 final long identity = Binder.clearCallingIdentity();
4768 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004769 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4770 if (controller == null) {
4771 loge("isProvisioningRequiredForCapability: Device does not support IMS");
4772
4773 // device does not support IMS, this method will return false
4774 return false;
4775 }
4776 return controller.isImsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004777 } finally {
4778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004779 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 }
4781
4782 @Override
joonhunshincffb7fc2021-11-28 07:32:01 +00004783 public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) {
4784 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4785 mApp, subId, "isProvisioningRequiredForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004786
joonhunshincffb7fc2021-11-28 07:32:01 +00004787 final long identity = Binder.clearCallingIdentity();
4788 try {
joonhunshin91bc1952022-04-29 08:47:15 +00004789 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4790 if (controller == null) {
4791 loge("isRcsProvisioningRequiredForCapability: Device does not support IMS");
4792
4793 // device does not support IMS, this method will return false
4794 return false;
4795 }
4796 return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech);
joonhunshincffb7fc2021-11-28 07:32:01 +00004797 } finally {
4798 Binder.restoreCallingIdentity(identity);
4799 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800 }
4801
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004802 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004803 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4805 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4806 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004807 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4808 mApp, subId, "getImsProvisioningInt");
4809
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004810 final long identity = Binder.clearCallingIdentity();
4811 try {
4812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 int slotId = getSlotIndex(subId);
4814 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4815 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4816 + subId + "' for key:" + key);
4817 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4818 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004819
joonhunshin91bc1952022-04-29 08:47:15 +00004820 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4821 if (controller == null) {
4822 loge("getImsProvisioningInt: Device does not support IMS");
4823
4824 // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN.
4825 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4826 }
4827 int retVal = controller.getProvisioningValue(subId, key);
joonhunshincffb7fc2021-11-28 07:32:01 +00004828 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4829 return retVal;
4830 }
4831
calvinpanb5a34062021-02-08 19:59:36 +08004832 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004833 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004834 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4835 + subId + "' for key:" + key);
4836 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
4840 }
4841
4842 @Override
4843 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4845 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4846 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004847 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4848 mApp, subId, "getImsProvisioningString");
4849
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 int slotId = getSlotIndex(subId);
4854 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4855 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4856 + subId + "' for key:" + key);
4857 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4858 }
calvinpanb5a34062021-02-08 19:59:36 +08004859 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4862 + subId + "' for key:" + key);
4863 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
4867 }
4868
4869 @Override
4870 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004871 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4872 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4873 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4875 "setImsProvisioningInt");
joonhunshincffb7fc2021-11-28 07:32:01 +00004876
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004877 final long identity = Binder.clearCallingIdentity();
4878 try {
4879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 int slotId = getSlotIndex(subId);
4881 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4882 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4883 + subId + "' for key:" + key);
4884 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4885 }
joonhunshincffb7fc2021-11-28 07:32:01 +00004886
joonhunshin91bc1952022-04-29 08:47:15 +00004887 ImsProvisioningController controller = ImsProvisioningController.getInstance();
4888 if (controller == null) {
4889 loge("setImsProvisioningInt: Device does not support IMS");
4890
4891 // device does not support IMS, this method will return CONFIG_RESULT_FAILED.
4892 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4893 }
4894 int retVal = controller.setProvisioningValue(subId, key, value);
joonhunshincffb7fc2021-11-28 07:32:01 +00004895 if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) {
4896 return retVal;
4897 }
4898
calvinpanb5a34062021-02-08 19:59:36 +08004899 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4900 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004901 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004902 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004904 } finally {
4905 Binder.restoreCallingIdentity(identity);
4906 }
4907 }
4908
4909 @Override
4910 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4912 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4913 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4915 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 int slotId = getSlotIndex(subId);
4920 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4921 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4922 + subId + "' for key:" + key);
4923 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4924 }
calvinpanb5a34062021-02-08 19:59:36 +08004925 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4926 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004928 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004929 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
4933 }
4934
Brad Ebinger919631e2021-06-02 17:46:35 -07004935 /**
4936 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4937 * for the given slot ID or no ImsResolver instance has been created.
4938 * @param slotId The slot ID that the IMS service is created for.
4939 * @throws ImsException If there is no ImsService configured for this slot.
4940 */
4941 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4942 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4943 ImsFeature.FEATURE_MMTEL)) {
4944 throw new ImsException("This subscription does not support MMTEL over IMS",
4945 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4946 }
4947 }
4948
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004949 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004950 int slotId = SubscriptionManager.getSlotIndex(subId);
4951 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004952 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4953 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004954 }
4955 return slotId;
4956 }
4957
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 private int getSlotIndex(int subId) {
4959 int slotId = SubscriptionManager.getSlotIndex(subId);
4960 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4961 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4962 }
4963 return slotId;
4964 }
4965
Wink Saville36469e72014-06-11 15:17:00 -07004966 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004967 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004968 */
4969 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004970 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4971 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07004972 try {
4973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4974 } catch (SecurityException se) {
4975 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
4976 throw new SecurityException("Package " + callingPackage + " does not belong to "
4977 + Binder.getCallingUid());
4978 }
Nathan Haroldf096d982020-11-18 17:18:06 -08004979 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004980 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004981 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004982 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004983 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004984 mApp, subId, callingPackage, callingFeatureId,
4985 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004986 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4987 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 final Phone phone = getPhone(subId);
4992 if (phone != null) {
4993 return phone.getServiceState().getDataNetworkType();
4994 } else {
4995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4996 }
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005000 }
5001
5002 /**
5003 * Returns the data network type
5004 */
5005 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005006 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Jack Yudf049d72022-12-02 22:48:35 -08005007 return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(),
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005008 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005009 }
5010
5011 /**
5012 * Returns the data network type for a subId
5013 */
5014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005015 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5016 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005017 String functionName = "getDataNetworkTypeForSubscriber";
5018 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5019 mApp, functionName)) {
5020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5021 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5022 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5023 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005024 }
5025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 final Phone phone = getPhone(subId);
5029 if (phone != null) {
5030 return phone.getServiceState().getDataNetworkType();
5031 } else {
5032 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5033 }
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005036 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005037 }
5038
5039 /**
Wink Saville36469e72014-06-11 15:17:00 -07005040 * Returns the Voice network type for a subId
5041 */
5042 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005043 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5044 String callingFeatureId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07005045 String functionName = "getVoiceNetworkTypeForSubscriber";
5046 if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow(
5047 mApp, functionName)) {
5048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5049 mApp, subId, callingPackage, callingFeatureId, functionName)) {
5050 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5051 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005052 }
5053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 final Phone phone = getPhone(subId);
5057 if (phone != null) {
5058 return phone.getServiceState().getVoiceNetworkType();
5059 } else {
5060 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5061 }
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005065 }
5066
5067 /**
5068 * @return true if a ICC card is present
5069 */
5070 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005071 // FIXME Make changes to pass defaultSimId of type int
Jack Yudf049d72022-12-02 22:48:35 -08005072 return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex(
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005073 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005074 }
5075
5076 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005077 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005078 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005079 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005080 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 final Phone phone = PhoneFactory.getPhone(slotIndex);
5084 if (phone != null) {
5085 return phone.getIccCard().hasIccCard();
5086 } else {
5087 return false;
5088 }
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005091 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005092 }
5093
5094 /**
5095 * Return if the current radio is LTE on CDMA. This
5096 * is a tri-state return value as for a period of time
5097 * the mode may be unknown.
5098 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005099 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005100 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005101 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005102 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005104 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5105 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5106 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005107 }
5108
Sanket Padawe356d7632015-06-22 14:03:32 -07005109 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005110 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5111 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005112 try {
5113 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5114 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005115 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5116 }
5117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 final Phone phone = getPhone(subId);
5121 if (phone == null) {
5122 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5123 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005124 return TelephonyProperties.lte_on_cdma_device()
5125 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005129 }
Wink Saville36469e72014-06-11 15:17:00 -07005130 }
5131
Wink Saville36469e72014-06-11 15:17:00 -07005132 /**
5133 * {@hide}
5134 * Returns Default subId, 0 in the case of single standby.
5135 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005136 private int getDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005137 return SubscriptionManager.getDefaultSubscriptionId();
Wink Saville36469e72014-06-11 15:17:00 -07005138 }
5139
Shishir Agrawala9f32182016-04-12 12:00:16 -07005140 private int getSlotForDefaultSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005141 return SubscriptionManager.getPhoneId(getDefaultSubscription());
Shishir Agrawala9f32182016-04-12 12:00:16 -07005142 }
5143
Wink Savilleb564aae2014-10-23 10:18:09 -07005144 private int getPreferredVoiceSubscription() {
Jack Yudf049d72022-12-02 22:48:35 -08005145 return SubscriptionManager.getDefaultVoiceSubscriptionId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005146 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005147
Pengquan Menge92a50d2018-09-21 15:54:48 -07005148 private boolean isActiveSubscription(int subId) {
Jack Yudf049d72022-12-02 22:48:35 -08005149 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
5150 return SubscriptionManagerService.getInstance().isActiveSubId(subId,
5151 mApp.getOpPackageName(), mApp.getFeatureId());
5152 }
Pengquan Menge92a50d2018-09-21 15:54:48 -07005153 return mSubscriptionController.isActiveSubId(subId);
5154 }
5155
Ihab Awadf2177b72013-11-25 13:33:23 -08005156 /**
5157 * @see android.telephony.TelephonyManager.WifiCallingChoices
5158 */
5159 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 final long identity = Binder.clearCallingIdentity();
5161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005162 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5164 getWhenToMakeWifiCallsDefaultPreference());
5165 } finally {
5166 Binder.restoreCallingIdentity(identity);
5167 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005168 }
5169
5170 /**
5171 * @see android.telephony.TelephonyManager.WifiCallingChoices
5172 */
5173 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
5181 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005182 }
5183
Sailesh Nepald1e68152013-12-12 19:08:02 -08005184 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005185 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005186 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005187 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005188
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005189 private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) {
5190 int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex,
5191 portIndex);
Jordan Liu4c733742019-02-28 12:03:40 -08005192 if (phoneId == -1) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005193 throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: "
5194 + portIndex + " does not correspond to an active phone");
Jordan Liu4c733742019-02-28 12:03:40 -08005195 }
5196 return PhoneFactory.getPhone(phoneId);
5197 }
5198
Shishir Agrawal566b7612013-10-28 14:41:00 -07005199 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005200 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
Rambo Wanga1782702021-11-10 20:15:19 -08005201 @NonNull IccLogicalChannelRequest request) {
5202 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5203 /*message=*/ "iccOpenLogicalChannel");
5204
5205 if (DBG) log("iccOpenLogicalChannel: request=" + request);
5206 // Verify that the callingPackage in the request belongs to the calling UID
5207 mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage);
5208
5209 return iccOpenLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005210 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005211
Rambo Wanga1782702021-11-10 20:15:19 -08005212 private Phone getPhoneFromValidIccLogicalChannelRequest(
5213 @NonNull IccLogicalChannelRequest request, String message) {
5214 Phone phone;
5215 if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
5216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5217 mApp, request.subId, message);
5218 phone = getPhoneFromSubId(request.subId);
5219 } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5220 enforceModifyPermission();
5221 phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex);
5222 } else {
5223 throw new IllegalArgumentException("Both subId and slotIndex in request are invalid.");
Jordan Liu4c733742019-02-28 12:03:40 -08005224 }
Rambo Wanga1782702021-11-10 20:15:19 -08005225 return phone;
Jordan Liu4c733742019-02-28 12:03:40 -08005226 }
5227
5228 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
Rambo Wanga1782702021-11-10 20:15:19 -08005229 IccLogicalChannelRequest channelRequest) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 final long identity = Binder.clearCallingIdentity();
5231 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005232 if (TextUtils.equals(ISDR_AID, channelRequest.aid)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5235 .getContext().getPackageManager());
Rambo Wanga1782702021-11-10 20:15:19 -08005236 if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage,
5237 bestComponent.packageName)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 loge("The calling package is not allowed to access ISD-R.");
5239 throw new SecurityException(
5240 "The calling package is not allowed to access ISD-R.");
5241 }
Derek Tan740e1672017-06-27 14:56:27 -07005242 }
Derek Tan740e1672017-06-27 14:56:27 -07005243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Rambo Wanga1782702021-11-10 20:15:19 -08005245 CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */);
5246 if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 return response;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005251 }
5252
5253 @Override
Rambo Wanga1782702021-11-10 20:15:19 -08005254 public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) {
5255 Phone phone = getPhoneFromValidIccLogicalChannelRequest(request,
5256 /*message=*/"iccCloseLogicalChannel");
5257
5258 if (DBG) log("iccCloseLogicalChannel: request=" + request);
5259
5260 return iccCloseLogicalChannelWithPermission(phone, request);
Jordan Liu4c733742019-02-28 12:03:40 -08005261 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005262
Rambo Wanga1782702021-11-10 20:15:19 -08005263 private boolean iccCloseLogicalChannelWithPermission(Phone phone,
5264 IccLogicalChannelRequest request) {
Chen Xua8f0dff2022-02-12 00:34:15 -08005265 // before this feature is enabled, this API should only return false if
5266 // the operation fails instead of throwing runtime exception for
5267 // backward-compatibility.
5268 final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled(
5269 ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 final long identity = Binder.clearCallingIdentity();
5271 try {
Rambo Wanga1782702021-11-10 20:15:19 -08005272 if (request.channel < 0) {
Chen Xu540470b2021-12-14 17:15:47 -08005273 throw new IllegalArgumentException("request.channel is less than 0");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 }
Chen Xue9d737e2022-01-01 23:41:31 -08005275 Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone,
Jordan Liu4c733742019-02-28 12:03:40 -08005276 null /* workSource */);
Chen Xue9d737e2022-01-01 23:41:31 -08005277 Boolean success = false;
5278 if (result instanceof RuntimeException) {
5279 // if there is an exception returned, throw from the binder thread here.
Chen Xua8f0dff2022-02-12 00:34:15 -08005280 if (shouldThrowExceptionOnFailure) {
5281 throw (RuntimeException) result;
5282 } else {
5283 return false;
5284 }
Chen Xue9d737e2022-01-01 23:41:31 -08005285 } else if (result instanceof Boolean) {
5286 success = (Boolean) result;
5287 } else {
5288 loge("iccCloseLogicalChannelWithPermission: supported return type " + result);
5289 }
Rambo Wanga1782702021-11-10 20:15:19 -08005290 if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 return success;
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295 }
5296
5297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005298 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005299 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005300 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5301 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005302 if (DBG) {
5303 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5304 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5305 + p3 + " data=" + data);
5306 }
5307 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5308 command, p1, p2, p3, data);
5309 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005310
Jordan Liu4c733742019-02-28 12:03:40 -08005311 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005312 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel,
5313 int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005314 enforceModifyPermission();
5315 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005316 log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex="
5317 + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1="
5318 + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005319 }
5320 return iccTransmitApduLogicalChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005321 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla,
5322 command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005323 }
5324
5325 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5326 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005329 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 return "";
5331 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005334 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5335 null /* workSource */);
5336 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 // Append the returned status code to the end of the response payload.
5339 String s = Integer.toHexString(
5340 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5341 if (response.payload != null) {
5342 s = IccUtils.bytesToHexString(response.payload) + s;
5343 }
5344 return s;
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005347 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005348 }
Jake Hambye994d462014-02-03 13:10:13 -08005349
Evan Charltonc66da362014-05-16 14:06:40 -07005350 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005351 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5352 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5354 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005356 if (DBG) {
5357 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5358 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5359 }
5360 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5361 cla, command, p1, p2, p3, data);
5362 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005363
Jordan Liu4c733742019-02-28 12:03:40 -08005364 @Override
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005365 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex,
5366 String callingPackage, int cla, int command, int p1, int p2, int p3, String data) {
Jordan Liu4c733742019-02-28 12:03:40 -08005367 enforceModifyPermission();
5368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5369 if (DBG) {
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005370 log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex="
5371 + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2="
5372 + p2 + " p3=" + p3 + " data=" + data);
Jordan Liu4c733742019-02-28 12:03:40 -08005373 }
5374
5375 return iccTransmitApduBasicChannelWithPermission(
Muralidhar Reddybd38d952021-12-02 21:04:16 +00005376 getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage,
5377 cla, command, p1, p2, p3, data);
Jordan Liu4c733742019-02-28 12:03:40 -08005378 }
5379
5380 // open APDU basic channel assuming the caller has sufficient permissions
5381 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5382 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5386 && TextUtils.equals(ISDR_AID, data)) {
5387 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5389 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 if (bestComponent == null
5391 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5392 loge("The calling package is not allowed to select ISD-R.");
5393 throw new SecurityException(
5394 "The calling package is not allowed to select ISD-R.");
5395 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005396 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005399 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5400 null /* workSource */);
5401 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 // Append the returned status code to the end of the response payload.
5404 String s = Integer.toHexString(
5405 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5406 if (response.payload != null) {
5407 s = IccUtils.bytesToHexString(response.payload) + s;
5408 }
5409 return s;
5410 } finally {
5411 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005412 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005413 }
5414
5415 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005416 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005417 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5419 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 if (DBG) {
5424 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5425 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5426 }
5427
5428 IccIoResult response =
5429 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5430 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5431 subId);
5432
5433 if (DBG) {
5434 log("Exchange SIM_IO [R]" + response);
5435 }
5436
5437 byte[] result = null;
5438 int length = 2;
5439 if (response.payload != null) {
5440 length = 2 + response.payload.length;
5441 result = new byte[length];
5442 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5443 } else {
5444 result = new byte[length];
5445 }
5446
5447 result[length - 1] = (byte) response.sw2;
5448 result[length - 2] = (byte) response.sw1;
5449 return result;
5450 } finally {
5451 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005452 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005453 }
5454
Nathan Haroldb3014052017-01-25 15:57:32 -08005455 /**
5456 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5457 * on a particular subscription
5458 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005459 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5460 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005462 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005463 return null;
5464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (appType != TelephonyManager.APPTYPE_USIM
5469 && appType != TelephonyManager.APPTYPE_SIM) {
5470 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5471 return null;
5472 }
5473 Object response = sendRequest(
5474 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5475 if (response instanceof String[]) {
5476 return (String[]) response;
5477 }
yincheng zhao2737e882019-09-06 17:06:54 -07005478 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005480 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005483 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005484 }
5485
yincheng zhao2737e882019-09-06 17:06:54 -07005486 /**
5487 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5488 * subscription.
5489 *
5490 * @param subId the id of the subscription.
5491 * @param appType the uicc app type, must be USIM or SIM.
5492 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5493 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005494 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005495 * @return number of fplmns that is successfully written to the SIM.
5496 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005497 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5498 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5500 mApp, subId, "setForbiddenPlmns");
5501
yincheng zhao2737e882019-09-06 17:06:54 -07005502 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5503 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5504 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5505 }
5506 if (fplmns == null) {
5507 throw new IllegalArgumentException("Fplmn List provided is null");
5508 }
5509 for (String fplmn : fplmns) {
5510 if (!CellIdentity.isValidPlmn(fplmn)) {
5511 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5512 }
5513 }
5514 final long identity = Binder.clearCallingIdentity();
5515 try {
5516 Object response = sendRequest(
5517 CMD_SET_FORBIDDEN_PLMNS,
5518 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5519 subId);
5520 return (int) response;
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
5524 }
5525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005527 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5529 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005530
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5534 if (response.payload == null) {
5535 return "";
5536 }
Evan Charltonc66da362014-05-16 14:06:40 -07005537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 // Append the returned status code to the end of the response payload.
5539 String s = Integer.toHexString(
5540 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5541 s = IccUtils.bytesToHexString(response.payload) + s;
5542 return s;
5543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
Evan Charltonc66da362014-05-16 14:06:40 -07005546 }
5547
Jake Hambye994d462014-02-03 13:10:13 -08005548 /**
5549 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5550 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5551 *
5552 * @param itemID the ID of the item to read
5553 * @return the NV item as a String, or null on error.
5554 */
5555 @Override
5556 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005557 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005564 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5566 return value;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Jake Hambye994d462014-02-03 13:10:13 -08005570 }
5571
5572 /**
5573 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5574 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5575 *
5576 * @param itemID the ID of the item to read
5577 * @param itemValue the value to write, as a String
5578 * @return true on success; false on any failure
5579 */
5580 @Override
5581 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5584 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585
5586 final long identity = Binder.clearCallingIdentity();
5587 try {
5588 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5589 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005590 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5592 return success;
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Jake Hambye994d462014-02-03 13:10:13 -08005596 }
5597
5598 /**
5599 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5600 * Used for device configuration by some CDMA operators.
5601 *
5602 * @param preferredRoamingList byte array containing the new PRL
5603 * @return true on success; false on any failure
5604 */
5605 @Override
5606 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5608 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
5612 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5613 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5614 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5615 return success;
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
Jake Hambye994d462014-02-03 13:10:13 -08005619 }
5620
5621 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005622 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005623 * Used for device configuration by some CDMA operators.
5624 *
chen xu6dac5ab2018-10-26 17:39:23 -07005625 * @param slotIndex - device slot.
5626 *
Jake Hambye994d462014-02-03 13:10:13 -08005627 * @return true on success; false on any failure
5628 */
5629 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005630 public boolean resetModemConfig(int slotIndex) {
5631 Phone phone = PhoneFactory.getPhone(slotIndex);
5632 if (phone != null) {
5633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5634 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
chen xu6dac5ab2018-10-26 17:39:23 -07005636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5639 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5640 return success;
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 }
chen xu6dac5ab2018-10-26 17:39:23 -07005645 return false;
5646 }
5647
5648 /**
5649 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5650 *
5651 * @param slotIndex - device slot.
5652 *
5653 * @return true on success; false on any failure
5654 */
5655 @Override
5656 public boolean rebootModem(int slotIndex) {
5657 Phone phone = PhoneFactory.getPhone(slotIndex);
5658 if (phone != null) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, phone.getSubId(), "rebootModem");
5661
5662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5665 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5666 return success;
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
5670 }
5671 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005672 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005673
Brad Ebinger51f743a2017-01-23 13:50:20 -08005674 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005675 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5676 * {@link #disableIms(int)}.
5677 * @param slotIndex device slot.
5678 */
5679 public void resetIms(int slotIndex) {
5680 enforceModifyPermission();
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 if (mImsResolver == null) {
5685 // may happen if the does not support IMS.
5686 return;
5687 }
5688 mImsResolver.disableIms(slotIndex);
5689 mImsResolver.enableIms(slotIndex);
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
5692 }
5693 }
5694
5695 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005696 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5697 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005698 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005699 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005704 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005705 // may happen if the device does not support IMS.
5706 return;
5707 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005708 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005712 }
5713
5714 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005715 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5716 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005717 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005718 public void disableIms(int slotId) {
5719 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
5722 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005723 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005724 // may happen if the device does not support IMS.
5725 return;
5726 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005731 }
5732
5733 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005734 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5735 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005736 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005737 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005738 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005743 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005744 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5745 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005746 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005747 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005751 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005752 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005753 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5754 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005755 @Override
5756 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005757 enforceModifyPermission();
5758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005762 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
5766 }
5767
5768 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005769 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005770 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005771 */
5772 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005778 // may happen if the device does not support IMS.
5779 return null;
5780 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005785 }
5786
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005787 /**
5788 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005789 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005790 */
5791 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5792 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793
5794 final long identity = Binder.clearCallingIdentity();
5795 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005796 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005797 // may happen if the device does not support IMS.
5798 return null;
5799 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005804 }
5805
Brad Ebinger884c07b2018-02-15 16:17:40 -08005806 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005807 * Sets the ImsService Package Name that Telephony will bind to.
5808 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005809 * @param slotIndex the slot ID that the ImsService should bind for.
5810 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005811 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 * @param featureTypes An integer array of feature types associated with a packageName.
5813 * @param packageName The name of the package that the current configuration will be replaced
5814 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005815 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5818 int[] featureTypes, String packageName) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005821 SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 final long identity = Binder.clearCallingIdentity();
5824 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005825 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005826 // may happen if the device does not support IMS.
5827 return false;
5828 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005829 Map<Integer, String> featureConfig = new HashMap<>();
5830 for (int featureType : featureTypes) {
5831 featureConfig.put(featureType, packageName);
5832 }
5833 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5834 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005838 }
5839
5840 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005841 * Clears any carrier ImsService overrides for the slot index specified that were previously
5842 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5843 *
5844 * This should only be used for testing.
5845 *
5846 * @param slotIndex the slot ID that the ImsService should bind for.
5847 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5848 */
5849 @Override
5850 public boolean clearCarrierImsServiceOverride(int slotIndex) {
Brad Ebinger999d3302020-11-25 14:31:39 -08005851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5852 "clearCarrierImsServiceOverride");
5853 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
Jack Yude40a3f2022-11-19 22:29:12 -08005854 SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
Brad Ebinger999d3302020-11-25 14:31:39 -08005855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 if (mImsResolver == null) {
5859 // may happen if the device does not support IMS.
5860 return false;
5861 }
5862 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5863 } finally {
5864 Binder.restoreCallingIdentity(identity);
5865 }
5866 }
5867
5868 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005870 *
5871 * @param slotId The slot that the ImsService is associated with.
5872 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5873 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005874 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005875 * @return the package name of the ImsService configuration.
5876 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005877 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5878 @ImsFeature.FeatureType int featureType) {
Brad Ebinger24c29992019-12-05 13:03:21 -08005879 TelephonyPermissions
Jack Yude40a3f2022-11-19 22:29:12 -08005880 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
5881 SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883 final long identity = Binder.clearCallingIdentity();
5884 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005885 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005886 // may happen if the device does not support IMS.
5887 return "";
5888 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005889 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005890 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5891 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005895 }
5896
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005897 /**
5898 * Get the MmTelFeature state associated with the requested subscription id.
5899 * @param subId The subscription that the MmTelFeature is associated with.
5900 * @param callback A callback with an integer containing the
5901 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5902 */
5903 @Override
5904 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5905 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
Brad Ebingera2628302022-02-18 03:44:55 +00005906 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5908 "IMS not available on device.");
5909 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005910 final long token = Binder.clearCallingIdentity();
5911 try {
Brad Ebingera2628302022-02-18 03:44:55 +00005912 int slotId = getSlotIndex(subId);
5913 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5914 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5915 + subId + "'");
5916 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5917 }
5918 verifyImsMmTelConfiguredOrThrow(slotId);
5919 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5920 try {
5921 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5922 } catch (RemoteException e) {
5923 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5924 + "Ignore");
5925 }
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005926 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005927 } catch (ImsException e) {
5928 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005929 } finally {
5930 Binder.restoreCallingIdentity(token);
5931 }
5932 }
5933
Daniel Brightbb5840b2021-01-12 15:48:18 -08005934 /**
5935 * Sets the ims registration state on all valid {@link Phone}s.
5936 */
5937 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005938 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005942 // NOTE: Before S, this method only set the default phone.
5943 for (final Phone phone : PhoneFactory.getPhones()) {
5944 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5945 phone.setImsRegistrationState(registered);
5946 }
5947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Wink Saville36469e72014-06-11 15:17:00 -07005951 }
5952
5953 /**
Stuart Scott54788802015-03-30 13:18:01 -07005954 * Set the network selection mode to automatic.
5955 *
5956 */
5957 @Override
5958 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5960 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005961
5962 final long identity = Binder.clearCallingIdentity();
5963 try {
shilufc958392020-01-20 11:36:01 -08005964 if (!isActiveSubscription(subId)) {
5965 return;
5966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005968 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5969 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 } finally {
5971 Binder.restoreCallingIdentity(identity);
5972 }
Stuart Scott54788802015-03-30 13:18:01 -07005973 }
5974
Jack Yud10cdd42020-09-28 20:28:01 -07005975 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005976 * Ask the radio to connect to the input network and change selection mode to manual.
5977 *
5978 * @param subId the id of the subscription.
5979 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5980 * the operator to attach to.
5981 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5982 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5983 * normal network selection next time.
5984 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005985 */
5986 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005987 public boolean setNetworkSelectionModeManual(
5988 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5990 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005991
Jack Yudf049d72022-12-02 22:48:35 -08005992 final long identity = Binder.clearCallingIdentity();
Pengquan Menge92a50d2018-09-21 15:54:48 -07005993 if (!isActiveSubscription(subId)) {
5994 return false;
5995 }
5996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005998 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006000 if (DBG) {
6001 log("setNetworkSelectionModeManual: subId: " + subId
6002 + " operator: " + operatorInfo);
6003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006008 }
shilu84f6e8b2019-12-19 13:58:01 -08006009 /**
6010 * Get the manual network selection
6011 *
6012 * @param subId the id of the subscription.
6013 *
6014 * @return the previously saved user selected PLMN
6015 */
6016 @Override
6017 public String getManualNetworkSelectionPlmn(int subId) {
6018 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006019 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006020 mApp, subId, "getManualNetworkSelectionPlmn");
6021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006025 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006026 }
6027
6028 final Phone phone = getPhone(subId);
6029 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006030 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006031 }
6032 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6033 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6034 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
6038 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006039
6040 /**
6041 * Scans for available networks.
6042 */
6043 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006044 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6047 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006048 LocationAccessPolicy.LocationPermissionResult locationResult =
6049 LocationAccessPolicy.checkLocationPermission(mApp,
6050 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6051 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006052 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006053 .setCallingPid(Binder.getCallingPid())
6054 .setCallingUid(Binder.getCallingUid())
6055 .setMethod("getCellNetworkScanResults")
6056 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6058 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 .build());
6060 switch (locationResult) {
6061 case DENIED_HARD:
6062 throw new SecurityException("Not allowed to access scan results -- location");
6063 case DENIED_SOFT:
6064 return null;
6065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066
Pengquan Menga1bb6272018-09-06 09:59:22 -07006067 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 try {
6069 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006070 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 } finally {
6073 Binder.restoreCallingIdentity(identity);
6074 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006075 }
6076
6077 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006078 * Get the call forwarding info, given the call forwarding reason.
6079 */
6080 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006081 public void getCallForwarding(int subId, int callForwardingReason,
6082 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006083 enforceReadPrivilegedPermission("getCallForwarding");
6084 long identity = Binder.clearCallingIdentity();
6085 try {
6086 if (DBG) {
6087 log("getCallForwarding: subId " + subId
6088 + " callForwardingReason" + callForwardingReason);
6089 }
Hall Liu27d24262020-09-18 19:04:59 -07006090
6091 Phone phone = getPhone(subId);
6092 if (phone == null) {
6093 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006094 callback.onError(
6095 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006096 } catch (RemoteException e) {
6097 // ignore
6098 }
6099 return;
6100 }
6101
6102 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6103 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6104 @Override
6105 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6106 try {
6107 callback.onCallForwardingInfoAvailable(info);
6108 } catch (RemoteException e) {
6109 // ignore
6110 }
6111 }
6112
6113 @Override
6114 public void onError(int error) {
6115 try {
6116 callback.onError(error);
6117 } catch (RemoteException e) {
6118 // ignore
6119 }
6120 }
6121 });
6122 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
6126 }
6127
6128 /**
6129 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6130 * reason, the number to forward, and the timeout before the forwarding is attempted.
6131 */
6132 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006133 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6134 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006135 enforceModifyPermission();
6136 long identity = Binder.clearCallingIdentity();
6137 try {
6138 if (DBG) {
6139 log("setCallForwarding: subId " + subId
6140 + " callForwardingInfo" + callForwardingInfo);
6141 }
Hall Liu27d24262020-09-18 19:04:59 -07006142
6143 Phone phone = getPhone(subId);
6144 if (phone == null) {
6145 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006146 callback.accept(
6147 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 return;
6152 }
6153
6154 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6155 FunctionalUtils.ignoreRemoteException(callback::accept));
6156
6157 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
6161 }
6162
6163 /**
Hall Liu27d24262020-09-18 19:04:59 -07006164 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006165 */
6166 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006167 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006168 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006169 long identity = Binder.clearCallingIdentity();
6170 try {
Hall Liu27d24262020-09-18 19:04:59 -07006171 Phone phone = getPhone(subId);
6172 if (phone == null) {
6173 try {
6174 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6175 } catch (RemoteException e) {
6176 // ignore
6177 }
6178 return;
6179 }
SongFerngWang0e767992021-03-31 22:08:45 +08006180 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6181 PersistableBundle c = configManager.getConfigForSubId(subId);
6182 boolean requireUssd = c.getBoolean(
6183 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006184
Shuo Qian4a594052020-01-23 11:59:30 -08006185 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006186 if (requireUssd) {
6187 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6188 getSubscriptionCarrierId(subId));
6189 String newUssdCommand = "";
6190 try {
6191 newUssdCommand = carrierXmlParser.getFeature(
6192 CarrierXmlParser.FEATURE_CALL_WAITING)
6193 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6194 } catch (NullPointerException e) {
6195 loge("Failed to generate USSD number" + e);
6196 }
6197 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6198 mMainThreadHandler, callback, carrierXmlParser,
6199 CarrierXmlParser.SsEntry.SSAction.QUERY);
6200 final String ussdCommand = newUssdCommand;
6201 Executors.newSingleThreadExecutor().execute(() -> {
6202 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6203 });
6204 } else {
6205 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6206 callback::accept);
6207 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6208 }
Shuo Qian4a594052020-01-23 11:59:30 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
Hall Liu27d24262020-09-18 19:04:59 -07006215 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006216 */
6217 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006218 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006219 enforceModifyPermission();
6220 long identity = Binder.clearCallingIdentity();
6221 try {
Hall Liu27d24262020-09-18 19:04:59 -07006222 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6223
6224 Phone phone = getPhone(subId);
6225 if (phone == null) {
6226 try {
6227 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6228 } catch (RemoteException e) {
6229 // ignore
6230 }
6231 return;
6232 }
6233
SongFerngWang0e767992021-03-31 22:08:45 +08006234 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6235 PersistableBundle c = configManager.getConfigForSubId(subId);
6236 boolean requireUssd = c.getBoolean(
6237 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006238
SongFerngWang0e767992021-03-31 22:08:45 +08006239 if (DBG) log("getCallWaitingStatus: subId " + subId);
6240 if (requireUssd) {
6241 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6242 getSubscriptionCarrierId(subId));
6243 CarrierXmlParser.SsEntry.SSAction ssAction =
6244 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6245 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6246 String newUssdCommand = "";
6247 try {
6248 newUssdCommand = carrierXmlParser.getFeature(
6249 CarrierXmlParser.FEATURE_CALL_WAITING)
6250 .makeCommand(ssAction, null);
6251 } catch (NullPointerException e) {
6252 loge("Failed to generate USSD number" + e);
6253 }
6254 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6255 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6256 final String ussdCommand = newUssdCommand;
6257 Executors.newSingleThreadExecutor().execute(() -> {
6258 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6259 });
6260 } else {
6261 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6262 FunctionalUtils.ignoreRemoteException(callback::accept));
6263
6264 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6265 }
Shuo Qian4a594052020-01-23 11:59:30 -08006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
6268 }
6269 }
6270
6271 /**
yinxub1bed742017-04-17 11:45:04 -07006272 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006273 *
yinxub1bed742017-04-17 11:45:04 -07006274 * @param subId id of the subscription
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006275 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive
6276 * location related information which will be sent if the caller already possess
6277 * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission
yinxub1bed742017-04-17 11:45:04 -07006278 * @param request contains the radio access networks with bands/channels to scan
6279 * @param messenger callback messenger for scan results or errors
6280 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006281 * @return the id of the requested scan which can be used to stop the scan.
6282 */
6283 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006284 public int requestNetworkScan(int subId, boolean renounceFineLocationAccess,
6285 NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006286 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6288 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006289 LocationAccessPolicy.LocationPermissionResult locationResult =
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006290 LocationAccessPolicy.LocationPermissionResult.DENIED_HARD;
6291 if (!renounceFineLocationAccess) {
6292 locationResult = LocationAccessPolicy.checkLocationPermission(mApp,
6293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6294 .setCallingPackage(callingPackage)
6295 .setCallingFeatureId(callingFeatureId)
6296 .setCallingPid(Binder.getCallingPid())
6297 .setCallingUid(Binder.getCallingUid())
6298 .setMethod("requestNetworkScan")
6299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6300 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6301 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
6302 .build());
6303 }
Hall Liub2ac8ef2019-02-28 15:56:23 -08006304 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006305 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6306 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006307 if (e != null) {
6308 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6309 throw e;
6310 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006311 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006312 return TelephonyScanManager.INVALID_SCAN_ID;
6313 }
6314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 }
Hall Liu912dfd32019-04-25 14:02:26 -07006316 int callingUid = Binder.getCallingUid();
6317 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 return mNetworkScanRequestTracker.startNetworkScan(
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08006321 renounceFineLocationAccess, request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006322 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006323 } finally {
6324 Binder.restoreCallingIdentity(identity);
6325 }
yinxu504e1392017-04-12 16:03:22 -07006326 }
6327
Hall Liub2ac8ef2019-02-28 15:56:23 -08006328 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006329 NetworkScanRequest request, int subId, String callingPackage) {
6330 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006331 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6332 boolean hasNetworkScanPermission =
6333 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6334 == PERMISSION_GRANTED;
6335
6336 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6337 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6338 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006339 }
6340
6341 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6342 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006343 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6344 return new SecurityException("Specific channels must not be"
6345 + " scanned without location access.");
6346 }
6347 }
6348 }
6349
Hall Liub2ac8ef2019-02-28 15:56:23 -08006350 return null;
6351 }
6352
yinxu504e1392017-04-12 16:03:22 -07006353 /**
6354 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006355 *
6356 * @param subId id of the subscription
6357 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006358 */
6359 @Override
6360 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6362 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
Hall Liu912dfd32019-04-25 14:02:26 -07006364 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 final long identity = Binder.clearCallingIdentity();
6366 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006367 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
yinxu504e1392017-04-12 16:03:22 -07006371 }
6372
6373 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006374 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006375 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006376 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006377 */
6378 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006379 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006380 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006381 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006382 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006386 if (DBG) log("getAllowedNetworkTypesBitmask");
6387 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6388 int networkTypesBitmask = (result != null ? result[0] : -1);
6389 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6390 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006394 }
6395
6396 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006397 * Get the allowed network types for certain reason.
6398 *
6399 * @param subId the id of the subscription.
6400 * @param reason the reason the allowed network type change is taking place
6401 * @return the allowed network types.
6402 */
6403 @Override
6404 public long getAllowedNetworkTypesForReason(int subId,
6405 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006406 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006407 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006408 final long identity = Binder.clearCallingIdentity();
6409 try {
6410 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
6414 }
6415
6416 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006417 * Enable/Disable E-UTRA-NR Dual Connectivity
6418 * @param subId subscription id of the sim card
6419 * @param nrDualConnectivityState expected NR dual connectivity state
6420 * This can be passed following states
6421 * <ol>
6422 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6423 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6424 * <li>Disable NR dual connectivity and force secondary cell to be released
6425 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6426 * </ol>
6427 * @return operation result.
6428 */
6429 @Override
6430 public int setNrDualConnectivityState(int subId,
6431 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6433 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006434 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006435 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6436 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6437 }
6438
Sooraj Sasindran37444802020-08-11 10:40:43 -07006439 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6440 final long identity = Binder.clearCallingIdentity();
6441 try {
6442 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6443 nrDualConnectivityState, subId,
6444 workSource);
6445 if (DBG) log("enableNRDualConnectivity result: " + result);
6446 return result;
6447 } finally {
6448 Binder.restoreCallingIdentity(identity);
6449 }
6450 }
6451
6452 /**
6453 * Is E-UTRA-NR Dual Connectivity enabled
6454 * @return true if dual connectivity is enabled else false
6455 */
6456 @Override
6457 public boolean isNrDualConnectivityEnabled(int subId) {
6458 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006459 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006460 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006461 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006462 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6463 return false;
6464 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6469 null, subId, workSource);
6470 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6471 return isEnabled;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006478 * Set the allowed network types of the device and
6479 * provide the reason triggering the allowed network change.
6480 *
6481 * @param subId the id of the subscription.
6482 * @param reason the reason the allowed network type change is taking place
6483 * @param allowedNetworkTypes the allowed network types.
6484 * @return true on success; false on any failure.
6485 */
6486 @Override
6487 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006488 @TelephonyManager.AllowedNetworkTypesReason int reason,
6489 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6491 mApp, subId, "setAllowedNetworkTypesForReason");
Gil Cukierman1d3d3752022-10-03 21:31:33 +00006492 // If the caller only has carrier privileges, then they should not be able to override
6493 // any network types which were set for security reasons.
6494 if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE)
6495 != PERMISSION_GRANTED
6496 && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G
6497 || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) {
6498 throw new SecurityException(
6499 "setAllowedNetworkTypesForReason cannot be called with carrier privileges for"
6500 + " reason "
6501 + reason);
6502 }
SongFerngWang3ef3e072020-12-21 16:41:52 +08006503 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006504 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6505 return false;
6506 }
6507 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6508 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006509 return false;
6510 }
6511
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006512 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6513 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6514
6515
6516 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6517 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6518 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006519 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006520
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006521 final long identity = Binder.clearCallingIdentity();
6522 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006523 Boolean success = (Boolean) sendRequest(
6524 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6525 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6526
6527 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6528 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 /**
Miaoa84611c2019-03-15 09:21:10 +08006535 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006536 *
Miaoa84611c2019-03-15 09:21:10 +08006537 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006538 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006539 * @hide
6540 */
6541 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006542 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006545 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546 try {
Miaoa84611c2019-03-15 09:21:10 +08006547 if (phone != null) {
6548 return phone.hasMatchedTetherApnSetting();
6549 } else {
6550 return false;
6551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 } finally {
6553 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006554 }
Junda Liu475951f2014-11-07 16:45:03 -08006555 }
6556
6557 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006558 * Get the user enabled state of Mobile Data.
6559 *
6560 * TODO: remove and use isUserDataEnabled.
6561 * This can't be removed now because some vendor codes
6562 * calls through ITelephony directly while they should
6563 * use TelephonyManager.
6564 *
6565 * @return true on enabled
6566 */
6567 @Override
6568 public boolean getDataEnabled(int subId) {
6569 return isUserDataEnabled(subId);
6570 }
6571
6572 /**
6573 * Get whether mobile data is enabled per user setting.
6574 *
6575 * There are other factors deciding whether mobile data is actually enabled, but they are
6576 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006577 *
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006578 * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE
6579 * or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006580 *
6581 * @return {@code true} if data is enabled else {@code false}
6582 */
6583 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006584 public boolean isUserDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006585 String functionName = "isUserDataEnabled";
Robert Greenwalt646120a2014-05-23 11:54:03 -07006586 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006587 try {
6588 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6589 functionName);
6590 } catch (Exception e) {
6591 mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName);
6592 }
Robert Greenwalt646120a2014-05-23 11:54:03 -07006593 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006595 mApp, subId, functionName);
6596
Robert Greenwalt646120a2014-05-23 11:54:03 -07006597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
Jack Yudf049d72022-12-02 22:48:35 -08006601 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006602 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6603 Phone phone = PhoneFactory.getPhone(phoneId);
6604 if (phone != null) {
6605 boolean retVal = phone.isUserDataEnabled();
6606 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6607 return retVal;
6608 } else {
6609 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6610 return false;
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006614 }
6615 }
6616
6617 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006618 * Checks if the device is capable of mobile data by considering whether whether the
6619 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6620 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006621 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006622 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 */
6624 @Override
6625 public boolean isDataEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006626 String functionName = "isDataEnabled";
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006627 try {
6628 try {
6629 mApp.enforceCallingOrSelfPermission(
6630 android.Manifest.permission.ACCESS_NETWORK_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006631 functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006632 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006633 try {
6634 mApp.enforceCallingOrSelfPermission(
6635 android.Manifest.permission.READ_PHONE_STATE,
6636 functionName);
6637 } catch (Exception e2) {
6638 mApp.enforceCallingOrSelfPermission(
6639 permission.READ_BASIC_PHONE_STATE, functionName);
6640 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006641 }
6642 } catch (Exception e) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006643 enforceReadPrivilegedPermission(functionName);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
Jack Yudf049d72022-12-02 22:48:35 -08006648 int phoneId = SubscriptionManager.getPhoneId(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 Phone phone = PhoneFactory.getPhone(phoneId);
6650 if (phone != null) {
Jack Yu4ad64e52021-12-03 14:23:53 -08006651 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006652 retVal = phone.getDataSettingsManager().isDataEnabled();
Jack Yu4ad64e52021-12-03 14:23:53 -08006653 if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 return retVal;
6655 } else {
6656 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6657 return false;
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006661 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006662 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006663
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006664 /**
6665 * Check if data is enabled for a specific reason
6666 * @param subId Subscription index
6667 * @param reason the reason the data enable change is taking place
6668 * @return {@code true} if the overall data is enabled; {@code false} if not.
6669 */
6670 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006671 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006672 @TelephonyManager.DataEnabledReason int reason) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006673 String functionName = "isDataEnabledForReason";
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006674 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006675 try {
6676 mApp.enforceCallingOrSelfPermission(
6677 android.Manifest.permission.ACCESS_NETWORK_STATE,
6678 functionName);
6679 } catch (Exception e) {
6680 mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE,
6681 functionName);
6682 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006683 } catch (Exception e) {
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006684 try {
6685 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006686 functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006687 } catch (Exception e2) {
6688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07006689 mApp, subId, functionName);
Sooraj Sasindran0d909a02021-11-08 12:01:16 -08006690 }
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006691 }
6692
6693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
Jack Yudf049d72022-12-02 22:48:35 -08006696 int phoneId = SubscriptionManager.getPhoneId(subId);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006697 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006698 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006699 + " reason=" + reason);
6700 }
6701 Phone phone = PhoneFactory.getPhone(phoneId);
6702 if (phone != null) {
6703 boolean retVal;
Jack Yuabb10902022-07-31 00:43:21 -07006704 retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason);
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006705 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006706 return retVal;
6707 } else {
6708 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006709 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006710 + subId + " retVal=false");
6711 }
6712 return false;
6713 }
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
6716 }
6717 }
6718
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006719 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006720 public int getCarrierPrivilegeStatus(int subId) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006721 // No permission needed; this only lets the caller inspect their own status.
6722 return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006723 }
Junda Liu29340342014-07-10 15:23:27 -07006724
6725 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006727 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006728 return getCarrierPrivilegeStatusForUidWithPermission(subId, uid);
6729 }
6730
6731 private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) {
6732 Phone phone = getPhone(subId);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006733 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006734 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6736 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006737 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6738 if (cpt == null) {
6739 loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006740 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6741 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006742 return cpt.getCarrierPrivilegeStatusForUid(uid);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006743 }
6744
6745 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006746 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006747 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006748 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006749 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006750 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006751 Phone phone = getPhone(subId);
6752 if (phone == null) {
6753 loge("checkCarrierPrivilegesForPackage: Invalid subId");
6754 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6755 }
6756 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6757 if (cpt == null) {
6758 loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6760 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006761 return cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006762 }
6763
6764 @Override
6765 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006766 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Rambo Wange7209ce2022-02-23 13:41:02 -08006767 return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName);
6768 }
6769
6770 private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) {
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006771 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006772 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006773 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006774 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006775 for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) {
6776 Phone phone = PhoneFactory.getPhone(phoneId);
6777 if (phone == null) {
6778 continue;
Zach Johnson50ecba32015-05-19 00:24:21 -07006779 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006780 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6781 if (cpt == null) {
6782 continue;
6783 }
6784 result = cpt.getCarrierPrivilegeStatusForPackage(pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006785 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6786 break;
6787 }
6788 }
Zach Johnson50ecba32015-05-19 00:24:21 -07006789 return result;
Junda Liu29340342014-07-10 15:23:27 -07006790 }
Derek Tan89e89d42014-07-08 17:00:10 -07006791
6792 @Override
Junda Liue64de782015-04-16 17:19:16 -07006793 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006794 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Rambo Wang8a247eb2022-02-08 21:11:18 +00006795 Phone phone = PhoneFactory.getPhone(phoneId);
6796 if (phone == null) {
6797 return Collections.emptyList();
Junda Liue64de782015-04-16 17:19:16 -07006798 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006799 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6800 if (cpt == null) {
6801 return Collections.emptyList();
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006802 }
Rambo Wang8a247eb2022-02-08 21:11:18 +00006803 return cpt.getCarrierPackageNamesForIntent(intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006804 }
6805
Amith Yamasani6e118872016-02-19 12:53:51 -08006806 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006807 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006808 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006809 Phone phone = PhoneFactory.getPhone(phoneId);
6810 if (phone == null) {
6811 return Collections.emptyList();
Amith Yamasani6e118872016-02-19 12:53:51 -08006812 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006813 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6814 if (cpt == null) {
6815 return Collections.emptyList();
6816 }
6817 return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges());
Amith Yamasani6e118872016-02-19 12:53:51 -08006818 }
6819
chen xuf7e9fe82019-05-09 19:31:02 -07006820 @Override
6821 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006822 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006823 Set<String> privilegedPackages = new ArraySet<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 final long identity = Binder.clearCallingIdentity();
Shuo Qian067a06d2019-12-03 23:40:18 +00006825 try {
6826 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6827 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6828 }
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006831 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08006832 return new ArrayList<>(privilegedPackages);
chen xuf7e9fe82019-05-09 19:31:02 -07006833 }
6834
Rambo Wang6812ffb2022-03-15 16:54:17 -07006835 @Override
6836 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) {
6837 enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot");
6838
6839 final Phone phone = PhoneFactory.getPhone(logicalSlotIndex);
6840 if (phone == null) {
6841 return null;
6842 }
6843 final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
6844 if (cpt == null) {
6845 return null;
6846 }
6847 return cpt.getCarrierServicePackageName();
6848 }
6849
Wink Savilleb564aae2014-10-23 10:18:09 -07006850 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006851 final Phone phone = getPhone(subId);
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006852 UiccPort port = phone == null ? null : phone.getUiccPort();
6853 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006854 return null;
6855 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00006856 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006857 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006858 return null;
6859 }
6860 return iccId;
6861 }
6862
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006863 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006864 public void setCallComposerStatus(int subId, int status) {
6865 enforceModifyPermission();
6866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 Phone phone = getPhone(subId);
6870 if (phone != null) {
6871 Phone defaultPhone = phone.getImsPhone();
6872 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6873 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6874 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6876 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006877 }
6878 }
Shuo Qian284ae752020-12-22 19:10:14 -08006879 } catch (ImsException e) {
6880 throw new ServiceSpecificException(e.getCode());
6881 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006882 Binder.restoreCallingIdentity(identity);
6883 }
6884 }
6885
6886 @Override
6887 public int getCallComposerStatus(int subId) {
6888 enforceReadPrivilegedPermission("getCallComposerStatus");
6889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 Phone phone = getPhone(subId);
6893 if (phone != null) {
6894 Phone defaultPhone = phone.getImsPhone();
6895 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6896 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6897 return imsPhone.getCallComposerStatus();
6898 }
6899 }
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
6902 }
6903 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6904 }
6905
6906 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006907 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6908 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006909 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006910 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912 final long identity = Binder.clearCallingIdentity();
6913 try {
6914 final String iccId = getIccId(subId);
6915 final Phone phone = getPhone(subId);
6916 if (phone == null) {
6917 return false;
6918 }
6919 final String subscriberId = phone.getSubscriberId();
6920
6921 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006922 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923 + subscriberId + " to " + number);
6924 }
6925
6926 if (TextUtils.isEmpty(iccId)) {
6927 return false;
6928 }
6929
6930 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6931
6932 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6933 if (alphaTag == null) {
6934 editor.remove(alphaTagPrefKey);
6935 } else {
6936 editor.putString(alphaTagPrefKey, alphaTag);
6937 }
6938
6939 // Record both the line number and IMSI for this ICCID, since we need to
6940 // track all merged IMSIs based on line number
6941 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6942 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6943 if (number == null) {
6944 editor.remove(numberPrefKey);
6945 editor.remove(subscriberPrefKey);
6946 } else {
6947 editor.putString(numberPrefKey, number);
6948 editor.putString(subscriberPrefKey, subscriberId);
6949 }
6950
6951 editor.commit();
6952 return true;
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006955 }
Derek Tan7226c842014-07-02 17:42:23 -07006956 }
6957
6958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006959 public String getLine1NumberForDisplay(int subId, String callingPackage,
6960 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006961 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006963 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006964 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006965 return null;
6966 }
Derek Tan97ebb422014-09-05 16:55:38 -07006967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 String iccId = getIccId(subId);
6971 if (iccId != null) {
6972 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6973 if (DBG_MERGE) {
6974 log("getLine1NumberForDisplay returning "
6975 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6976 }
6977 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6980 return null;
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006983 }
Derek Tan7226c842014-07-02 17:42:23 -07006984 }
6985
6986 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006987 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006990 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006991 return null;
6992 }
Derek Tan97ebb422014-09-05 16:55:38 -07006993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 String iccId = getIccId(subId);
6997 if (iccId != null) {
6998 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6999 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7000 }
7001 return null;
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007004 }
Derek Tan7226c842014-07-02 17:42:23 -07007005 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007006
7007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007008 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7009 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007010 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7011 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007013 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007014 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007015 return null;
7016 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007017
Jordan Liub49b04b2019-05-06 14:45:15 -07007018 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7019 // the process, where TelephonyManager was instantiated.
7020 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007021 final long identity = Binder.clearCallingIdentity();
7022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007023 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final TelephonyManager tele = TelephonyManager.from(context);
7025 final SubscriptionManager sub = SubscriptionManager.from(context);
7026
7027 // Figure out what subscribers are currently active
7028 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029
Jordan Liub49b04b2019-05-06 14:45:15 -07007030 // Only consider subs which match the current subId
7031 // This logic can be simplified. See b/131189269 for progress.
7032 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007033 activeSubscriberIds.add(tele.getSubscriberId(subId));
7034 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035
7036 // First pass, find a number override for an active subscriber
7037 String mergeNumber = null;
7038 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7039 for (String key : prefs.keySet()) {
7040 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7041 final String subscriberId = (String) prefs.get(key);
7042 if (activeSubscriberIds.contains(subscriberId)) {
7043 final String iccId = key.substring(
7044 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7045 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7046 mergeNumber = (String) prefs.get(numberKey);
7047 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007048 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 + " for active subscriber " + subscriberId);
7050 }
7051 if (!TextUtils.isEmpty(mergeNumber)) {
7052 break;
7053 }
7054 }
7055 }
7056 }
7057
7058 // Shortcut when no active merged subscribers
7059 if (TextUtils.isEmpty(mergeNumber)) {
7060 return null;
7061 }
7062
7063 // Second pass, find all subscribers under that line override
7064 final ArraySet<String> result = new ArraySet<>();
7065 for (String key : prefs.keySet()) {
7066 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7067 final String number = (String) prefs.get(key);
7068 if (mergeNumber.equals(number)) {
7069 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7070 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7071 final String subscriberId = (String) prefs.get(subscriberKey);
7072 if (!TextUtils.isEmpty(subscriberId)) {
7073 result.add(subscriberId);
7074 }
7075 }
7076 }
7077 }
7078
7079 final String[] resultArray = result.toArray(new String[result.size()]);
7080 Arrays.sort(resultArray);
7081 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007082 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7084 }
7085 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007088 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007089 }
7090
7091 @Override
zoey chen38003472019-12-13 17:16:31 +08007092 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7093 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007094
7095 final long identity = Binder.clearCallingIdentity();
7096 try {
7097 final TelephonyManager telephonyManager = mApp.getSystemService(
7098 TelephonyManager.class);
7099 String subscriberId = telephonyManager.getSubscriberId(subId);
7100 if (subscriberId == null) {
7101 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007102 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007103 + subId);
7104 }
7105 return null;
7106 }
7107
Jack Yudf049d72022-12-02 22:48:35 -08007108 ParcelUuid groupUuid;
7109 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7110 final SubscriptionInfo info = SubscriptionManagerService.getInstance()
7111 .getSubscriptionInfo(subId);
7112 groupUuid = info.getGroupUuid();
7113 } else {
7114 final SubscriptionInfo info = mSubscriptionController
7115 .getSubscriptionInfo(subId);
7116 groupUuid = info.getGroupUuid();
7117 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007118 // If it doesn't belong to any group, return just subscriberId of itself.
7119 if (groupUuid == null) {
7120 return new String[]{subscriberId};
7121 }
7122
7123 // Get all subscriberIds from the group.
7124 final List<String> mergedSubscriberIds = new ArrayList<>();
Jack Yudf049d72022-12-02 22:48:35 -08007125 List<SubscriptionInfo> groupInfos;
7126 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7127 groupInfos = SubscriptionManagerService.getInstance()
7128 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7129 mApp.getAttributionTag());
7130 } else {
7131 groupInfos = mSubscriptionController
7132 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
7133 mApp.getAttributionTag());
7134 }
Malcolm Chen6ca97372019-07-01 16:28:21 -07007135 for (SubscriptionInfo subInfo : groupInfos) {
7136 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7137 if (subscriberId != null) {
7138 mergedSubscriberIds.add(subscriberId);
7139 }
7140 }
7141
7142 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145
7146 }
7147 }
7148
7149 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007150 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007151 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007152 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 final Phone phone = getPhone(subId);
7157 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
7160 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007161 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007162
7163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007164 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007165 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7166 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007167 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7168 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 final Phone phone = getPhone(subId);
7173 if (phone == null) {
7174 return false;
7175 }
7176 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7177 cdmaNonRoamingList);
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007180 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007181 }
7182
7183 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007184 @Deprecated
7185 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7186 enforceModifyPermission();
7187
7188 int returnValue = 0;
7189 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007190 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007191 if(result.exception == null) {
7192 if (result.result != null) {
7193 byte[] responseData = (byte[])(result.result);
7194 if(responseData.length > oemResp.length) {
7195 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7196 responseData.length + "bytes. Buffer Size is " +
7197 oemResp.length + "bytes.");
7198 }
7199 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7200 returnValue = responseData.length;
7201 }
7202 } else {
7203 CommandException ex = (CommandException) result.exception;
7204 returnValue = ex.getCommandError().ordinal();
7205 if(returnValue > 0) returnValue *= -1;
7206 }
7207 } catch (RuntimeException e) {
7208 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7209 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7210 if(returnValue > 0) returnValue *= -1;
7211 }
7212
7213 return returnValue;
7214 }
7215
7216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007217 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007218 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007219 try {
7220 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007221 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007222 mApp, phone.getSubId(), "getRadioAccessFamily");
7223 } catch (SecurityException e) {
7224 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7225 throw e;
7226 }
chen xub97461a2018-10-26 14:17:57 -07007227 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007229 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 final long identity = Binder.clearCallingIdentity();
7232 try {
chen xub97461a2018-10-26 14:17:57 -07007233 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007234 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007235 mApp, phone.getSubId(), "getRadioAccessFamily");
7236 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 } finally {
7238 Binder.restoreCallingIdentity(identity);
7239 }
chen xub97461a2018-10-26 14:17:57 -07007240 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007241 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007242
7243 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007244 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007245 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007246 try {
7247 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7248 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007249 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007250 }
7251 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007252 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007253 }
7254 RoleManager rm = mApp.getSystemService(RoleManager.class);
7255 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7256 if (!dialerRoleHolders.contains(callingPackage)) {
7257 throw new SecurityException("App must be the dialer role holder to"
7258 + " upload a call composer pic");
7259 }
7260
7261 Executors.newSingleThreadExecutor().execute(() -> {
7262 ByteArrayOutputStream output = new ByteArrayOutputStream(
7263 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7264 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7265 boolean readUntilEnd = false;
7266 int totalBytesRead = 0;
7267 byte[] buffer = new byte[16 * 1024];
7268 while (true) {
7269 int numRead;
7270 try {
7271 numRead = input.read(buffer);
7272 } catch (IOException e) {
7273 try {
7274 fd.checkError();
7275 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7276 null);
7277 } catch (IOException e1) {
7278 // This means that the other side closed explicitly with an error. If this
7279 // happens, log and ignore.
7280 loge("Remote end of call composer picture pipe closed: " + e1);
7281 }
7282 break;
7283 }
7284 if (numRead == -1) {
7285 readUntilEnd = true;
7286 break;
7287 }
7288 totalBytesRead += numRead;
7289 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7290 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7291 try {
7292 input.close();
7293 } catch (IOException e) {
7294 // ignore
7295 }
7296 break;
7297 }
7298 output.write(buffer, 0, numRead);
7299 }
7300 // Generally, the remote end will close the file descriptors. The only case where we
7301 // close is above, where the picture size is too big.
7302
7303 try {
7304 fd.checkError();
7305 } catch (IOException e) {
7306 loge("Remote end for call composer closed with an error: " + e);
7307 return;
7308 }
7309
Hall Liuaa4211e2021-01-20 15:43:39 -08007310 if (!readUntilEnd) {
7311 loge("Did not finish reading entire image; aborting");
7312 return;
7313 }
Hall Liu82694d52020-12-11 18:22:04 -08007314
Hall Liuaa4211e2021-01-20 15:43:39 -08007315 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7316 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7317 new CallComposerPictureTransfer.Factory() {},
7318 imageData,
7319 (result) -> {
7320 if (result.first != null) {
7321 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7322 Bundle outputResult = new Bundle();
7323 outputResult.putParcelable(
7324 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7325 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7326 outputResult);
7327 } else {
7328 callback.send(result.second, null);
7329 }
7330 }
7331 );
Hall Liu82694d52020-12-11 18:22:04 -08007332 });
7333 }
7334
7335 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007336 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007337 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007338 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339
7340 final long identity = Binder.clearCallingIdentity();
7341 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 ImsManager.getInstance(defaultPhone.getContext(),
7343 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007347 }
7348
7349 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007351 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7353 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007354 return false;
7355 }
Svet Ganovb320e182015-04-16 12:30:10 -07007356
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 final long identity = Binder.clearCallingIdentity();
7358 try {
7359 // Check the user preference and the system-level IMS setting. Even if the user has
7360 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7361 // In the long run, we may instead need to check if there exists a connection service
7362 // which can support video calling.
7363 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 return imsManager.isVtEnabledByPlatform()
7366 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7367 && imsManager.isVtEnabledByUser();
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007371 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007372
Andrew Leea1239f22015-03-02 17:44:07 -08007373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007374 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7375 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007377 mApp, subId, callingPackage, callingFeatureId,
7378 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 return false;
7380 }
7381
7382 final long identity = Binder.clearCallingIdentity();
7383 try {
7384 CarrierConfigManager configManager =
7385 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7388 } finally {
7389 Binder.restoreCallingIdentity(identity);
7390 }
Andrew Leea1239f22015-03-02 17:44:07 -08007391 }
7392
7393 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007394 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007396 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 return false;
7398 }
7399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 CarrierConfigManager configManager =
7403 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007404 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
7408 }
Andrew Leea1239f22015-03-02 17:44:07 -08007409 }
7410
Andrew Lee9431b832015-03-09 18:46:45 -07007411 @Override
7412 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007413 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007414 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007415 }
7416
7417 @Override
7418 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 final long identity = Binder.clearCallingIdentity();
7420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007421 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 } finally {
7423 Binder.restoreCallingIdentity(identity);
7424 }
Andrew Lee9431b832015-03-09 18:46:45 -07007425 }
7426
Hall Liuf6668912018-10-31 17:05:23 -07007427 /**
7428 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7429 * support for the feature and device firmware support.
7430 *
7431 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7432 */
7433 @Override
7434 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 final Phone phone = getPhone(subscriptionId);
7437 if (phone == null) {
7438 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7439 return false;
7440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7444 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 return isCarrierSupported && isDeviceSupported;
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Hall Liu98187582018-01-22 19:15:32 -08007450 }
7451
Hall Liuf6668912018-10-31 17:05:23 -07007452 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007453 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7454 * RTT setting, will return true if the device and carrier both support RTT.
7455 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007456 */
7457 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 final long identity = Binder.clearCallingIdentity();
7459 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007460 boolean isRttSupported = isRttSupported(subscriptionId);
7461 boolean isUserRttSettingOn = Settings.Secure.getInt(
7462 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7463 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7464 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7465 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007469 }
7470
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007471 @Deprecated
7472 @Override
7473 public String getDeviceId(String callingPackage) {
7474 return getDeviceIdWithFeature(callingPackage, null);
7475 }
7476
Sanket Padawe7310cc72015-01-14 09:53:20 -08007477 /**
7478 * Returns the unique device ID of phone, for example, the IMEI for
7479 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7480 *
7481 * <p>Requires Permission:
7482 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7483 */
7484 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007486 try {
7487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7488 } catch (SecurityException se) {
7489 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7490 throw new SecurityException("Package " + callingPackage + " does not belong to "
7491 + Binder.getCallingUid());
7492 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007493 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007494 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007495 return null;
7496 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007497 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007498 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007500 return null;
7501 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 return phone.getDeviceId();
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007509 }
7510
Ping Sunc67b7c22016-03-02 19:16:45 +08007511 /**
7512 * {@hide}
7513 * Returns the IMS Registration Status on a particular subid
7514 *
7515 * @param subId
7516 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007517 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007518 Phone phone = getPhone(subId);
7519 if (phone != null) {
7520 return phone.isImsRegistered();
7521 } else {
7522 return false;
7523 }
7524 }
7525
Santos Cordon7a1885b2015-02-03 11:15:19 -08007526 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007527 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007531 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7532 }
7533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
7539 }
7540
7541 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007542 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007543 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007544 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007545 mApp,
7546 subscriptionId,
7547 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007548 final long identity = Binder.clearCallingIdentity();
7549 try {
7550 Phone phone = getPhone(subscriptionId);
7551 if (phone == null) {
7552 return null;
7553 }
7554 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
7557 }
7558 }
7559
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007560 /**
7561 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007562 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007563 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 Phone phone = getPhone(subId);
7567 if (phone != null) {
7568 return phone.isWifiCallingEnabled();
7569 } else {
7570 return false;
7571 }
7572 } finally {
7573 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007574 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007575 }
7576
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007577 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007578 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007579 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007580 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 Phone phone = getPhone(subId);
7584 if (phone != null) {
7585 return phone.isVideoEnabled();
7586 } else {
7587 return false;
7588 }
7589 } finally {
7590 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007591 }
7592 }
7593
7594 /**
7595 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7596 * defined in {@link ImsRegistrationImplBase}.
7597 */
7598 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 Phone phone = getPhone(subId);
7602 if (phone != null) {
7603 return phone.getImsRegistrationTech();
7604 } else {
7605 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7606 }
7607 } finally {
7608 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007609 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007610 }
7611
Stuart Scott8eef64f2015-04-08 15:13:54 -07007612 @Override
Sarah Chinecc78c42022-03-31 21:16:48 -07007613 public void factoryReset(int subId, String callingPackage) {
paulhu5a773602019-08-23 19:17:33 +08007614 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007615 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7616 return;
7617 }
Kai Shif70f46f2021-03-03 13:59:46 -08007618 Phone defaultPhone = getDefaultPhone();
7619 if (defaultPhone != null) {
7620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7621 mApp, getDefaultPhone().getSubId(), "factoryReset");
7622 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007623 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624
Svet Ganovcc087f82015-05-12 20:35:54 -07007625 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007626 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7627 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007628 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sarah Chinecc78c42022-03-31 21:16:48 -07007629 getDefaultDataEnabled(), callingPackage);
Svet Ganovcc087f82015-05-12 20:35:54 -07007630 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007631 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007632 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007634 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007635 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007636 // There has been issues when Sms raw table somehow stores orphan
7637 // fragments. They lead to garbled message when new fragments come
7638 // in and combined with those stale ones. In case this happens again,
7639 // user can reset all network settings which will clean up this table.
7640 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007641 // Clean up IMS settings as well here.
7642 int slotId = getSlotIndex(subId);
7643 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7644 ImsManager.getInstance(mApp, slotId).factoryReset();
7645 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007646
Kai Shif70f46f2021-03-03 13:59:46 -08007647 if (defaultPhone == null) {
7648 return;
7649 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007650 // Erase modem config if erase modem on network setting is enabled.
7651 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7652 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7653 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007654 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007655 }
Kai Shif70f46f2021-03-03 13:59:46 -08007656
7657 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007660 }
7661 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007662
SongFerngWangfd89b102021-05-27 22:44:54 +08007663 @VisibleForTesting
7664 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7665 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7666 return;
7667 }
7668 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7669 RILConstants.PREFERRED_NETWORK_MODE);
7670 SubscriptionManager.setSubscriptionProperty(subId,
7671 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7672 "user=" + defaultNetworkType);
7673 phone.loadAllowedNetworksFromSubscriptionDatabase();
7674 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7675 defaultNetworkType, null);
7676 }
7677
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007678 private void cleanUpSmsRawTable(Context context) {
7679 ContentResolver resolver = context.getContentResolver();
7680 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7681 resolver.delete(uri, null, null);
7682 }
7683
Narayan Kamath1c496c22015-04-16 14:40:19 +01007684 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007685 public String getSimLocaleForSubscriber(int subId) {
7686 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7687 final Phone phone = getPhone(subId);
7688 if (phone == null) {
7689 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007690 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007692 final long identity = Binder.clearCallingIdentity();
7693 try {
Jack Yudf049d72022-12-02 22:48:35 -08007694 SubscriptionInfo info;
7695 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7696 info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId,
7697 phone.getContext().getOpPackageName(),
7698 phone.getContext().getAttributionTag());
7699 if (info == null) {
7700 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7701 return null;
7702 }
7703 } else {
7704 info = mSubscriptionController.getActiveSubscriptionInfo(subId,
7705 phone.getContext().getOpPackageName(),
7706 phone.getContext().getAttributionTag());
7707 if (info == null) {
7708 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7709 return null;
7710 }
chen xu6291c472019-02-04 12:55:53 -08007711 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 // Try and fetch the locale from the carrier properties or from the SIM language
7713 // preferences (EF-PL and EF-LI)...
7714 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007715 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007716 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7717 if (localeFromDefaultSim != null) {
7718 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7719 if (DBG) log("Using locale from subId: " + subId + " locale: "
7720 + localeFromDefaultSim);
tom hsu22b7c3e2022-10-27 00:10:04 +08007721 return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim);
chen xu5d3637b2019-01-21 23:31:38 -08007722 } else {
7723 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 }
7725 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 // The SIM language preferences only store a language (e.g. fr = French), not an
7728 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7729 // the SIM and carrier preferences does not include a country we add the country
7730 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007731 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007733 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
tom hsu22b7c3e2022-10-27 00:10:04 +08007734 return matchLocaleFromSupportedLocaleList(phone, mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 }
7736
7737 if (DBG) log("No locale found - returning null");
7738 return null;
7739 } finally {
7740 Binder.restoreCallingIdentity(identity);
7741 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007742 }
7743
tom hsue9360cd2022-09-29 23:49:21 +08007744 @VisibleForTesting
tom hsu22b7c3e2022-10-27 00:10:04 +08007745 String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) {
tom hsue9360cd2022-09-29 23:49:21 +08007746 String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales(
tom hsu22b7c3e2022-10-27 00:10:04 +08007747 phone.getContext());
tom hsue9360cd2022-09-29 23:49:21 +08007748 for (String localeTag : supportedLocale) {
tom hsu22b7c3e2022-10-27 00:10:04 +08007749 if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag))
7750 && TextUtils.equals(inputLocale.getCountry(),
tom hsue9360cd2022-09-29 23:49:21 +08007751 Locale.forLanguageTag(localeTag).getCountry())) {
7752 return localeTag;
7753 }
7754 }
7755 return inputLocale.toLanguageTag();
7756 }
7757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 /**
7759 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7760 */
7761 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Jack Yudf049d72022-12-02 22:48:35 -08007762 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7763 return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList(
7764 mApp.getOpPackageName(), mApp.getAttributionTag());
7765 }
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007766 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007767 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007768 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007769
Gary Jian3aa9a762022-01-24 16:41:19 +08007770 private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null;
7771 private ModemActivityInfo mLastModemActivityInfo = null;
Chenjie Yu1ba97252018-01-11 18:16:20 -08007772
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007773 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007774 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7775 * representing the state of the modem.
7776 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007777 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7778 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007779 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007780 */
7781 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007782 public void requestModemActivityInfo(ResultReceiver result) {
7783 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785
7786 final long identity = Binder.clearCallingIdentity();
7787 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007788 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007791 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007792 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007793
Siddharth Rayb8114062018-06-17 15:02:38 -07007794 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7795 // less than total activity duration.
7796 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7797 if (info == null) {
7798 return false;
7799 }
7800 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007801 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7802 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7803
Siddharth Rayb8114062018-06-17 15:02:38 -07007804 return (info.isValid()
7805 && (info.getSleepTimeMillis() <= activityDurationMs)
7806 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007807 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007808 && (totalTxTimeMs <= activityDurationMs));
7809 }
7810
Gary Jian3aa9a762022-01-24 16:41:19 +08007811 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) {
7812 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7813 int[] txTimeMs = info.getTransmitTimeMillis(rat, freq);
7814 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq);
7815
7816 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7817 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7818 }
7819
7820 mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs);
7821 mLastModemActivityInfo.setReceiveTimeMillis(
7822 rat,
7823 freq,
7824 info.getReceiveTimeMillis(rat, freq)
7825 + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq));
7826 }
7827
7828 private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) {
7829 int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()];
7830 int[] txTimeMs = info.getTransmitTimeMillis(rat);
7831 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat);
7832
7833 for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) {
7834 mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl];
7835 }
7836 mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs);
7837 mLastModemActivityInfo.setReceiveTimeMillis(
7838 rat,
7839 info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat));
7840 }
7841
7842 /**
7843 * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo
7844 * @param info recent ModemActivityInfo
7845 */
7846 private void mergeModemActivityInfo(ModemActivityInfo info) {
7847 List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>();
7848 ActivityStatsTechSpecificInfo mDeltaSpecificInfo;
7849 boolean matched;
7850 for (int i = 0; i < info.getSpecificInfoLength(); i++) {
7851 matched = false;
7852 int rat = info.getSpecificInfoRat(i);
7853 int freq = info.getSpecificInfoFrequencyRange(i);
7854 //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns
7855 //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original
7856 //if it already exists
7857 for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) {
7858 if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) {
7859 //Merged based on frequency range (MMWAVE vs SUB6) for 5G
7860 if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) {
7861 if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) {
7862 updateLastModemActivityInfo(info, rat, freq);
7863 matched = true;
7864 }
7865 } else {
7866 updateLastModemActivityInfo(info, rat);
7867 matched = true;
7868 }
7869 }
7870 }
7871
7872 if (!matched) {
7873 mDeltaSpecificInfo =
7874 new ActivityStatsTechSpecificInfo(
7875 rat,
7876 freq,
7877 info.getTransmitTimeMillis(rat, freq),
7878 (int) info.getReceiveTimeMillis(rat, freq));
7879 merged.addAll(Arrays.asList(mDeltaSpecificInfo));
7880 }
7881 }
7882 merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo));
7883 mLastModemActivitySpecificInfo =
7884 new ActivityStatsTechSpecificInfo[merged.size()];
7885 merged.toArray(mLastModemActivitySpecificInfo);
7886
7887 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
7888 mLastModemActivityInfo.setSleepTimeMillis(
7889 info.getSleepTimeMillis()
7890 + mLastModemActivityInfo.getSleepTimeMillis());
7891 mLastModemActivityInfo.setIdleTimeMillis(
7892 info.getIdleTimeMillis()
7893 + mLastModemActivityInfo.getIdleTimeMillis());
7894 }
7895
Jack Yu85bd38a2015-11-09 11:34:32 -08007896 /**
Jack Yu85bd38a2015-11-09 11:34:32 -08007897 * Returns the service state information on specified subscription.
7898 */
7899 @Override
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007900 public ServiceState getServiceStateForSubscriber(int subId,
7901 boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess,
7902 String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007904 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007905 return null;
7906 }
7907
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007908 boolean hasFinePermission = false;
7909 boolean hasCoarsePermission = false;
7910 if (!renounceFineLocationAccess) {
7911 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7912 LocationAccessPolicy.checkLocationPermission(mApp,
7913 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7914 .setCallingPackage(callingPackage)
7915 .setCallingFeatureId(callingFeatureId)
7916 .setCallingPid(Binder.getCallingPid())
7917 .setCallingUid(Binder.getCallingUid())
7918 .setMethod("getServiceStateForSubscriber")
7919 .setLogAsInfo(true)
7920 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7921 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7922 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7923 .build());
7924 hasFinePermission =
7925 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7926 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007927
Sooraj Sasindran2250dc02021-11-10 16:42:01 -08007928 if (!renounceCoarseLocationAccess) {
7929 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7930 LocationAccessPolicy.checkLocationPermission(mApp,
7931 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7932 .setCallingPackage(callingPackage)
7933 .setCallingFeatureId(callingFeatureId)
7934 .setCallingPid(Binder.getCallingPid())
7935 .setCallingUid(Binder.getCallingUid())
7936 .setMethod("getServiceStateForSubscriber")
7937 .setLogAsInfo(true)
7938 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7939 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7940 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
7941 .build());
7942 hasCoarsePermission =
7943 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7944 }
Hall Liuf19c44f2018-11-27 14:38:17 -08007945
Jack Yu479f40e2020-10-27 21:29:25 -07007946 final Phone phone = getPhone(subId);
7947 if (phone == null) {
7948 return null;
7949 }
7950
Jordan Liu0f2bc442020-11-18 16:47:37 -08007951 final long identity = Binder.clearCallingIdentity();
7952
Jack Yu479f40e2020-10-27 21:29:25 -07007953 boolean isCallingPackageDataService = phone.getDataServicePackages()
7954 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007956 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
Jack Yudf049d72022-12-02 22:48:35 -08007957 if (PhoneFactory.isSubscriptionManagerServiceEnabled()) {
7958 SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance()
7959 .getSubscriptionInfoInternal(subId);
7960 if (subInfo == null || !subInfo.isActive()) {
7961 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
7962 + "subId=" + subId);
7963 return null;
7964 }
7965 } else {
7966 if (!mSubscriptionController.isActiveSubId(subId, callingPackage,
7967 callingFeatureId)) {
7968 Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive "
7969 + "subId=" + subId);
7970 return null;
7971 }
Jordan Liuc437b192020-08-17 10:59:12 -07007972 }
7973
Hall Liuf19c44f2018-11-27 14:38:17 -08007974 ServiceState ss = phone.getServiceState();
7975
7976 // Scrub out the location info in ServiceState depending on what level of access
7977 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007978 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007979 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7980 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007984 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007985
7986 /**
7987 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7988 *
7989 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7990 * voicemail ringtone.
7991 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7992 * PhoneAccount.
7993 */
7994 @Override
7995 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 final long identity = Binder.clearCallingIdentity();
7997 try {
7998 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7999 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008007 }
8008
8009 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008010 * Sets the per-account voicemail ringtone.
8011 *
8012 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8013 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8014 *
8015 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8016 * voicemail ringtone.
8017 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8018 * PhoneAccount.
8019 */
8020 @Override
8021 public void setVoicemailRingtoneUri(String callingPackage,
8022 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008025 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8026 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8028 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8029 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008030 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031
8032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8035 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008036 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 }
8038 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008041 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008042 }
8043
8044 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008045 * Returns whether vibration is set for voicemail notification in Phone settings.
8046 *
8047 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8048 * voicemail vibration setting.
8049 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8050 */
8051 @Override
8052 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8056 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8061 } finally {
8062 Binder.restoreCallingIdentity(identity);
8063 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008064 }
8065
Youhan Wange64578a2016-05-02 15:32:42 -07008066 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008067 * Sets the per-account voicemail vibration.
8068 *
8069 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8070 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8071 *
8072 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8073 * voicemail vibration setting.
8074 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8075 * specific PhoneAccount.
8076 */
8077 @Override
8078 public void setVoicemailVibrationEnabled(String callingPackage,
8079 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008080 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008082 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8083 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8085 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8086 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008087 }
8088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8092 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008093 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008094 }
8095 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008098 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008099 }
8100
8101 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008102 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8103 *
8104 * @throws SecurityException if the caller does not have the required permission
8105 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008106 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008108 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008109 }
8110
8111 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008112 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8113 * permission.
8114 *
8115 * @throws SecurityException if the caller does not have the required permission
8116 */
8117 private void enforceSendSmsPermission() {
8118 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8119 }
8120
8121 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008122 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008123 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008124 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008125 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008126 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008130 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 if (componentName == null) {
8132 throw new SecurityException(
8133 "Caller not current active visual voicemail package[null]");
8134 }
8135 String vvmPackage = componentName.getPackageName();
8136 if (!callingPackage.equals(vvmPackage)) {
Hui Wang7f657552022-08-16 16:58:25 +00008137 throw new SecurityException("Caller not current active visual voicemail package");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 }
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008141 }
8142 }
8143
8144 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008145 * Return the application ID for the app type.
8146 *
8147 * @param subId the subscription ID that this request applies to.
8148 * @param appType the uicc app type.
8149 * @return Application ID for specificied app type, or null if no uicc.
8150 */
8151 @Override
8152 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008153 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008154 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008157 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158 if (phone == null) {
8159 return null;
8160 }
8161 String aid = null;
8162 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008163 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 .getApplicationByType(appType).getAid();
8165 } catch (Exception e) {
8166 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8167 }
8168 return aid;
8169 } finally {
8170 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008171 }
Youhan Wange64578a2016-05-02 15:32:42 -07008172 }
8173
Youhan Wang4001d252016-05-11 10:29:41 -07008174 /**
8175 * Return the Electronic Serial Number.
8176 *
8177 * @param subId the subscription ID that this request applies to.
8178 * @return ESN or null if error.
8179 */
8180 @Override
8181 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008182 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008183 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184
8185 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008186 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 if (phone == null) {
8188 return null;
8189 }
8190 String esn = null;
8191 try {
8192 esn = phone.getEsn();
8193 } catch (Exception e) {
8194 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8195 }
8196 return esn;
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008199 }
Youhan Wang4001d252016-05-11 10:29:41 -07008200 }
8201
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008202 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008203 * Return the Preferred Roaming List Version.
8204 *
8205 * @param subId the subscription ID that this request applies to.
8206 * @return PRLVersion or null if error.
8207 */
8208 @Override
8209 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008210 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008211 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212
8213 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008214 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008215 if (phone == null) {
8216 return null;
8217 }
8218 String cdmaPrlVersion = null;
8219 try {
8220 cdmaPrlVersion = phone.getCdmaPrlVersion();
8221 } catch (Exception e) {
8222 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8223 }
8224 return cdmaPrlVersion;
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008227 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008228 }
8229
8230 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008231 * Get snapshot of Telephony histograms
8232 * @return List of Telephony histograms
8233 * @hide
8234 */
8235 @Override
8236 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8238 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008239
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 return RIL.getTelephonyRILTimingHistograms();
8243 } finally {
8244 Binder.restoreCallingIdentity(identity);
8245 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008246 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247
8248 /**
8249 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008250 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8251 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008252 * Require system privileges. In the future we may add this to carrier APIs.
8253 *
Michele Berionne482f8202018-11-27 18:57:59 -08008254 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008255 */
8256 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008257 @TelephonyManager.SetCarrierRestrictionResult
8258 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008259 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008261
Michele Berionne482f8202018-11-27 18:57:59 -08008262 if (carrierRestrictionRules == null) {
8263 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008264 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 final long identity = Binder.clearCallingIdentity();
8267 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008268 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008269 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008273 }
8274
8275 /**
8276 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008277 * Get the allowed carrier list and the excluded carrier list, including the priority between
8278 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008279 * Require system privileges. In the future we may add this to carrier APIs.
8280 *
Michele Berionne482f8202018-11-27 18:57:59 -08008281 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008282 */
8283 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008284 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008285 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287
8288 final long identity = Binder.clearCallingIdentity();
8289 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008290 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8291 if (response instanceof CarrierRestrictionRules) {
8292 return (CarrierRestrictionRules) response;
8293 }
8294 // Response is an Exception of some kind,
8295 // which is signalled to the user as a NULL retval
8296 return null;
8297 } catch (Exception e) {
8298 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8299 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008303 }
8304
fionaxu59545b42016-05-25 15:53:37 -07008305 /**
fionaxu59545b42016-05-25 15:53:37 -07008306 * Action set from carrier signalling broadcast receivers to enable/disable radio
8307 * @param subId the subscription ID that this action applies to.
8308 * @param enabled control enable or disable radio.
8309 * {@hide}
8310 */
8311 @Override
8312 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8313 enforceModifyPermission();
8314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315
8316 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008317 if (phone == null) {
8318 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8319 return;
8320 }
8321 try {
8322 phone.carrierActionSetRadioEnabled(enabled);
8323 } catch (Exception e) {
8324 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 } finally {
8326 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008327 }
8328 }
8329
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008330 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008331 * Enable or disable Voice over NR (VoNR)
8332 * @param subId the subscription ID that this action applies to.
8333 * @param enabled enable or disable VoNR.
8334 * @return operation result.
8335 */
8336 @Override
8337 public int setVoNrEnabled(int subId, boolean enabled) {
8338 enforceModifyPermission();
8339 final Phone phone = getPhone(subId);
8340
8341 final long identity = Binder.clearCallingIdentity();
8342 if (phone == null) {
8343 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8344 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8345 }
8346
8347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8348 try {
8349 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8350 workSource);
8351 if (DBG) log("setVoNrEnabled result: " + result);
Gary Jian8dd305f2021-10-14 16:31:35 +08008352
8353 if (result == TelephonyManager.ENABLE_VONR_SUCCESS) {
8354 if (DBG) {
8355 log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled);
8356 }
8357 SubscriptionManager.setSubscriptionProperty(
8358 subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED,
8359 (enabled ? "1" : "0"));
8360 }
8361
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008362 return result;
8363 } finally {
8364 Binder.restoreCallingIdentity(identity);
8365 }
8366 }
8367
8368 /**
8369 * Is voice over NR enabled
8370 * @return true if VoNR is enabled else false
8371 */
8372 @Override
8373 public boolean isVoNrEnabled(int subId) {
8374 enforceReadPrivilegedPermission("isVoNrEnabled");
8375 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8379 null, subId, workSource);
8380 if (DBG) log("isVoNrEnabled: " + isEnabled);
8381 return isEnabled;
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008388 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8389 * network status based on which carrier apps could apply actions accordingly,
8390 * enable/disable default url handler for example.
8391 *
8392 * @param subId the subscription ID that this action applies to.
8393 * @param report control start/stop reporting the default network status.
8394 * {@hide}
8395 */
8396 @Override
8397 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8398 enforceModifyPermission();
8399 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400
8401 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008402 if (phone == null) {
8403 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8404 return;
8405 }
8406 try {
8407 phone.carrierActionReportDefaultNetworkStatus(report);
8408 } catch (Exception e) {
8409 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410 } finally {
8411 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008412 }
8413 }
8414
8415 /**
fionaxud9622282017-07-17 17:51:30 -07008416 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8417 * @param subId the subscription ID that this action applies to.
8418 * {@hide}
8419 */
8420 @Override
8421 public void carrierActionResetAll(int subId) {
8422 enforceModifyPermission();
8423 final Phone phone = getPhone(subId);
8424 if (phone == null) {
8425 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8426 return;
8427 }
8428 try {
8429 phone.carrierActionResetAll();
8430 } catch (Exception e) {
8431 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8432 }
8433 }
8434
8435 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008436 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8437 * bug report is being generated.
8438 */
8439 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008440 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8442 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008443 writer.println("Permission Denial: can't dump Phone from pid="
8444 + Binder.getCallingPid()
8445 + ", uid=" + Binder.getCallingUid()
8446 + "without permission "
8447 + android.Manifest.permission.DUMP);
8448 return;
8449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008450 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008451 }
Jack Yueb89b242016-06-22 13:27:47 -07008452
Brad Ebingerdac2f002018-04-03 15:17:52 -07008453 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008454 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8455 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8456 @NonNull String[] args) {
8457 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8458 this, in.getFileDescriptor(), out.getFileDescriptor(),
8459 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008460 }
8461
Jack Yueb89b242016-06-22 13:27:47 -07008462 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008463 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008464 * @param subId Subscription index
Sarah Chinecc78c42022-03-31 21:16:48 -07008465 * @param reason The reason the data enable change is taking place.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008466 * @param enabled True if enabling the data, otherwise disabling.
Sarah Chinecc78c42022-03-31 21:16:48 -07008467 * @param callingPackage The package that changed the data enabled state.
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008468 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008469 */
8470 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008471 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sarah Chinecc78c42022-03-31 21:16:48 -07008472 boolean enabled, String callingPackage) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008473 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8474 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8475 try {
8476 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008477 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008478 } catch (SecurityException se) {
8479 enforceModifyPermission();
8480 }
8481 } else {
8482 enforceModifyPermission();
8483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 Phone phone = getPhone(subId);
8488 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008489 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8490 phone.carrierActionSetMeteredApnsEnabled(enabled);
8491 } else {
Jack Yuabb10902022-07-31 00:43:21 -07008492 phone.getDataSettingsManager().setDataEnabled(
8493 reason, enabled, callingPackage);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008495 }
8496 } finally {
8497 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008498 }
8499 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008500
8501 /**
8502 * Get Client request stats
8503 * @return List of Client Request Stats
8504 * @hide
8505 */
8506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008507 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8508 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008510 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008511 return null;
8512 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008513 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 if (phone != null) {
8518 return phone.getClientRequestStats();
8519 }
8520
8521 return null;
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
8524 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008525 }
8526
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008527 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008528 String packageName = mApp.getPackageManager().getNameForUid(uid);
Hunter Knepshieldd03383b2022-03-29 22:47:54 +00008529 if (uid == Process.ROOT_UID && packageName == null) {
8530 // Downstream WorkSource attribution inside the RIL requires both a UID and package name
8531 // to be set for wakelock tracking, otherwise RIL requests fail with a runtime
8532 // exception. ROOT_UID seems not to have a valid package name returned by
8533 // PackageManager, so just fake it here to avoid issues when running telephony shell
8534 // commands that plumb through the RIL as root, like so:
8535 // $ adb root
8536 // $ adb shell cmd phone ...
8537 packageName = "root";
8538 }
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008539 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008540 }
Jack Yueb4124c2017-02-16 15:32:43 -08008541
8542 /**
Grace Chen70990072017-03-24 17:21:30 -07008543 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008544 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008545 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008546 * @param state State of SIM (power down, power up, pass through)
8547 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8548 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8549 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008550 *
8551 **/
8552 @Override
Grace Chen70990072017-03-24 17:21:30 -07008553 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008554 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008555 Phone phone = PhoneFactory.getPhone(slotIndex);
8556
vagdeviaf9a5b92018-08-15 16:01:53 -07008557 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008562 phone.setSimPowerState(state, null, workSource);
8563 }
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
8569 /**
8570 * Set SIM card power state.
8571 *
8572 * @param slotIndex SIM slot id.
8573 * @param state State of SIM (power down, power up, pass through)
8574 * @param callback callback to trigger after success or failure
8575 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8576 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8577 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8578 *
8579 **/
8580 @Override
8581 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8582 IIntegerConsumer callback) {
8583 enforceModifyPermission();
8584 Phone phone = PhoneFactory.getPhone(slotIndex);
8585
8586 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8587
8588 final long identity = Binder.clearCallingIdentity();
8589 try {
8590 if (phone != null) {
8591 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8592 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 }
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008596 }
8597 }
Shuo Qiandd210312017-04-12 22:11:33 +00008598
Tyler Gunn65d45c22017-06-05 11:22:26 -07008599 private boolean isUssdApiAllowed(int subId) {
8600 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008601 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008602 if (configManager == null) {
8603 return false;
8604 }
8605 PersistableBundle pb = configManager.getConfigForSubId(subId);
8606 if (pb == null) {
8607 return false;
8608 }
8609 return pb.getBoolean(
8610 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8611 }
8612
Shuo Qiandd210312017-04-12 22:11:33 +00008613 /**
8614 * Check if phone is in emergency callback mode
8615 * @return true if phone is in emergency callback mode
8616 * @param subId sub id
8617 */
goneil9c5f4872017-12-05 14:07:56 -08008618 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008619 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008620 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008621 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 if (phone != null) {
8626 return phone.isInEcm();
8627 } else {
8628 return false;
8629 }
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008632 }
8633 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008634
8635 /**
8636 * Get the current signal strength information for the given subscription.
8637 * Because this information is not updated when the device is in a low power state
8638 * it should not be relied-upon to be current.
8639 * @param subId Subscription index
8640 * @return the most recent cached signal strength info from the modem
8641 */
8642 @Override
8643 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 Phone p = getPhone(subId);
8647 if (p == null) {
8648 return null;
8649 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008650
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008651 return p.getSignalStrength();
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008655 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008656
Pengquan Meng77b7f132018-08-22 14:49:57 -07008657 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008658 * Get the current modem radio state for the given slot.
8659 * @param slotIndex slot index.
8660 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008661 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008662 * @return the current radio power state from the modem
8663 */
8664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008665 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008666 Phone phone = PhoneFactory.getPhone(slotIndex);
8667 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8669 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008670 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8671 }
8672
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 return phone.getRadioPowerState();
8676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
8679 }
8680 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8681 }
8682
8683 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008684 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8685 *
8686 * <p>Requires one of the following permissions:
8687 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008688 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE},
Pengquan Meng77b7f132018-08-22 14:49:57 -07008689 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8690 * privileges.
8691 *
8692 * @param subId subscription id
8693 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8694 * {@code false}.
8695 */
8696 @Override
8697 public boolean isDataRoamingEnabled(int subId) {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008698 String functionName = "isDataRoamingEnabled";
Shuo Qian093013d2020-08-13 15:42:55 -07008699 try {
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008700 try {
8701 mApp.enforceCallingOrSelfPermission(
8702 android.Manifest.permission.ACCESS_NETWORK_STATE,
8703 functionName);
8704 } catch (Exception e) {
8705 mApp.enforceCallingOrSelfPermission(
8706 permission.READ_BASIC_PHONE_STATE, functionName);
8707 }
Shuo Qian093013d2020-08-13 15:42:55 -07008708 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008709 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran5d051bf2021-11-05 13:14:15 -07008710 mApp, subId, functionName);
Shuo Qian093013d2020-08-13 15:42:55 -07008711 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008712
Pengquan Menga1bb6272018-09-06 09:59:22 -07008713 boolean isEnabled = false;
8714 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008715 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008716 Phone phone = getPhone(subId);
8717 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008718 } finally {
8719 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008720 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008721 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008722 }
8723
8724
8725 /**
8726 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8727 *
8728 * <p> Requires permission:
8729 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8730 * privileges.
8731 *
8732 * @param subId subscription id
8733 * @param isEnabled {@code true} means enable, {@code false} means disable.
8734 */
8735 @Override
8736 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8738 mApp, subId, "setDataRoamingEnabled");
8739
Pengquan Menga1bb6272018-09-06 09:59:22 -07008740 final long identity = Binder.clearCallingIdentity();
8741 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008742 Phone phone = getPhone(subId);
8743 if (phone != null) {
8744 phone.setDataRoamingEnabled(isEnabled);
8745 }
8746 } finally {
8747 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008748 }
8749 }
8750
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008751 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008752 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008753 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008754 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008755 mApp, subId, "isManualNetworkSelectionAllowed");
8756
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008757 boolean isAllowed = true;
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008760 Phone phone = getPhone(subId);
8761 if (phone != null) {
8762 isAllowed = phone.isCspPlmnEnabled();
8763 }
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 return isAllowed;
8768 }
8769
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008770 private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) {
8771 UiccProfile profile = port.getUiccProfile();
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008772 if (profile == null) {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008773 return false;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008774 }
Hunter Knepshieldcad7f0b2021-12-13 15:08:35 -08008775 Phone phone = PhoneFactory.getPhone(profile.getPhoneId());
8776 if (phone == null) {
8777 return false;
8778 }
8779 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
8780 return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage)
8781 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00008782 }
8783
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008784 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008785 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008786 // Verify that the callingPackage belongs to the calling UID
Jordan Liu4cda4552020-03-23 11:55:07 -07008787 mApp.getSystemService(AppOpsManager.class)
8788 .checkPackage(Binder.getCallingUid(), callingPackage);
8789
Jordan Liu1e142fc2019-04-22 15:10:43 -07008790 boolean hasReadPermission = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008791 boolean isIccIdAccessRestricted = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008792 try {
8793 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008794 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008795 } catch (SecurityException e) {
8796 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8797 // has carrier privileges on an active UICC
Rambo Wange7209ce2022-02-23 13:41:02 -08008798 if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage)
Jordan Liuc65bc952019-02-12 17:54:02 -08008799 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008800 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008801 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008802 }
sandeepjsb6c87872021-09-27 15:34:44 +00008803 // checking compatibility, if calling app's target SDK is T and beyond.
8804 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8805 Binder.getCallingUid())) {
8806 isIccIdAccessRestricted = true;
8807 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008808 final long identity = Binder.clearCallingIdentity();
8809 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008810 UiccController uiccController = UiccController.getInstance();
8811 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008812 if (hasReadPermission) {
8813 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008814 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008815
8816 // Remove private info if the caller doesn't have access
8817 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8818 for (UiccCardInfo cardInfo : cardInfos) {
sandeepjsb6c87872021-09-27 15:34:44 +00008819 //setting the value after compatibility check
8820 cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted);
Jordan Liu1e142fc2019-04-22 15:10:43 -07008821 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8822 // is available
sandeepjsb6c87872021-09-27 15:34:44 +00008823 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex());
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008824 if (card == null) {
8825 // assume no access if the card is unavailable
sandeepjsb6c87872021-09-27 15:34:44 +00008826 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008827 continue;
8828 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008829 Collection<UiccPortInfo> portInfos = cardInfo.getPorts();
8830 if (portInfos.isEmpty()) {
sandeepjsb6c87872021-09-27 15:34:44 +00008831 filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008832 continue;
Jordan Liu1e142fc2019-04-22 15:10:43 -07008833 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008834 List<UiccPortInfo> uiccPortInfos = new ArrayList<>();
8835 for (UiccPortInfo portInfo : portInfos) {
8836 UiccPort port = uiccController.getUiccPortForSlot(
8837 cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex());
8838 if (port == null) {
8839 // assume no access if port is null
8840 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8841 continue;
8842 }
8843 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
8844 uiccPortInfos.add(portInfo);
8845 } else {
8846 uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo));
8847 }
8848 }
8849 filteredInfos.add(new UiccCardInfo(
8850 cardInfo.isEuicc(),
8851 cardInfo.getCardId(),
8852 null,
8853 cardInfo.getPhysicalSlotIndex(),
8854 cardInfo.isRemovable(),
8855 cardInfo.isMultipleEnabledProfilesSupported(),
8856 uiccPortInfos));
Jordan Liu1e142fc2019-04-22 15:10:43 -07008857 }
8858 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008859 } finally {
8860 Binder.restoreCallingIdentity(identity);
8861 }
8862 }
8863
sandeepjsb6c87872021-09-27 15:34:44 +00008864 /**
8865 * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are
8866 * generally private and require carrier privileges to view.
8867 *
8868 * @hide
8869 */
8870 @NonNull
8871 public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) {
8872 List<UiccPortInfo> portinfo = new ArrayList<>();
8873 for (UiccPortInfo portinfos : cardInfo.getPorts()) {
8874 portinfo.add(getUiccPortInfoUnPrivileged(portinfos));
8875 }
8876 return new UiccCardInfo(
8877 cardInfo.isEuicc(),
8878 cardInfo.getCardId(),
8879 null,
8880 cardInfo.getPhysicalSlotIndex(),
8881 cardInfo.isRemovable(),
8882 cardInfo.isMultipleEnabledProfilesSupported(),
8883 portinfo
8884 );
8885 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008886
sandeepjsb6c87872021-09-27 15:34:44 +00008887 /**
8888 * @hide
8889 * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}.
8890 * These values are generally private and require carrier privileges to view.
8891 */
8892 @NonNull
8893 public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) {
8894 return new UiccPortInfo(
8895 UiccPortInfo.ICCID_REDACTED,
8896 portInfo.getPortIndex(),
8897 portInfo.getLogicalSlotIndex(),
8898 portInfo.isActive()
8899 );
8900 }
8901 @Override
8902 public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
sandeepjsa208e3b2021-11-17 04:05:58 +00008903 // Verify that the callingPackage belongs to the calling UID
sandeepjsb6c87872021-09-27 15:34:44 +00008904 mApp.getSystemService(AppOpsManager.class)
8905 .checkPackage(Binder.getCallingUid(), callingPackage);
8906
sandeepjsb6c87872021-09-27 15:34:44 +00008907 boolean isLogicalSlotAccessRestricted = false;
sandeepjsb6c87872021-09-27 15:34:44 +00008908
Aman Guptaf3c90b32022-03-17 04:54:16 +00008909 // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as
8910 // we are reading iccId which is PII data.
8911 enforceReadPrivilegedPermission("getUiccSlotsInfo");
sandeepjsb6c87872021-09-27 15:34:44 +00008912
8913 // checking compatibility, if calling app's target SDK is T and beyond.
8914 if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO,
8915 Binder.getCallingUid())) {
8916 isLogicalSlotAccessRestricted = true;
8917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008918 final long identity = Binder.clearCallingIdentity();
8919 try {
8920 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Muralidhar Reddyd196bbf2022-01-17 17:56:30 +00008921 if (slots == null || slots.length == 0) {
8922 Rlog.i(LOG_TAG, "slots is null or empty.");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008923 return null;
8924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008925 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8926 for (int i = 0; i < slots.length; i++) {
8927 UiccSlot slot = slots[i];
8928 if (slot == null) {
8929 continue;
8930 }
8931
Jordan Liu7be7e652019-05-06 18:55:02 +00008932 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008933 UiccCard card = slot.getUiccCard();
8934 if (card != null) {
8935 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008936 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008937 cardId = slot.getEid();
8938 if (TextUtils.isEmpty(cardId)) {
Aman Guptaf3c90b32022-03-17 04:54:16 +00008939 // If cardId is null, use iccId of default port as cardId.
8940 cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX);
Jordan Liu01bd00d2019-09-12 16:19:43 -07008941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 }
8943
Jordan Liu857451f2019-05-09 16:35:35 -07008944 if (cardId != null) {
8945 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8946 // if cardId is an EID, it's all digits so this is fine
8947 cardId = IccUtils.stripTrailingFs(cardId);
8948 }
8949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950 int cardState = 0;
8951 switch (slot.getCardState()) {
8952 case CARDSTATE_ABSENT:
8953 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8954 break;
8955 case CARDSTATE_PRESENT:
8956 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8957 break;
8958 case CARDSTATE_ERROR:
8959 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8960 break;
8961 case CARDSTATE_RESTRICTED:
8962 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8963 break;
8964 default:
8965 break;
8966
8967 }
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008968 List<UiccPortInfo> portInfos = new ArrayList<>();
8969 int[] portIndexes = slot.getPortList();
8970 for (int portIdx : portIndexes) {
8971 String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx,
Aman Guptaf3c90b32022-03-17 04:54:16 +00008972 callingPackage, /* hasReadPermission= */ true));
Muralidhar Reddyfbcff0c2022-01-19 13:07:57 +00008973 portInfos.add(new UiccPortInfo(iccId, portIdx,
8974 slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx)));
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008976 infos[i] = new UiccSlotInfo(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008977 slot.isEuicc(),
8978 cardId,
8979 cardState,
Jordan Liua2619582019-02-14 12:56:40 -08008980 slot.isExtendedApduSupported(),
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008981 slot.isRemovable(), portInfos);
sandeepjsb6c87872021-09-27 15:34:44 +00008982 //setting the value after compatibility check
8983 infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008984 }
8985 return infos;
8986 } finally {
8987 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008988 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008989 }
8990
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00008991 /* Returns null if doesn't have read permission or carrier privilege access. */
8992 private String getIccId(UiccSlot slot, int portIndex, String callingPackage,
8993 boolean hasReadPermission) {
8994 String iccId = slot.getIccId(portIndex);
8995 if (hasReadPermission) { // if has read permission
8996 return iccId;
8997 } else {
8998 if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) {
8999 UiccPort port = slot.getUiccCard().getUiccPort(portIndex);
9000 // if no read permission, checking carrier privilege access
9001 if (haveCarrierPrivilegeAccess(port, callingPackage)) {
9002 return iccId;
9003 }
9004 }
9005 }
9006 // No read permission or carrier privilege access.
9007 return UiccPortInfo.ICCID_REDACTED;
9008 }
9009
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009010 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009011 @Deprecated
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009012 public boolean switchSlots(int[] physicalSlots) {
9013 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009014
9015 final long identity = Binder.clearCallingIdentity();
9016 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009017 List<UiccSlotMapping> slotMappings = new ArrayList<>();
9018 for (int i = 0; i < physicalSlots.length; i++) {
9019 // Deprecated API, hence MEP is not supported. Adding default portIndex 0.
9020 slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX,
9021 physicalSlots[i], i));
9022 }
9023 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009024 } finally {
9025 Binder.restoreCallingIdentity(identity);
9026 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00009027 }
Jack Yu4c988042018-02-27 15:30:01 -08009028
9029 @Override
sandeepjsb6c87872021-09-27 15:34:44 +00009030 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
9031 public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) {
9032 enforceModifyPermission();
9033
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
Muralidhar Reddyeb809e32021-11-19 03:07:54 +00009036 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping);
sandeepjsb6c87872021-09-27 15:34:44 +00009037 } finally {
9038 Binder.restoreCallingIdentity(identity);
9039 }
9040 }
9041
9042 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08009043 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08009044 final long identity = Binder.clearCallingIdentity();
9045 try {
9046 return UiccController.getInstance().getCardIdForDefaultEuicc();
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
9051
Pengquan Meng85728fb2018-03-12 16:31:21 -07009052 /**
goneil47ffb6e2018-04-06 15:40:58 -07009053 * A test API to reload the UICC profile.
9054 *
9055 * <p>Requires that the calling app has permission
9056 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
9057 * @hide
9058 */
9059 @Override
9060 public void refreshUiccProfile(int subId) {
9061 enforceModifyPermission();
9062
9063 final long identity = Binder.clearCallingIdentity();
9064 try {
9065 Phone phone = getPhone(subId);
9066 if (phone == null) {
9067 return;
9068 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009069 UiccPort uiccPort = phone.getUiccPort();
9070 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07009071 return;
9072 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009073 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07009074 if (uiccProfile == null) {
9075 return;
9076 }
9077 uiccProfile.refresh();
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
9080 }
9081 }
9082
9083 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07009084 * Returns false if the mobile data is disabled by default, otherwise return true.
9085 */
9086 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009087 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009088 }
9089
9090 /**
9091 * Returns true if the data roaming is enabled by default, i.e the system property
9092 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
9093 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
9094 */
9095 private boolean getDefaultDataRoamingEnabled(int subId) {
9096 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009097 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07009098 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07009099 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
9100 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
9101 return isDataRoamingEnabled;
9102 }
9103
9104 /**
9105 * Returns the default network type for the given {@code subId}, if the default network type is
9106 * not set, return {@link Phone#PREFERRED_NT_MODE}.
9107 */
9108 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09009109 List<Integer> list = TelephonyProperties.default_network();
Jack Yudf049d72022-12-02 22:48:35 -08009110 int phoneId = SubscriptionManager.getPhoneId(subId);
Inseob Kim14bb3d02018-12-13 17:11:34 +09009111 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
9112 return list.get(phoneId);
9113 }
9114 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07009115 }
fionaxua13278b2018-03-21 00:08:13 -07009116
9117 @Override
9118 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07009119 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07009120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 final Phone phone = getPhone(subId);
9125 if (phone == null) {
9126 loge("setCarrierTestOverride fails with invalid subId: " + subId);
9127 return;
9128 }
Rambo Wang9c9ffdd2022-01-13 21:51:44 -08009129 CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker();
9130 if (cpt != null) {
9131 cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules);
9132 }
9133 // TODO(b/211796398): remove the legacy logic below once CPT migration is done.
chen xueaba88a2019-03-15 13:15:10 -07009134 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
9135 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07009136 if (carrierPrivilegeRules == null) {
9137 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
9138 } else {
9139 mCarrierPrivilegeTestOverrideSubIds.add(subId);
9140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009141 } finally {
9142 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009143 }
fionaxua13278b2018-03-21 00:08:13 -07009144 }
9145
9146 @Override
9147 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07009148 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08009149
9150 final long identity = Binder.clearCallingIdentity();
9151 try {
9152 final Phone phone = getPhone(subId);
9153 if (phone == null) {
9154 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
9155 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
9156 }
9157 return phone.getCarrierIdListVersion();
9158 } finally {
9159 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07009160 }
fionaxua13278b2018-03-21 00:08:13 -07009161 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07009162
9163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009164 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
9165 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009167 mApp, subId, callingPackage, callingFeatureId,
9168 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07009169 return -1;
9170 }
9171
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
9177 }
9178 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07009179
9180 @Override
9181 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08009182 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009183 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07009184 mApp, subId, "getCdmaRoamingMode");
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 }
9193
9194 @Override
9195 public boolean setCdmaRoamingMode(int subId, int mode) {
9196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9197 mApp, subId, "setCdmaRoamingMode");
9198
9199 final long identity = Binder.clearCallingIdentity();
9200 try {
9201 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9202 } finally {
9203 Binder.restoreCallingIdentity(identity);
9204 }
9205 }
9206
9207 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009208 public int getCdmaSubscriptionMode(int subId) {
9209 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009210 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009211 mApp, subId, "getCdmaSubscriptionMode");
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
9218 }
9219 }
9220
9221 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009222 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9224 mApp, subId, "setCdmaSubscriptionMode");
9225
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009233
sqianc5eccab2018-10-19 18:46:41 -07009234 @Override
sqian8c685422019-02-22 15:55:18 -08009235 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009236 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009238 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9239 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009240 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9241 }
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
sqian854d44b2018-12-12 16:48:18 -08009244 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9245 for (Phone phone: PhoneFactory.getPhones()) {
9246 if (phone.getEmergencyNumberTracker() != null
9247 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9248 emergencyNumberListInternal.put(
9249 phone.getSubId(),
9250 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9251 }
sqian11b7a0e2018-12-05 18:48:28 -08009252 }
sqian854d44b2018-12-12 16:48:18 -08009253 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009254 } finally {
9255 Binder.restoreCallingIdentity(identity);
9256 }
sqianc5eccab2018-10-19 18:46:41 -07009257 }
9258
9259 @Override
sqian8c685422019-02-22 15:55:18 -08009260 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009261 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009262 if (!exactMatch) {
9263 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009264 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009265 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009266 }
9267 final long identity = Binder.clearCallingIdentity();
9268 try {
sqian854d44b2018-12-12 16:48:18 -08009269 for (Phone phone: PhoneFactory.getPhones()) {
9270 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009271 && phone.getEmergencyNumberTracker()
9272 .isEmergencyNumber(number, exactMatch)) {
9273 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009274 }
sqian11b7a0e2018-12-05 18:48:28 -08009275 }
9276 return false;
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
sqianf4ca7ed2019-01-15 18:32:07 -08009282 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009283 * Start emergency callback mode for GsmCdmaPhone for testing.
9284 */
9285 @Override
9286 public void startEmergencyCallbackMode() {
9287 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9288 "startEmergencyCallbackMode");
9289 enforceModifyPermission();
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 for (Phone phone : PhoneFactory.getPhones()) {
9293 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9294 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9295 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9296 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9297 gsmCdmaPhone.obtainMessage(
9298 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9299 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9300 }
9301 }
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
9307 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009308 * Update emergency number list for test mode.
9309 */
9310 @Override
9311 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9313 "updateEmergencyNumberListTestMode");
9314
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 for (Phone phone: PhoneFactory.getPhones()) {
9318 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9319 if (tracker != null) {
9320 tracker.executeEmergencyNumberTestModeCommand(action, num);
9321 }
9322 }
9323 } finally {
9324 Binder.restoreCallingIdentity(identity);
9325 }
9326 }
9327
9328 /**
9329 * Get the full emergency number list for test mode.
9330 */
9331 @Override
9332 public List<String> getEmergencyNumberListTestMode() {
9333 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9334 "getEmergencyNumberListTestMode");
9335
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 Set<String> emergencyNumbers = new HashSet<>();
9339 for (Phone phone: PhoneFactory.getPhones()) {
9340 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9341 if (tracker != null) {
9342 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9343 emergencyNumbers.add(num.getNumber());
9344 }
9345 }
9346 }
9347 return new ArrayList<>(emergencyNumbers);
9348 } finally {
9349 Binder.restoreCallingIdentity(identity);
9350 }
9351 }
9352
chen xud6b45bd2018-10-30 22:27:10 -07009353 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009354 public int getEmergencyNumberDbVersion(int subId) {
9355 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 final Phone phone = getPhone(subId);
9360 if (phone == null) {
9361 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9362 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9363 }
9364 return phone.getEmergencyNumberDbVersion();
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
9370 @Override
9371 public void notifyOtaEmergencyNumberDbInstalled() {
9372 enforceModifyPermission();
9373
9374 final long identity = Binder.clearCallingIdentity();
9375 try {
9376 for (Phone phone: PhoneFactory.getPhones()) {
9377 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9378 if (tracker != null) {
9379 tracker.updateOtaEmergencyNumberDatabase();
9380 }
9381 }
9382 } finally {
9383 Binder.restoreCallingIdentity(identity);
9384 }
9385 }
9386
9387 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009388 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009389 enforceActiveEmergencySessionPermission();
9390
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 for (Phone phone: PhoneFactory.getPhones()) {
9394 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9395 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009396 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9397 }
9398 }
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
9404 @Override
9405 public void resetOtaEmergencyNumberDbFilePath() {
9406 enforceActiveEmergencySessionPermission();
9407
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 for (Phone phone: PhoneFactory.getPhones()) {
9411 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9412 if (tracker != null) {
9413 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009414 }
9415 }
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009422 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9423 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9424 Phone phone = getPhone(subId);
9425 if (phone == null) {
9426 return null;
9427 }
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
9430 UiccProfile profile = UiccController.getInstance()
9431 .getUiccProfileForPhone(phone.getPhoneId());
9432 if (profile != null) {
9433 return profile.getCertsFromCarrierPrivilegeAccessRules();
9434 }
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 return null;
9439 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009440
9441 /**
9442 * Enable or disable a modem stack.
9443 */
9444 @Override
9445 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9446 enforceModifyPermission();
9447
9448 final long identity = Binder.clearCallingIdentity();
9449 try {
9450 Phone phone = PhoneFactory.getPhone(slotIndex);
9451 if (phone == null) {
9452 return false;
9453 } else {
9454 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9455 }
9456 } finally {
9457 Binder.restoreCallingIdentity(identity);
9458 }
9459 }
Michelecea4cf22018-12-21 15:00:11 -08009460
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009461 /**
9462 * Whether a modem stack is enabled or not.
9463 */
9464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009465 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9466 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009467 Phone phone = PhoneFactory.getPhone(slotIndex);
9468 if (phone == null) return false;
9469
9470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009471 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9472 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009473 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9474 }
9475
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009478 try {
9479 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9480 } catch (NoSuchElementException ex) {
9481 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9482 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009483 } finally {
9484 Binder.restoreCallingIdentity(identity);
9485 }
9486 }
9487
Michelecea4cf22018-12-21 15:00:11 -08009488 @Override
Michele0ea7d782019-03-19 14:58:42 -07009489 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009490 enforceModifyPermission();
9491
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009495 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009496 .commit();
9497 } finally {
9498 Binder.restoreCallingIdentity(identity);
9499 }
9500 }
9501
9502 @Override
Michele0ea7d782019-03-19 14:58:42 -07009503 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009504 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009506 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9507 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009508 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009509 }
Michelecea4cf22018-12-21 15:00:11 -08009510
9511 final long identity = Binder.clearCallingIdentity();
9512 try {
Michele0ea7d782019-03-19 14:58:42 -07009513 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009518
Michele0ea7d782019-03-19 14:58:42 -07009519 @TelephonyManager.IsMultiSimSupportedResult
9520 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009521 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9522 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9523 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009524 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9525 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009526 }
9527 // Check if the hardware supports multisim functionality. If usage of multisim is not
9528 // supported by the modem, indicate that it is restricted.
9529 PhoneCapability staticCapability =
9530 mPhoneConfigurationManager.getStaticPhoneCapability();
9531 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009532 loge("isMultiSimSupportedInternal: no static configuration available");
9533 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009534 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009535 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009536 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9537 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009538 }
9539 // Check if support of multiple SIMs is restricted by carrier
9540 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009541 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009542 }
9543
Michele0ea7d782019-03-19 14:58:42 -07009544 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009545 }
9546
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009547 /**
9548 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009549 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9550 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9551 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009552 * @param numOfSims number of active sims we want to switch to
9553 */
9554 @Override
9555 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009556 if (numOfSims == 1) {
9557 enforceModifyPermission();
9558 } else {
9559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9560 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9561 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009562 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009563
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009564 try {
Michele30b57b22019-03-01 12:01:14 -08009565 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009566 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009567 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9568 return;
9569 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009570 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9571 } finally {
9572 Binder.restoreCallingIdentity(identity);
9573 }
9574 }
9575
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009576 @Override
9577 public boolean isApplicationOnUicc(int subId, int appType) {
9578 enforceReadPrivilegedPermission("isApplicationOnUicc");
9579 Phone phone = getPhone(subId);
9580 if (phone == null) {
9581 return false;
9582 }
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009585 UiccPort uiccPort = phone.getUiccPort();
9586 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009587 return false;
9588 }
Muralidhar Reddy472c2ae2021-09-29 19:38:40 +00009589 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009590 if (uiccProfile == null) {
9591 return false;
9592 }
9593 if (TelephonyManager.APPTYPE_SIM <= appType
9594 && appType <= TelephonyManager.APPTYPE_ISIM) {
9595 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9596 }
9597 return false;
9598 } finally {
9599 Binder.restoreCallingIdentity(identity);
9600 }
9601 }
9602
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009603 /**
chen xub4baa772019-04-03 10:23:41 -07009604 * Get whether making changes to modem configurations will trigger reboot.
9605 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009606 */
9607 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009608 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9609 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009611 mApp, subId, callingPackage, callingFeatureId,
9612 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009613 return false;
9614 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009615 final long identity = Binder.clearCallingIdentity();
9616 try {
9617 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9618 } finally {
9619 Binder.restoreCallingIdentity(identity);
9620 }
9621 }
9622
Nathan Harold29f5f052019-02-15 13:41:57 -08009623 private void updateModemStateMetrics() {
9624 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9625 // TODO: check the state for each modem if the api is ready.
9626 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9627 }
9628
Pengquan Meng3889a572019-01-23 11:16:29 -08009629 @Override
sandeepjsa208e3b2021-11-17 04:05:58 +00009630 public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
Pengquan Meng3889a572019-01-23 11:16:29 -08009631 enforceReadPrivilegedPermission("getSlotsMapping");
sandeepjsa208e3b2021-11-17 04:05:58 +00009632 // Verify that the callingPackage belongs to the calling UID
9633 mApp.getSystemService(AppOpsManager.class)
9634 .checkPackage(Binder.getCallingUid(), callingPackage);
Pengquan Meng3889a572019-01-23 11:16:29 -08009635 final long identity = Binder.clearCallingIdentity();
sandeepjsa208e3b2021-11-17 04:05:58 +00009636 List<UiccSlotMapping> slotMap = new ArrayList<>();
Pengquan Meng3889a572019-01-23 11:16:29 -08009637 try {
sandeepjsa208e3b2021-11-17 04:05:58 +00009638 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
9639 if (slotInfos != null) {
9640 for (int i = 0; i < slotInfos.length; i++) {
9641 for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
9642 if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
9643 slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
9644 portInfo.getLogicalSlotIndex()));
9645 }
9646 }
Pengquan Meng3889a572019-01-23 11:16:29 -08009647 }
9648 }
sandeepjsa208e3b2021-11-17 04:05:58 +00009649 return slotMap;
Pengquan Meng3889a572019-01-23 11:16:29 -08009650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009654
9655 /**
9656 * Get the IRadio HAL Version
9657 */
9658 @Override
9659 public int getRadioHalVersion() {
9660 Phone phone = getDefaultPhone();
9661 if (phone == null) return -1;
9662 HalVersion hv = phone.getHalVersion();
9663 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9664 return hv.major * 100 + hv.minor;
9665 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009666
9667 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009668 * Get the current calling package name.
9669 * @return the current calling package name
9670 */
9671 @Override
9672 public String getCurrentPackageName() {
9673 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9674 }
9675
9676 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009677 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9678 * corresponding network requests on a subId.
9679 *
9680 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009681 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009682 * 2) APN is un-metered for this subscription, or
9683 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009684 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009685 *
9686 * @return whether data is allowed for a apn type.
9687 *
9688 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009689 */
9690 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009691 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009692 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9693 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009694
9695 // Now that all security checks passes, perform the operation as ourselves.
9696 final long identity = Binder.clearCallingIdentity();
9697 try {
9698 Phone phone = getPhone(subId);
9699 if (phone == null) return false;
9700
Jack Yu27422a52022-03-21 10:38:05 -07009701 boolean isMetered;
Jack Yu99e87332021-12-17 23:14:15 -08009702 boolean isDataEnabled;
Jack Yuabb10902022-07-31 00:43:21 -07009703 isMetered = phone.getDataNetworkController().getDataConfigManager()
9704 .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType),
9705 phone.getServiceState().getDataRoaming());
9706 isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType);
Jack Yu99e87332021-12-17 23:14:15 -08009707 return !isMetered || isDataEnabled;
Malcolm Chene5ad5792019-04-18 13:51:02 -07009708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009714 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009715 enforceReadPrivilegedPermission("isApnMetered");
9716
9717 // Now that all security checks passes, perform the operation as ourselves.
9718 final long identity = Binder.clearCallingIdentity();
9719 try {
9720 Phone phone = getPhone(subId);
9721 if (phone == null) return true; // By default return true.
Jack Yuabb10902022-07-31 00:43:21 -07009722 return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability(
9723 DataUtils.apnTypeToNetworkCapability(apnType),
9724 phone.getServiceState().getDataRoaming());
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009729
9730 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009731 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9732 int subscriptionId, IBooleanConsumer resultCallback) {
9733 enforceModifyPermission();
9734 long token = Binder.clearCallingIdentity();
9735 try {
9736 Phone phone = getPhone(subscriptionId);
9737 if (phone == null) {
9738 try {
9739 if (resultCallback != null) {
9740 resultCallback.accept(false);
9741 }
9742 } catch (RemoteException e) {
9743 // ignore
9744 }
9745 return;
9746 }
9747 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9748 Pair.create(specifiers, (x) -> {
9749 try {
9750 if (resultCallback != null) {
9751 resultCallback.accept(x);
9752 }
9753 } catch (RemoteException e) {
9754 // ignore
9755 }
9756 });
9757 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9758 } finally {
9759 Binder.restoreCallingIdentity(token);
9760 }
9761 }
9762
9763 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009764 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9765 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009766 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009767 mApp, subId, "getSystemSelectionChannels");
9768 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009771 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9772 if (result instanceof IllegalStateException) {
9773 throw (IllegalStateException) result;
9774 }
9775 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009776 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9777 return specifiers;
9778 } finally {
9779 Binder.restoreCallingIdentity(identity);
9780 }
9781 }
9782
9783 @Override
Jack Yu8b766fc2022-03-21 09:42:33 -07009784 public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009785 enforceReadPrivilegedPermission("isMvnoMatched");
Jack Yu8b766fc2022-03-21 09:42:33 -07009786 return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData);
changbetty7157e9e2019-12-06 18:16:37 +08009787 }
9788
9789 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009790 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9791 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009792 if (callingPackage == null) {
9793 callingPackage = getCurrentPackageName();
9794 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009795 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9796 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009797 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9798 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009799 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9800 }
9801 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9802 Intent intent = new Intent();
9803 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9804 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9805 // Bring up choose default SMS subscription dialog right now
9806 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9807 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9808 mApp.startActivity(intent);
9809 }
chen xud5ca2d52019-05-28 15:20:57 -07009810
9811 @Override
9812 public String getMmsUAProfUrl(int subId) {
9813 //TODO investigate if this API should require proper permission check in R b/133791609
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009816 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9817 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9818 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9819 return carrierUAProfUrl;
9820 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009821 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9822 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009823 } finally {
9824 Binder.restoreCallingIdentity(identity);
9825 }
9826 }
9827
9828 @Override
9829 public String getMmsUserAgent(int subId) {
9830 //TODO investigate if this API should require proper permission check in R b/133791609
9831 final long identity = Binder.clearCallingIdentity();
9832 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009833 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9834 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9835 if (!TextUtils.isEmpty(carrierUserAgent)) {
9836 return carrierUserAgent;
9837 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009838 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9839 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 }
Jack Yub07d4972019-05-28 16:12:25 -07009844
9845 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009846 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9847 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009848
Jack Yub07d4972019-05-28 16:12:25 -07009849 final long identity = Binder.clearCallingIdentity();
9850 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009851 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009852 if (phone == null) return false;
9853
Ling Ma58448e42022-09-16 15:22:36 -07009854 return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy);
Jack Yub07d4972019-05-28 16:12:25 -07009855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 }
9859
9860 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009861 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009862 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009863 enforceModifyPermission();
9864
changbettyd5c246e2019-12-24 15:40:37 +08009865 final long identity = Binder.clearCallingIdentity();
9866 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009867 Phone phone = getPhone(subscriptionId);
9868 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009869
Ling Ma58448e42022-09-16 15:22:36 -07009870 phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled);
changbettyd5c246e2019-12-24 15:40:37 +08009871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
9875
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009876 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009877 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009878 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9879 * otherwise.
9880 */
9881 @Override
9882 public void setCepEnabled(boolean isCepEnabled) {
9883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9884
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
9887 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9888 for (Phone phone : PhoneFactory.getPhones()) {
9889 Phone defaultPhone = phone.getImsPhone();
9890 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9891 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9892 ImsPhoneCallTracker imsPhoneCallTracker =
9893 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9894 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9895 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9896 + imsPhone.getMsisdn());
9897 }
9898 }
9899 } finally {
9900 Binder.restoreCallingIdentity(identity);
9901 }
9902 }
allenwtsu46dcc572020-01-08 18:24:03 +08009903
9904 /**
9905 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9906 *
9907 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9908 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9909 * before being read.
9910 */
9911 @Override
9912 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9913 isCompressed) {
9914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9915 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9917 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9918 }
9919 if (!isImsAvailableOnDevice()) {
9920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9921 "IMS not available on device.");
9922 }
9923
9924 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009925 try {
Hui Wang761a6682020-10-31 05:12:53 +00009926 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9927 } finally {
9928 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009929 }
9930 }
zoey chene02881a2019-12-30 16:11:23 +08009931
9932 @Override
9933 public boolean isIccLockEnabled(int subId) {
9934 enforceReadPrivilegedPermission("isIccLockEnabled");
9935
9936 // Now that all security checks passes, perform the operation as ourselves.
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
9939 Phone phone = getPhone(subId);
9940 if (phone != null && phone.getIccCard() != null) {
9941 return phone.getIccCard().getIccLockEnabled();
9942 } else {
9943 return false;
9944 }
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 /**
9951 * Set the ICC pin lock enabled or disabled.
9952 *
9953 * @return an integer representing the status of IccLock enabled or disabled in the following
9954 * three cases:
9955 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9956 * successfully.
9957 * - Positive number and zero for remaining password attempts.
9958 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9959 *
9960 */
9961 @Override
9962 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9963 enforceModifyPermission();
9964
9965 Phone phone = getPhone(subId);
9966 if (phone == null) {
9967 return 0;
9968 }
9969 // Now that all security checks passes, perform the operation as ourselves.
9970 final long identity = Binder.clearCallingIdentity();
9971 try {
9972 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9973 new Pair<Boolean, String>(enabled, password), phone, null);
9974 return attemptsRemaining;
9975
9976 } catch (Exception e) {
9977 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981 return 0;
9982 }
9983
9984 /**
9985 * Change the ICC password used in ICC pin lock.
9986 *
9987 * @return an integer representing the status of IccLock changed in the following three cases:
9988 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9989 * - Positive number and zero for remaining password attempts.
9990 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9991 *
9992 */
9993 @Override
9994 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9995 enforceModifyPermission();
9996
9997 Phone phone = getPhone(subId);
9998 if (phone == null) {
9999 return 0;
10000 }
10001 // Now that all security checks passes, perform the operation as ourselves.
10002 final long identity = Binder.clearCallingIdentity();
10003 try {
10004 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
10005 new Pair<String, String>(oldPassword, newPassword), phone, null);
10006 return attemptsRemaining;
10007
10008 } catch (Exception e) {
10009 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
10010 } finally {
10011 Binder.restoreCallingIdentity(identity);
10012 }
10013 return 0;
10014 }
Peter Wangdafb9ac2020-01-15 14:13:38 -080010015
10016 /**
10017 * Request for receiving user activity notification
10018 */
10019 @Override
10020 public void requestUserActivityNotification() {
10021 if (!mNotifyUserActivity.get()
10022 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
10023 mNotifyUserActivity.set(true);
10024 }
10025 }
10026
10027 /**
10028 * Called when userActivity is signalled in the power manager.
10029 * This is safe to call from any thread, with any window manager locks held or not.
10030 */
10031 @Override
10032 public void userActivity() {
10033 // ***************************************
10034 // * Inherited from PhoneWindowManager *
10035 // ***************************************
10036 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
10037 // WITH ITS LOCKS HELD.
10038 //
10039 // This code must be VERY careful about the locks
10040 // it acquires.
10041 // In fact, the current code acquires way too many,
10042 // and probably has lurking deadlocks.
10043
10044 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
10045 throw new SecurityException("Only the OS may call notifyUserActivity()");
10046 }
10047
10048 if (mNotifyUserActivity.getAndSet(false)) {
10049 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
10050 USER_ACTIVITY_NOTIFICATION_DELAY);
10051 }
10052 }
Malcolm Chen4639c562020-04-13 11:59:40 -070010053
10054 @Override
10055 public boolean canConnectTo5GInDsdsMode() {
10056 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
10057 }
Jack Yud10cdd42020-09-28 20:28:01 -070010058
10059 @Override
10060 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
10061 String callingFeatureId) {
10062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
10063 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
10064 throw new SecurityException("Requires READ_PHONE_STATE permission.");
10065 }
10066
10067 Phone phone = getPhone(subId);
10068 if (phone == null) {
10069 throw new RuntimeException("phone is not available");
10070 }
10071 // Now that all security checks passes, perform the operation as ourselves.
10072 final long identity = Binder.clearCallingIdentity();
10073 try {
10074 return phone.getEquivalentHomePlmns();
10075 } finally {
10076 Binder.restoreCallingIdentity(identity);
10077 }
10078 }
Daniel Bright59e67312020-11-13 11:49:37 -080010079
10080 @Override
10081 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010082 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
10083 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -080010084 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -080010085 if (radioInterfaceCapabilities == null) {
10086 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -080010087 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -080010088 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -080010089 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010090
Hui Wang641e81c2020-10-12 12:14:23 -070010091 @Override
10092 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
10093 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +000010094 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
10095 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10096 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
10097 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10098 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -070010099 if (DBG) {
10100 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
10101 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
10102 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
10103 }
10104
10105 if (!SubscriptionManager.isValidSubscriptionId(subId)
10106 || appType < TelephonyManager.APPTYPE_UNKNOWN
10107 || appType > TelephonyManager.APPTYPE_ISIM
10108 || nafUrl == null || securityProtocol == null || callback == null) {
10109 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
10110 if (callback != null) {
10111 try {
10112 callback.onAuthenticationFailure(
10113 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
10114 } catch (RemoteException exception) {
10115 log("Fail to notify onAuthenticationFailure due to " + exception);
10116 }
10117 return;
10118 }
10119 }
10120
10121 final long token = Binder.clearCallingIdentity();
10122 try {
10123 getGbaManager(subId).bootstrapAuthenticationRequest(
10124 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
10125 forceBootStrapping, callback));
10126 } finally {
10127 Binder.restoreCallingIdentity(token);
10128 }
10129 }
10130
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010131 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010132 * Attempts to set the radio power state for all phones for thermal reason.
10133 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 * requested radio power state will actually be set. See {@link
10135 * PhoneInternalInterface#setRadioPowerForReason} for more details.
10136 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 * @param enable {@code true} if trying to turn radio on.
10138 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
10139 * false}.
10140 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010141 private boolean setRadioPowerForThermal(boolean enable) {
10142 boolean isPhoneAvailable = false;
10143 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
10144 Phone phone = PhoneFactory.getPhone(i);
10145 if (phone != null) {
10146 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
10147 isPhoneAvailable = true;
10148 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010149 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010150
10151 // return true if successfully informed the phone object about the thermal radio power
10152 // request.
10153 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010154 }
10155
10156 private int handleDataThrottlingRequest(int subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010157 DataThrottlingRequest dataThrottlingRequest, String callingPackage) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010158 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
10159 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
10160 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
10161 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
10162 throw new IllegalArgumentException("modem does not support data throttling");
10163 }
10164
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010165 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
10166 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010167 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010168 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10169 }
10170
Sarah Chinecc78c42022-03-31 21:16:48 -070010171 setDataEnabledForReason(
10172 subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010173
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010174 if (isDataThrottlingSupported) {
10175 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010176 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010177 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
10178 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
10179 } else if (thermalMitigationResult
10180 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010181 log("Modem likely does not support data throttling on secondary carrier. Data " +
10182 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10183 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010184 }
10185 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010186 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010187
10188 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010189 }
10190
Jack Nudelman644b91a2021-03-12 14:09:48 -080010191 private static List<String> getThermalMitigationAllowlist(Context context) {
10192 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10193 for (String pckg : context.getResources()
10194 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10195 sThermalMitigationAllowlistedPackages.add(pckg);
10196 }
10197 }
10198
10199 return sThermalMitigationAllowlistedPackages;
10200 }
10201
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010202 private boolean isAnyPhoneInEmergencyState() {
10203 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10204 if (tm.isInEmergencyCall()) {
10205 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10206 return true;
10207 }
10208 for (Phone phone : PhoneFactory.getPhones()) {
10209 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10210 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10211 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10212 + phone.isInEcm());
10213 return true;
10214 }
10215 }
10216
10217 return false;
10218 }
10219
Jack Nudelman644b91a2021-03-12 14:09:48 -080010220 /**
10221 * Used by shell commands to add an authorized package name for thermal mitigation.
10222 * @param packageName name of package to be allowlisted
10223 * @param context
10224 */
10225 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10226 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10227 sThermalMitigationAllowlistedPackages.add(packageName);
10228 }
10229
10230 /**
10231 * Used by shell commands to remove an authorized package name for thermal mitigation.
10232 * @param packageName name of package to remove from allowlist
10233 * @param context
10234 */
10235 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10236 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10237 sThermalMitigationAllowlistedPackages.remove(packageName);
10238 }
10239
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010240 /**
10241 * Thermal mitigation request to control functionalities at modem.
10242 *
10243 * @param subId the id of the subscription.
10244 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010245 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010246 *
10247 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10248 */
10249 @Override
10250 @ThermalMitigationResult
10251 public int sendThermalMitigationRequest(
10252 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010253 ThermalMitigationRequest thermalMitigationRequest,
10254 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010255 enforceModifyPermission();
10256
Jack Nudelman644b91a2021-03-12 14:09:48 -080010257 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10258 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10259 .contains(callingPackage)) {
10260 throw new SecurityException("Calling package must be configured in the device config. "
10261 + "calling package: " + callingPackage);
10262 }
10263
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10265 final long identity = Binder.clearCallingIdentity();
10266
10267 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10268 try {
10269 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10270 switch (thermalMitigationAction) {
10271 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10272 thermalMitigationResult =
10273 handleDataThrottlingRequest(subId,
Sarah Chinecc78c42022-03-31 21:16:48 -070010274 thermalMitigationRequest.getDataThrottlingRequest(),
10275 callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010276 break;
10277 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10278 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10279 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10280 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10281 }
10282
10283 // Ensure that radio is on. If not able to power on due to phone being
10284 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010285 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010286 thermalMitigationResult =
10287 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10288 break;
10289 }
10290
10291 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
Sarah Chinecc78c42022-03-31 21:16:48 -070010292 false, callingPackage);
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010293 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10294 break;
10295 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10296 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10297 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10298 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10299 }
10300
10301 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10302 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010303 Phone phone = getPhone(subId);
10304 if (phone == null) {
10305 thermalMitigationResult =
10306 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10307 break;
10308 }
10309
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010310 TelephonyConnectionService service =
10311 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010312 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010313 Log.e(LOG_TAG, "An emergency call is pending");
10314 thermalMitigationResult =
10315 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10316 break;
10317 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010318 thermalMitigationResult =
10319 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10320 break;
10321 }
10322 } else {
10323 thermalMitigationResult =
10324 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10325 break;
10326 }
10327
10328 // Turn radio off. If not able to power off due to phone being unavailable,
10329 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010330 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010331 thermalMitigationResult =
10332 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10333 break;
10334 }
10335 thermalMitigationResult =
10336 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10337 break;
10338 default:
10339 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10340 + "not exist. Requested action: " + thermalMitigationAction);
10341 }
10342 } catch (IllegalArgumentException e) {
10343 throw e;
10344 } catch (Exception e) {
10345 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10346 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350
10351 if (DBG) {
10352 log("thermalMitigationRequest returning with thermalMitigationResult: "
10353 + thermalMitigationResult);
10354 }
10355
10356 return thermalMitigationResult;
10357 }
Hui Wang641e81c2020-10-12 12:14:23 -070010358
10359 /**
10360 * Set the GbaService Package Name that Telephony will bind to.
10361 *
10362 * @param subId The sim that the GbaService is associated with.
10363 * @param packageName The name of the package to be replaced with.
10364 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10365 */
10366 @Override
10367 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10368 enforceModifyPermission();
10369
10370 final long identity = Binder.clearCallingIdentity();
10371 try {
10372 return getGbaManager(subId).overrideServicePackage(packageName);
10373 } finally {
10374 Binder.restoreCallingIdentity(identity);
10375 }
10376 }
10377
10378 /**
10379 * Return the package name of the currently bound GbaService.
10380 *
10381 * @param subId The sim that the GbaService is associated with.
10382 * @return the package name of the GbaService configuration, null if GBA is not supported.
10383 */
10384 @Override
10385 public String getBoundGbaService(int subId) {
10386 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10387
10388 final long identity = Binder.clearCallingIdentity();
10389 try {
10390 return getGbaManager(subId).getServicePackage();
10391 } finally {
10392 Binder.restoreCallingIdentity(identity);
10393 }
10394 }
10395
10396 /**
10397 * Set the release time for telephony to unbind GbaService.
10398 *
10399 * @param subId The sim that the GbaService is associated with.
10400 * @param interval The release time to unbind GbaService by millisecond.
10401 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10402 */
10403 @Override
10404 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10405 enforceModifyPermission();
10406
10407 final long identity = Binder.clearCallingIdentity();
10408 try {
10409 return getGbaManager(subId).overrideReleaseTime(interval);
10410 } finally {
10411 Binder.restoreCallingIdentity(identity);
10412 }
10413 }
10414
10415 /**
10416 * Return the release time for telephony to unbind GbaService.
10417 *
10418 * @param subId The sim that the GbaService is associated with.
10419 * @return The release time to unbind GbaService by millisecond.
10420 */
10421 @Override
10422 public int getGbaReleaseTime(int subId) {
10423 enforceReadPrivilegedPermission("getGbaReleaseTime");
10424
10425 final long identity = Binder.clearCallingIdentity();
10426 try {
10427 return getGbaManager(subId).getReleaseTime();
10428 } finally {
10429 Binder.restoreCallingIdentity(identity);
10430 }
10431 }
10432
10433 private GbaManager getGbaManager(int subId) {
10434 GbaManager instance = GbaManager.getInstance(subId);
10435 if (instance == null) {
10436 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10437 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10438 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10439 }
10440 return instance;
10441 }
Hui Wang761a6682020-10-31 05:12:53 +000010442
10443 /**
10444 * indicate whether the device and the carrier can support
10445 * RCS VoLTE single registration.
10446 */
10447 @Override
10448 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010449 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10450 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10451 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10452 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010453
10454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10456 }
10457
10458 final long identity = Binder.clearCallingIdentity();
10459 try {
10460 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10461 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010462 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10463 if (isCapable != null) {
10464 return isCapable;
10465 }
Hui Wang761a6682020-10-31 05:12:53 +000010466 }
Hui Wang67af90e2021-06-04 16:57:15 -070010467 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10468 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
10474 /**
10475 * Register RCS provisioning callback.
10476 */
10477 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010478 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010479 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010480 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010481 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010482 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10483 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010484
10485 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10486 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10487 }
10488 if (!isImsAvailableOnDevice()) {
10489 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10490 "IMS not available on device.");
10491 }
10492
10493 final long identity = Binder.clearCallingIdentity();
10494 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010495 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010496 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010497 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10498 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010499 }
Hui Wang761a6682020-10-31 05:12:53 +000010500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
10505 /**
10506 * Unregister RCS provisioning callback.
10507 */
10508 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010509 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010510 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010511 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010512 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010513 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10514 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010515
10516 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10517 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10518 }
10519 if (!isImsAvailableOnDevice()) {
10520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10521 "IMS not available on device.");
10522 }
10523
10524 final long identity = Binder.clearCallingIdentity();
10525 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010526 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010527 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010528 } finally {
10529 Binder.restoreCallingIdentity(identity);
10530 }
10531 }
10532
10533 /**
10534 * trigger RCS reconfiguration.
10535 */
10536 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010537 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10538 "triggerRcsReconfiguration",
10539 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010540
10541 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10542 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10543 }
10544 if (!isImsAvailableOnDevice()) {
10545 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10546 "IMS not available on device.");
10547 }
10548
10549 final long identity = Binder.clearCallingIdentity();
10550 try {
10551 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10552 } finally {
10553 Binder.restoreCallingIdentity(identity);
10554 }
10555 }
10556
10557 /**
10558 * Provide the client configuration parameters of the RCS application.
10559 */
10560 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010561 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10562 "setRcsClientConfiguration",
10563 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010564
10565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10566 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10567 }
10568 if (!isImsAvailableOnDevice()) {
10569 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10570 "IMS not available on device.");
10571 }
10572
10573 final long identity = Binder.clearCallingIdentity();
10574
10575 try {
10576 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10577 if (configBinder == null) {
10578 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010579 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10580 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010581 } else {
10582 configBinder.setRcsClientConfiguration(rcc);
10583 }
joonhunshin3e154242021-09-17 06:33:39 +000010584
10585 RcsStats.getInstance().onRcsClientProvisioningStats(subId,
10586 RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT);
Hui Wang761a6682020-10-31 05:12:53 +000010587 } catch (RemoteException e) {
10588 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010589 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10590 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
10595
10596 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010597 * Enables or disables the test mode for RCS VoLTE single registration.
10598 */
10599 @Override
10600 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10602 "setRcsSingleRegistrationTestModeEnabled");
10603
10604 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10605 }
10606
10607 /**
10608 * Gets the test mode for RCS VoLTE single registration.
10609 */
10610 @Override
10611 public boolean getRcsSingleRegistrationTestModeEnabled() {
10612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10613 "getRcsSingleRegistrationTestModeEnabled");
10614
10615 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10616 }
10617
10618 /**
Hui Wang761a6682020-10-31 05:12:53 +000010619 * Overrides the config of RCS VoLTE single registration enabled for the device.
10620 */
10621 @Override
10622 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10624 "setDeviceSingleRegistrationEnabledOverride");
10625 enforceModifyPermission();
10626
10627 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10628 : Boolean.parseBoolean(enabledStr);
10629 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010630 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010631 }
10632
10633 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010634 * Sends a device to device communication message. Only usable via shell.
10635 * @param message message to send.
10636 * @param value message value.
10637 */
10638 @Override
10639 public void sendDeviceToDeviceMessage(int message, int value) {
10640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010641 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010642 enforceModifyPermission();
10643
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 TelephonyConnectionService service =
10647 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10648 if (service == null) {
10649 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10650 return;
10651 }
10652 service.sendTestDeviceToDeviceMessage(message, value);
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
Tyler Gunnbabbda02021-02-10 11:05:02 -080010658 /**
10659 * Sets the specified device to device transport active.
10660 * @param transport The transport to set active.
10661 */
10662 @Override
10663 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10664 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10665 "setActiveDeviceToDeviceTransport");
10666 enforceModifyPermission();
10667
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 TelephonyConnectionService service =
10671 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10672 if (service == null) {
10673 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10674 return;
10675 }
10676 service.setActiveDeviceToDeviceTransport(transport);
10677 } finally {
10678 Binder.restoreCallingIdentity(identity);
10679 }
10680 }
Tyler Gunn92479152021-01-20 16:30:10 -080010681
Tyler Gunnd4339262021-05-03 14:46:49 -070010682 @Override
10683 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10685 "setDeviceToDeviceForceEnabled");
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 Arrays.stream(PhoneFactory.getPhones()).forEach(
10690 p -> {
10691 Phone thePhone = p.getImsPhone();
10692 if (thePhone != null && thePhone instanceof ImsPhone) {
10693 ImsPhone imsPhone = (ImsPhone) thePhone;
10694 CallTracker tracker = imsPhone.getCallTracker();
10695 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10696 ImsPhoneCallTracker imsPhoneCallTracker =
10697 (ImsPhoneCallTracker) tracker;
10698 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10699 }
10700 }
10701 }
10702 );
10703 } finally {
10704 Binder.restoreCallingIdentity(identity);
10705 }
10706 }
10707
Tyler Gunn92479152021-01-20 16:30:10 -080010708 /**
Hui Wang761a6682020-10-31 05:12:53 +000010709 * Gets the config of RCS VoLTE single registration enabled for the device.
10710 */
10711 @Override
10712 public boolean getDeviceSingleRegistrationEnabled() {
10713 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10714 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10715 }
10716
10717 /**
10718 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10719 */
10720 @Override
10721 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10722 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10723 "setCarrierSingleRegistrationEnabledOverride");
10724 enforceModifyPermission();
10725
10726 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10727 : Boolean.parseBoolean(enabledStr);
10728 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10729 subId, enabled);
10730 }
10731
10732 /**
10733 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10734 */
10735 @Override
10736 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10737 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10738 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10739 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010740
10741 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010742 * Overrides the ims feature validation result
10743 */
10744 @Override
10745 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10747 "setImsFeatureValidationOverride");
10748
10749 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10750 : Boolean.parseBoolean(enabledStr);
10751 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10752 subId, enabled);
10753 }
10754
10755 /**
10756 * Gets the ims feature validation override value
10757 */
10758 @Override
10759 public boolean getImsFeatureValidationOverride(int subId) {
10760 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10761 "getImsFeatureValidationOverride");
10762 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10763 }
10764
10765 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010766 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10767 * their mobile plan.
10768 */
10769 @Override
10770 public String getMobileProvisioningUrl() {
10771 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10772 final long identity = Binder.clearCallingIdentity();
10773 try {
10774 return getDefaultPhone().getMobileProvisioningUrl();
10775 } finally {
10776 Binder.restoreCallingIdentity(identity);
10777 }
10778 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010779
James.cf Linbcdf8b32021-01-14 16:44:13 +080010780 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010781 * Get the EAB contact from the EAB database.
10782 */
10783 @Override
10784 public String getContactFromEab(String contact) {
10785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10786 enforceModifyPermission();
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10790 } finally {
10791 Binder.restoreCallingIdentity(identity);
10792 }
10793 }
10794
10795 /**
Calvin Pana1434322021-07-01 19:27:01 +080010796 * Get the EAB capability from the EAB database.
10797 */
10798 @Override
10799 public String getCapabilityFromEab(String contact) {
10800 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10801 enforceModifyPermission();
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10805 } finally {
10806 Binder.restoreCallingIdentity(identity);
10807 }
10808 }
10809
10810 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010811 * Remove the EAB contacts from the EAB database.
10812 */
10813 @Override
10814 public int removeContactFromEab(int subId, String contacts) {
10815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10816 enforceModifyPermission();
10817 final long identity = Binder.clearCallingIdentity();
10818 try {
10819 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10820 } finally {
10821 Binder.restoreCallingIdentity(identity);
10822 }
10823 }
10824
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010825 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010826 public boolean getDeviceUceEnabled() {
10827 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10828 final long identity = Binder.clearCallingIdentity();
10829 try {
10830 return mApp.getDeviceUceEnabled();
10831 } finally {
10832 Binder.restoreCallingIdentity(identity);
10833 }
10834 }
10835
10836 @Override
10837 public void setDeviceUceEnabled(boolean isEnabled) {
10838 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10839 final long identity = Binder.clearCallingIdentity();
10840 try {
10841 mApp.setDeviceUceEnabled(isEnabled);
10842 } finally {
10843 Binder.restoreCallingIdentity(identity);
10844 }
10845 }
10846
Brad Ebinger14d467f2021-02-12 06:18:28 +000010847 /**
10848 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10849 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10850 */
10851 // Used for SHELL command only right now.
10852 @Override
10853 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10854 List<String> featureTags) {
10855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10856 "addUceRegistrationOverrideShell");
10857 final long identity = Binder.clearCallingIdentity();
10858 try {
10859 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10860 new ArraySet<>(featureTags));
10861 } catch (ImsException e) {
10862 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10863 } finally {
10864 Binder.restoreCallingIdentity(identity);
10865 }
10866 }
10867
10868 /**
10869 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10870 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10871 */
10872 // Used for SHELL command only right now.
10873 @Override
10874 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10875 List<String> featureTags) {
10876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10877 "removeUceRegistrationOverrideShell");
10878 final long identity = Binder.clearCallingIdentity();
10879 try {
10880 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10881 new ArraySet<>(featureTags));
10882 } catch (ImsException e) {
10883 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10884 } finally {
10885 Binder.restoreCallingIdentity(identity);
10886 }
10887 }
10888
10889 /**
10890 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10891 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10892 */
10893 // Used for SHELL command only right now.
10894 @Override
10895 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10897 "clearUceRegistrationOverrideShell");
10898 final long identity = Binder.clearCallingIdentity();
10899 try {
10900 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10901 } catch (ImsException e) {
10902 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10903 } finally {
10904 Binder.restoreCallingIdentity(identity);
10905 }
10906 }
10907
10908 /**
10909 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10910 */
10911 // Used for SHELL command only right now.
10912 @Override
10913 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10915 "getLatestRcsContactUceCapabilityShell");
10916 final long identity = Binder.clearCallingIdentity();
10917 try {
10918 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10919 } catch (ImsException e) {
10920 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10921 } finally {
10922 Binder.restoreCallingIdentity(identity);
10923 }
10924 }
10925
10926 /**
10927 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10928 * device does not have an active PUBLISH.
10929 */
10930 // Used for SHELL command only right now.
10931 @Override
10932 public String getLastUcePidfXmlShell(int subId) {
10933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10934 final long identity = Binder.clearCallingIdentity();
10935 try {
10936 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10937 } catch (ImsException e) {
10938 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10939 } finally {
10940 Binder.restoreCallingIdentity(identity);
10941 }
10942 }
10943
James.cf Line8713a42021-04-29 16:04:26 +080010944 /**
10945 * Remove UCE requests cannot be sent to the network status.
10946 */
10947 // Used for SHELL command only right now.
10948 @Override
10949 public boolean removeUceRequestDisallowedStatus(int subId) {
10950 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10951 final long identity = Binder.clearCallingIdentity();
10952 try {
10953 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10954 } catch (ImsException e) {
10955 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10956 } finally {
10957 Binder.restoreCallingIdentity(identity);
10958 }
10959 }
10960
James.cf Lin18bb9002021-05-25 01:37:38 +080010961 /**
10962 * Remove UCE requests cannot be sent to the network status.
10963 */
10964 // Used for SHELL command only.
10965 @Override
10966 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10967 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10968 final long identity = Binder.clearCallingIdentity();
10969 try {
10970 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10971 } catch (ImsException e) {
10972 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10973 } finally {
10974 Binder.restoreCallingIdentity(identity);
10975 }
10976 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010977
James.cf Lin4b784aa2021-01-31 03:25:15 +080010978 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010979 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10980 String callingPackage) {
10981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10982 mApp, subId, "setSignalStrengthUpdateRequest");
10983
10984 final int callingUid = Binder.getCallingUid();
10985 // Verify that tha callingPackage belongs to the calling UID
10986 mApp.getSystemService(AppOpsManager.class)
10987 .checkPackage(callingUid, callingPackage);
10988
Rambo Wang3607f502021-02-01 21:51:40 -080010989 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010990
10991 final long identity = Binder.clearCallingIdentity();
10992 try {
10993 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10994 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10995
10996 if (result instanceof IllegalStateException) {
10997 throw (IllegalStateException) result;
10998 }
10999 } finally {
11000 Binder.restoreCallingIdentity(identity);
11001 }
11002 }
11003
11004 @Override
11005 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
11006 String callingPackage) {
11007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
11008 mApp, subId, "clearSignalStrengthUpdateRequest");
11009
11010 final int callingUid = Binder.getCallingUid();
11011 // Verify that tha callingPackage belongs to the calling UID
11012 mApp.getSystemService(AppOpsManager.class)
11013 .checkPackage(callingUid, callingPackage);
11014
11015 final long identity = Binder.clearCallingIdentity();
11016 try {
11017 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
11018 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
11019
11020 if (result instanceof IllegalStateException) {
11021 throw (IllegalStateException) result;
11022 }
11023 } finally {
11024 Binder.restoreCallingIdentity(identity);
11025 }
11026 }
11027
Rambo Wang3607f502021-02-01 21:51:40 -080011028 private static void validateSignalStrengthUpdateRequest(Context context,
11029 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011030 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
11031 // phone/system process do not have further restriction on request
11032 return;
11033 }
11034
11035 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080011036 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011037 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080011038 context.enforceCallingOrSelfPermission(
11039 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
11040 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080011041 }
11042
11043 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
11044 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
11045 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
11046 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
11047 || info.isEnabled()) {
11048 throw new IllegalArgumentException(
11049 "Only system can set hide fields in SignalThresholdInfo");
11050 }
11051
11052 // Thresholds length for each RAN need in range. This has been validated in
11053 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
11054 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
11055 final int[] thresholds = info.getThresholds();
11056 Objects.requireNonNull(thresholds);
11057 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
11058 || thresholds.length
11059 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
11060 throw new IllegalArgumentException(
11061 "thresholds length is out of range: " + thresholds.length);
11062 }
11063 }
11064 }
SongFerngWang8236caa2021-01-17 21:51:44 +080011065
11066 /**
11067 * Gets the current phone capability.
11068 *
11069 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
11070 * @return the PhoneCapability which describes the data connection capability of modem.
11071 * It's used to evaluate possible phone config change, for example from single
11072 * SIM device to multi-SIM device.
11073 */
11074 @Override
11075 public PhoneCapability getPhoneCapability() {
11076 enforceReadPrivilegedPermission("getPhoneCapability");
11077 final long identity = Binder.clearCallingIdentity();
11078 try {
11079 return mPhoneConfigurationManager.getCurrentPhoneCapability();
11080 } finally {
11081 Binder.restoreCallingIdentity(identity);
11082 }
11083 }
Michele Berionne5e411512020-11-13 02:36:59 +000011084
11085 /**
11086 * Prepare TelephonyManager for an unattended reboot. The reboot is
11087 * required to be done shortly after the API is invoked.
11088 */
11089 @Override
11090 @TelephonyManager.PrepareUnattendedRebootResult
11091 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000011093 enforceRebootPermission();
11094
11095 final long identity = Binder.clearCallingIdentity();
11096 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000011097 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000011098 } finally {
11099 Binder.restoreCallingIdentity(identity);
11100 }
11101 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011102
11103 /**
11104 * Request to get the current slicing configuration including URSP rules and
11105 * NSSAIs (configured, allowed and rejected).
11106 *
11107 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
11108 */
11109 @Override
11110 public void getSlicingConfig(ResultReceiver callback) {
Hongbo Zeng1b2063d2022-02-21 01:33:03 +000011111 TelephonyPermissions
11112 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11113 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig");
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080011114
11115 final long identity = Binder.clearCallingIdentity();
11116 try {
11117 Phone phone = getDefaultPhone();
11118 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
11119 } finally {
11120 Binder.restoreCallingIdentity(identity);
11121 }
11122 }
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011123
11124 /**
11125 * Register an IMS connection state callback
11126 */
11127 @Override
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011128 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
11129 String callingPackage) {
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011130 if (feature == ImsFeature.FEATURE_MMTEL) {
11131 // ImsMmTelManager
11132 // The following also checks READ_PRIVILEGED_PHONE_STATE.
11133 TelephonyPermissions
11134 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
11135 mApp, subId, "registerImsStateCallback");
11136 } else if (feature == ImsFeature.FEATURE_RCS) {
11137 // ImsRcsManager or SipDelegateManager
11138 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
11139 Binder.getCallingUid(), "registerImsStateCallback",
11140 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
11141 Manifest.permission.READ_PRECISE_PHONE_STATE,
11142 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
11143 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
11144 }
11145
11146 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
11147 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11148 "IMS not available on device.");
11149 }
11150
11151 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
11152 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
11153 }
11154
11155 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11156 if (controller == null) {
11157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
11158 "IMS not available on device.");
11159 }
11160
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011161 if (callingPackage == null) {
11162 callingPackage = getCurrentPackageName();
11163 }
11164
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011165 final long token = Binder.clearCallingIdentity();
11166 try {
11167 int slotId = getSlotIndexOrException(subId);
Hunsuk Choi89bd22c2021-11-01 13:04:54 +000011168 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
Hunsuk Choi3b742d62021-10-25 19:48:34 +000011169 } catch (ImsException e) {
11170 throw new ServiceSpecificException(e.getCode());
11171 } finally {
11172 Binder.restoreCallingIdentity(token);
11173 }
11174 }
11175
11176 /**
11177 * Unregister an IMS connection state callback
11178 */
11179 @Override
11180 public void unregisterImsStateCallback(IImsStateCallback cb) {
11181 final long token = Binder.clearCallingIdentity();
11182 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
11183 if (controller == null) {
11184 return;
11185 }
11186 try {
11187 controller.unregisterImsStateCallback(cb);
11188 } finally {
11189 Binder.restoreCallingIdentity(token);
11190 }
11191 }
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011192
11193 /**
11194 * @return {@CellIdentity} last known cell identity {@CellIdentity}.
11195 *
11196 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and
11197 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws
11198 * SecurityException.
11199 * If there is current registered network this value will be same as the registered cell
11200 * identity. If the device goes out of service the previous cell identity is cached and
11201 * will be returned. If the cache age of the Cell identity is more than 24 hours
11202 * it will be cleared and null will be returned.
11203 *
11204 */
11205 @Override
11206 public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage,
11207 String callingFeatureId) {
11208 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11209 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
11210 LocationAccessPolicy.checkLocationPermission(mApp,
11211 new LocationAccessPolicy.LocationPermissionQuery.Builder()
11212 .setCallingPackage(callingPackage)
11213 .setCallingFeatureId(callingFeatureId)
11214 .setCallingPid(Binder.getCallingPid())
11215 .setCallingUid(Binder.getCallingUid())
11216 .setMethod("getLastKnownCellIdentity")
11217 .setLogAsInfo(true)
11218 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
11219 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
11220 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
11221 .build());
11222
11223 boolean hasFinePermission =
11224 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
11225 if (!hasFinePermission
11226 || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) {
11227 throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION "
Rambo Wang918993a2022-04-27 09:08:36 -070011228 + "and ACCESS_LAST_KNOWN_CELL_ID permission.");
Sooraj Sasindranfae41b32021-10-26 02:10:05 -070011229 }
11230
11231 final long identity = Binder.clearCallingIdentity();
11232 try {
11233 Phone phone = getPhone(subId);
11234 if (phone == null) return null;
11235 ServiceStateTracker sst = phone.getServiceStateTracker();
11236 if (sst == null) return null;
11237 return sst.getLastKnownCellIdentity();
11238 } finally {
11239 Binder.restoreCallingIdentity(identity);
11240 }
11241 }
Jack Yu4c0a5502021-12-03 23:58:26 -080011242
jimsun3b9ccac2021-10-26 15:01:23 +080011243 /**
11244 * Sets the modem service class Name that Telephony will bind to.
11245 *
11246 * @param serviceName The class name of the modem service.
11247 * @return true if the operation is succeed, otherwise false.
11248 */
11249 public boolean setModemService(String serviceName) {
11250 Log.d(LOG_TAG, "setModemService - " + serviceName);
11251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService");
11252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
11253 SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11254 "setModemService");
11255 return mPhoneConfigurationManager.setModemService(serviceName);
11256 }
11257
11258 /**
11259 * Return the class name of the currently bounded modem service.
11260 *
11261 * @return the class name of the modem service.
11262 */
11263 public String getModemService() {
11264 String result;
11265 Log.d(LOG_TAG, "getModemService");
11266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService");
11267 TelephonyPermissions
11268 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
11269 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
11270 "getModemService");
11271 result = mPhoneConfigurationManager.getModemService();
11272 Log.d(LOG_TAG, "result = " + result);
11273 return result;
11274 }
Hunter Knepshield2b076fa2022-01-19 02:26:22 -080011275
11276 @Override
11277 public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) {
11278 // Only telecom (and shell, for CTS purposes) is allowed to call this method.
11279 mApp.enforceCallingOrSelfPermission(
11280 permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride");
11281 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11282
11283 final long identity = Binder.clearCallingIdentity();
11284 try {
11285 Phone phone = getPhone(subId);
11286 if (phone == null) return;
11287 phone.setVoiceServiceStateOverride(hasService);
11288 } finally {
11289 Binder.restoreCallingIdentity(identity);
11290 }
11291 }
Muralidhar Reddy4e5a8012022-05-11 14:49:00 +000011292
11293 /**
11294 * set removable eSIM as default eUICC.
11295 *
11296 * @hide
11297 */
11298 @Override
11299 public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) {
11300 enforceModifyPermission();
11301 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11302
11303 final long identity = Binder.clearCallingIdentity();
11304 try {
11305 UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault);
11306 } finally {
11307 Binder.restoreCallingIdentity(identity);
11308 }
11309 }
11310
11311 /**
11312 * Returns whether the removable eSIM is default eUICC or not.
11313 *
11314 * @hide
11315 */
11316 @Override
11317 public boolean isRemovableEsimDefaultEuicc(String callingPackage) {
11318 enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc");
11319 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
11320
11321 final long identity = Binder.clearCallingIdentity();
11322 try {
11323 return UiccController.getInstance().isRemovableEsimDefaultEuicc();
11324 } finally {
11325 Binder.restoreCallingIdentity(identity);
11326 }
11327 }
11328
11329
Santos Cordon7d4ddf62013-07-10 11:58:08 -070011330}